1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 ////////////////////////////////////////////////////////////////////////////////
12 #include <asm/errno.h>
18 #include "System/SystemError.hpp"
19 #include "System/Socket.hpp"
20 #include "BCMP/Receiver.hpp"
21 #include "DDL/FileList.hpp"
22 #include "System/SignalHandler.hpp"
30 bool terminate = false;
37 class Handler : public BCMP::EventHandler
41 virtual void OnConnect(const System::Address& address)
43 cout << "Connected to: " << address << endl;
46 virtual void OnDisconnect(const System::Address& address)
48 cout << "Disonnected to: " << address << endl;
51 virtual void OnConnectionLost(const System::Address& address)
53 cout << "Connection to: " << address << " lost." << endl;
56 virtual void OnMessage(
57 const char* message, const UInt length,
58 const System::Address& from
61 cout << "Got message of " << length << " bytes from: " << from << endl;
62 char* str = new char[length+1];
63 memcpy(str, message, length);
65 cout << " : " << str << endl;
76 cerr << "Usage: > TriggerDDLFilePublisher [-r] <filelist> [<port>]" << endl;
77 cerr << " -r : Optional flag indicating to recursively go through sub directories" << endl;
78 cerr << " and add files to the file list for publishing." << endl;
79 cerr << "<filelist> : Required file name containing a file list (one file/directory per line)" << endl;
80 cerr << " of files to publish." << endl;
81 cerr << " <port> : Optional port number to listen to for L2 signals." << endl;
85 /* Parse command line and fill the port number and filelist.
86 If the port number or filelist is untouched then the default
88 Returns true if the command line is parsed properly.
90 bool ParseCommandLine(const int argc, const char** argv, UShort& port, FileList& filelist)
92 // TODO: parse command line.
93 // command line format:
94 // > TriggerDDLFilePublisher [-r] <filelist> [<port>]
95 // -r : Optional flag indicating to recursively go through sub directories
96 // and add files to the file list for publishing.
97 // <filelist> : The file name containing a file list (one file/directory per line)
98 // of files to publish.
99 // <port> : The port number to listen to for L2 signals.
106 int main(const int argc, const char** argv)
113 bool valid_arguments = ParseCommandLine(argc, argv, port, filelist);
114 if (not valid_arguments) return 1;
116 BCMP::Receiver receiver(&handler, port);
117 cout << "Listening on: " << receiver.LocalAddress() << endl;
119 // Enter an event handling loop:
120 while (not terminate)
124 // Try handle events or timeout every 50 milliseconds
125 // to check if we were signaled to terminate or not.
126 receiver.HandleEvents(10);
128 catch (System::Error& e)
130 if (e.ErrorCode() != EINTR) throw;
134 catch (const Error& e)
136 cerr << "Error [" << e.ErrorCode() << "]: " << e << endl;
139 cout << "done." << endl;