00001 #include <stdio.h>
00002 #include <sched.h>
00003 #include <unistd.h>
00004 #include <time.h>
00005 #include <list>
00006 #include "Connector.h"
00007 #include "ConnectionWrap.h"
00008 #include "BufferedFile.h"
00009 #include "BufferedFileFactory.h"
00010 #include "ConnectionFactory.h"
00011 #include "OutputConnection.h"
00012 #include "Clock.h"
00013
00017 #define DEFAULT_PORT 8880
00018
00022 int main(int argc, char *argv[]){
00023 BufferedFileFactory * bf = new BufferedFileFactory();
00024 ConnectionFactory * cf = NULL;
00025 BufferedFile * outputBf = bf->getNewBufferedFile(STDOUT_FILENO);
00026 outputBf->setWriteOnly();
00027 OutputConnection<short> * oc = new OutputConnection<short>(outputBf);
00028 ConnectionWrap * ocwrap = new ConnectionWrap((void*)oc,SHORTCONN);
00029 list<ConnectionWrap *> * incoming = new list<ConnectionWrap*>();
00030 if (argc > 1) {
00031 cf = new ConnectionFactory(bf,atoi(argv[1]),0,0,0);
00032 } else {
00033 cf = new ConnectionFactory(bf,DEFAULT_PORT,0,0,0);
00034 }
00035 try {
00036 for (;;) {
00037 int rw = bf->process(100);
00038 if (rw) {
00039 Clock::clock++;
00040
00041 ocwrap->process();
00042 if (cf->isThereANewConnection()) {
00043 cerr << "_";
00044 ConnectionWrap * wrap = cf->processConnection();
00045 if (wrap!=NULL) {
00046 cerr << (int)(wrap->conn.floatConn->getFileHandle()) << "\n";
00047 assert(wrap->conn.floatConn!=0);
00048 if (wrap == NULL) {
00049 cerr << "NULL Wrapper Returned?\n";
00050 } else {
00051 cerr << "New Connection\n";
00052 incoming->push_back(wrap);
00053 ocwrap->connectFrom(wrap);
00054 }
00055 } else {
00056 cerr << "Connection Failed!\n";
00057 }
00058 }
00059 }
00060 }
00061 } catch (char * str) {
00062 cerr<< "EXCEPTION: " <<str<<"\n";
00063 } catch (string * str) {
00064 cerr<< "EXCEPTION: " <<*str<<"\n";
00065 }
00066 return 0;
00067 }