1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 // Author: Gareth de Vaux
7 // Email: devaux@lhc.phy.uct.ac.za | dhlt@lordcow.org
9 ////////////////////////////////////////////////////////////////////////////////
14 #include <asm/errno.h>
20 #include "System/SystemError.hpp"
21 #include "System/Socket.hpp"
22 #include "DDL/L2SignalReceiver.hpp"
23 #include "DDL/FileList.hpp"
24 #include "System/SignalHandler.hpp"
25 #include "Debug/print.hpp"
33 class L2SignalReceiver : public DDL::L2SignalReceiver
37 L2SignalReceiver(FileList& list, const UShort port = 4900)
38 : DDL::L2SignalReceiver(port)
43 virtual void GotL2(const EventID eventid)
45 cout << "Got signal: " << eventid << endl;
54 L2SignalReceiver* signalreceiver = NULL;
56 // If we get a SIGINT ( keyboard Ctrl+C ) signal or SIGHUP then terminate the program.
58 if (signalreceiver != NULL) signalreceiver->Terminate();
61 if (signalreceiver != NULL) signalreceiver->Terminate();
67 cerr << "Usage: > triggerDDL [-r] <filelist> [<port>]" << endl;
68 cerr << " -r : Optional flag indicating to recursively go through sub directories" << endl;
69 cerr << " and add files to the file list for publishing." << endl;
70 cerr << "<filelist> : Required file name containing a file list (one file/directory per line)" << endl;
71 cerr << " of files to publish." << endl;
72 cerr << " <port> : Optional port number to listen to for L2 signals." << endl;
76 bool CheckIfEmpty(const FileList& filelist)
80 cerr << "Error: No files added to file list. Is the path empty?" << endl;
88 /* Parse command line and fill the port number and filelist.
89 If the port number or filelist is untouched then the default
91 Returns true if the command line is parsed properly.
93 bool ParseCommandLine(const int argc, const char** argv, UShort& port, FileList& filelist)
95 for (int i = 1; i < argc; i++)
97 if ( strcmp(argv[i], "-h") == 0 or strcmp(argv[i], "-help") == 0
98 or strcmp(argv[i], "--help") == 0)
108 return CheckIfEmpty(filelist);
113 if (strcmp(argv[1],"-r") == 0)
115 filelist.Add(argv[2], true);
116 return CheckIfEmpty(filelist);
120 int x = atoi(argv[2]);
121 if ( not (0 < x and x < 65536) )
123 cerr << "Error: Port is out of range, valid range is [1..65535]." << endl;
129 filelist.Add(argv[1], false);
130 return CheckIfEmpty(filelist);
137 if (strcmp(argv[1],"-r") != 0)
139 cerr << "Error: Unknown flag '" << argv[1] << "', expected '-r'." << endl;
143 int x = atoi(argv[3]);
144 if ( not (0 < x and x < 65536) )
146 cerr << "Error: Port is out of range, valid range is [1..65535]." << endl;
152 filelist.Add(argv[2], true);
153 return CheckIfEmpty(filelist);
162 int main(const int argc, const char** argv)
170 bool valid_arguments = ParseCommandLine(argc, argv, port, filelist);
173 L2SignalReceiver receiver(filelist, port);
174 signalreceiver = &receiver;
180 catch (const System::Error& e)
182 cerr << "Error [" << e.ErrorCode();
183 if (e.ErrorCode() == EACCES)
184 cerr << "]: Could not allocate socket. ";
190 catch (const Error& e)
192 cerr << "Error [" << e.ErrorCode() << "]: " << e << endl;
197 cerr << "Error: Unknown exception!" << endl;