[1cff17]: src / Hive.cpp  Maximize  Restore  History

Download this file

329 lines (259 with data), 9.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
//#include <iostream>
//#include <stdlib.h>
#include <boost/program_options.hpp>
#include "org/esb/signal/Messenger.h"
#include "org/esb/signal/Message.h"
#include "org/esb/signal/Messenger.h"
#include "org/esb/net/TcpServerSocket.h"
#include "org/esb/net/TcpSocket.h"
#include "org/esb/lang/Thread.h"
//#include "org/esb/hive/ProtocolServer.h"
#include "org/esb/config/config.h"
//#include "org/esb/hive/job/JobWatcher.h"
#include "org/esb/hive/job/ProcessUnitWatcher.h"
#include "org/esb/hive/job/ProcessUnit.h"
#include "org/esb/io/ObjectInputStream.h"
#include "org/esb/io/ObjectOutputStream.h"
#include "org/esb/web/WebServer.h"
#include "org/esb/hive/HiveListener.h"
#include "org/esb/hive/DirectoryScanner.h"
#include "org/esb/av/AV.h"
//#include "org/esb/hive/PacketCollector.h"
#include "Environment.cpp"
#include "org/esb/hive/HiveClient.h"
#include "org/esb/util/Decimal.h"
//#include "org/esb/hive/FileImporter.h"
#include "export.cpp"
//#include "org/esb/util/Log.h"
//#include "job.cpp"
//#include "org/esb/hive/JobUtil.h"
#if !defined(_WIN32)
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <pthread.h>
#endif // !_WIN32
using namespace org::esb::net;
using namespace org::esb::io;
using namespace org::esb::config;
using namespace org::esb::hive;
using namespace org::esb::hive::job;
using namespace org::esb::web;
using namespace org::esb::util;
using namespace org::esb::signal;
using namespace std;
using namespace std;
namespace po = boost::program_options;
void listener(int argc, char * argv[]);
void client(int argc, char * argv[]);
void shell(int argc, char * argv[]);
int main(int argc, char * argv[]) {
// loginit("log.properties");
std::string config_path;
po::options_description gen("general options");
gen.add_options()
("help", "produce this message")
("config,c", po::value<std::string > ()->default_value("/etc/hive.conf"), "use Configuration")
("version,v", "Prints the Version")
;
po::options_description ser("Server options");
ser.add_options()
("server,s", "start the Hive Server Process")
("port,p", po::value<int>()->default_value(20200), "specify the port for the Hive Server")
("web,w", po::value<int>()->default_value(8080), "start the Web Server Process on the specified port")
("webroot,r", po::value<std::string > ()->default_value("."), "define the Path for Web Server root")
("scandir", po::value<std::string > (), "define the Path to Scan for new Media Files")
("scanint", po::value<int>()->default_value(300), "define the Interval to Scan for new Media Files")
;
po::options_description cli("Client options");
cli.add_options()
("client,i", "start the Hive Client")
("host,h", po::value<std::string > ()->default_value("localhost"), "Host to connect")
("port,p", po::value<int>()->default_value(20200), "Port to connect")
;
po::options_description exp("Export options");
exp.add_options()
("export,e", "Exports a File")
("file,f", po::value<std::string > (), "which file to export")
("directory,d", po::value<std::string > (), "Directory in which the File to export")
;
po::options_description all("");
all.add(gen).add(ser).add(cli).add(exp);
gen.add(ser).add(cli).add(exp);
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, all), vm);
po::notify(vm);
if (argc == 1 || vm.count("help")) {
cout << all << "\n";
return 1;
}
if (vm.count("version")) {
cout << "MediaEncodingCluster V.-0.0.1" << endl;
cout << LIBAVCODEC_IDENT << endl;
cout << LIBAVFORMAT_IDENT << endl;
cout << LIBAVUTIL_IDENT << endl;
cout << LIBSWSCALE_IDENT << endl;
exit(0);
}
av_register_all();
avcodec_init();
avcodec_register_all();
if (vm.count("server")) {
Config::init((char*) vm["config"].as<std::string > ().c_str());
Config::setProperty("web.docroot", vm["webroot"].as<std::string > ().c_str());
if(vm.count("web"))
Config::setProperty("web.port", Decimal(vm["web"].as<int> ()).toString().c_str());
if (vm.count("scandir"))
Config::setProperty("hive.scandir", vm["scandir"].as<std::string > ().c_str());
if (vm.count("scanint"))
Config::setProperty("hive.scaninterval", Decimal(vm["scanint"].as<int> ()).toString().c_str());
Config::setProperty("hive.port", Decimal(vm["port"].as<int>()).toString().c_str());
listener(argc, argv);
}
if (vm.count("client")) {
Config::setProperty("client.port", Decimal(vm["port"].as<int>()).toString().c_str());
Config::setProperty("client.host", vm["host"].as<std::string > ().c_str());
client(argc, argv);
}
if (vm.count("export")) {
std::string file = vm["file"].as<std::string > ();
std::string dir = vm["directory"].as<std::string > ();
exporter((char*) file.c_str(), (char*) dir.c_str());
}
Config::close();
return 0;
}
#ifdef WIN32
boost::mutex terminationMutex;
boost::condition ctrlCHit;
boost::condition serverStopped;
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) {
switch (ctrl_type) {
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT:
{
boost::mutex::scoped_lock terminationLock(terminationMutex);
ctrlCHit.notify_all(); // should be just 1
serverStopped.wait(terminationLock);
return TRUE;
}
default:
return FALSE;
}
}
void ctrlCHitWait() {
boost::mutex::scoped_lock terminationLock(terminationMutex);
ctrlCHit.wait(terminationLock);
}
#else
void ctrlCHitWait() {
sigset_t wait_mask2;
sigemptyset(&wait_mask2);
sigaddset(&wait_mask2, SIGINT);
sigaddset(&wait_mask2, SIGQUIT);
sigaddset(&wait_mask2, SIGTERM);
//sigaddset(&wait_mask, SIGCHLD);
pthread_sigmask(SIG_BLOCK, &wait_mask2, 0);
int sig = 0;
//sigdelset(&wait_mask, SIGCHLD);
int err;
do {
err = sigwait(&wait_mask2, &sig);
} while (err != 0);
}
#endif
void client(int argc, char *argv[]) {
string host = Config::getProperty("client.host");
int port = atoi(Config::getProperty("client.port"));
org::esb::hive::HiveClient client(host, port);
Messenger::getInstance().addMessageListener(client);
Messenger::getInstance().sendRequest(Message().setProperty("hiveclient", "start"));
ctrlCHitWait();
Messenger::getInstance().sendRequest(Message().setProperty("hiveclient", "stop"));
// client.connect();
// client.process();
// return;
/*
cout << "Connecting to " << host << " on port " << port << endl;
TcpSocket sock((char*) host.c_str(), port);
sock.connect();
ObjectInputStream ois(sock.getInputStream());
ObjectOutputStream oos(sock.getOutputStream());
int pCount = 0;
while (true) {
while (true || ++pCount < 20) {
char * text = "get process_unit";
sock.getOutputStream()->write(text, strlen(text));
ProcessUnit unit;
ois.readObject(unit);
if (unit._input_packets.size() == 0)break;
// try{
unit.process();
// }catch(...){
// logerror("Error in process");
// }
char * text_out = "put process_unit";
sock.getOutputStream()->write(text_out, strlen(text_out));
oos.writeObject(unit);
// break;
}
// break;
org::esb::lang::Thread::sleep2(1000);
}
*/
}
/*----------------------------------------------------------------------------------------------*/
bool main_nextLoop = true;
void listener(int argc, char *argv[]) {
/*
if (!checkEnvironment()) {
cout << "Fehler in der Configuration" << endl;
exit(1);
}
*/
/*
*
* Initializing Application Services
*
*/
DirectoryScanner dirscan;
Messenger::getInstance().addMessageListener(dirscan);
WebServer webserver;
Messenger::getInstance().addMessageListener(webserver);
HiveListener hive;
Messenger::getInstance().addMessageListener(hive);
ProcessUnitWatcher puw;
Messenger::getInstance().addMessageListener(puw);
/*
*
* Starting Application Services from configuration
*
*/
if (string(Config::getProperty("hive.start")) == "true") {
Messenger::getInstance().sendMessage(Message().setProperty("jobwatcher", "start"));
Messenger::getInstance().sendMessage(Message().setProperty("hivelistener", "start"));
}
if (string(Config::getProperty("web.start")) == "true"){
Messenger::getInstance().sendRequest(Message().setProperty("webserver", "start"));
}
if (string(Config::getProperty("hive.autoscan")) == "true") {
Messenger::getInstance().sendMessage(Message().
setProperty("directoryscan", "start").
setProperty("directory", Config::getProperty("hive.scandir")).
setProperty("interval", Config::getProperty("hive.scaninterval")));
}
ctrlCHitWait();
/*
*
* Stopping Application Services from configuration
*
*/
Messenger::getInstance().sendRequest(Message().setProperty("directoryscan", "stop"));
Messenger::getInstance().sendRequest(Message().setProperty("jobwatcher", "stop"));
Messenger::getInstance().sendRequest(Message().setProperty("processunitwatcher", "stop"));
Messenger::getInstance().sendRequest(Message().setProperty("hivelistener", "stop"));
Messenger::getInstance().sendRequest(Message().setProperty("webserver", "stop"));
Messenger::free();
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks