void TaskManagerTest::testMultiTasks() { TaskManager tm; tm.start(new SimpleTask); tm.start(new SimpleTask); tm.start(new SimpleTask); TaskManager::TaskList list = tm.taskList(); assert (list.size() == 3); tm.cancelAll(); while (tm.count() > 0) Thread::sleep(100); assert (tm.count() == 0); }
void TaskManagerTest::testError() { TaskManager tm; TaskObserver to; tm.addObserver(Observer<TaskObserver, TaskStartedNotification>(to, &TaskObserver::taskStarted)); tm.addObserver(Observer<TaskObserver, TaskCancelledNotification>(to, &TaskObserver::taskCancelled)); tm.addObserver(Observer<TaskObserver, TaskFailedNotification>(to, &TaskObserver::taskFailed)); tm.addObserver(Observer<TaskObserver, TaskFinishedNotification>(to, &TaskObserver::taskFinished)); tm.addObserver(Observer<TaskObserver, TaskProgressNotification>(to, &TaskObserver::taskProgress)); AutoPtr<TestTask> pTT = new TestTask; tm.start(pTT.duplicate()); assert (pTT->progress() == 0); Thread::sleep(200); pTT->cont(); while (pTT->progress() != 0.5) Thread::sleep(50); assert (to.progress() == 0.5); assert (to.started()); assert (pTT->state() == Task::TASK_RUNNING); TaskManager::TaskList list = tm.taskList(); assert (list.size() == 1); assert (tm.count() == 1); pTT->fail(); pTT->cont(); while (pTT->state() != Task::TASK_FINISHED) Thread::sleep(50); assert (pTT->state() == Task::TASK_FINISHED); assert (to.finished()); assert (to.error() != 0); while (tm.count() == 1) Thread::sleep(50); list = tm.taskList(); assert (list.empty()); }
int main(const ArgVec& args) { if (!_helpRequested) { TaskManager tm; tm.start(new SampleTask); waitForTerminationRequest(); tm.cancelAll(); tm.joinAll(); } return Application::EXIT_OK; }
int main() { TaskManager manager; manager.start(); return 0; }
void TaskManagerTest::testCustom() { TaskManager tm; CustomTaskObserver<int> ti(0); tm.addObserver( Observer<CustomTaskObserver<int>, TaskCustomNotification<int> > (ti, &CustomTaskObserver<int>::taskCustom)); AutoPtr<CustomNotificationTask<int> > pCNT1 = new CustomNotificationTask<int>(0); tm.start(pCNT1.duplicate()); assert (ti.custom() == 0); for (int i = 1; i < 10; ++i) { pCNT1->setCustom(i); assert (ti.custom() == i); } CustomTaskObserver<std::string> ts(""); tm.addObserver( Observer<CustomTaskObserver<std::string>, TaskCustomNotification<std::string> > (ts, &CustomTaskObserver<std::string>::taskCustom)); AutoPtr<CustomNotificationTask<std::string> > pCNT2 = new CustomNotificationTask<std::string>(""); tm.start(pCNT2.duplicate()); assert (tm.taskList().size() == 2); assert (ts.custom() == ""); std::string str("notify me"); pCNT2->setCustom(str); assert (ts.custom() == str); S s; s.i = 0; s.str = ""; CustomTaskObserver<S*> ptst(&s); tm.addObserver( Observer<CustomTaskObserver<S*>, TaskCustomNotification<S*> > (ptst, &CustomTaskObserver<S*>::taskCustom)); AutoPtr<CustomNotificationTask<S*> > pCNT3 = new CustomNotificationTask<S*>(&s); tm.start(pCNT3.duplicate()); assert (tm.taskList().size() == 3); assert (ptst.custom()->i == 0); assert (ptst.custom()->str == ""); s.i = 123; s.str = "123"; pCNT3->setCustom(&s); assert (ptst.custom()->i == 123); assert (ptst.custom()->str == "123"); s.i = 0; s.str = ""; CustomTaskObserver<S> tst(s); tm.addObserver( Observer<CustomTaskObserver<S>, TaskCustomNotification<S> > (tst, &CustomTaskObserver<S>::taskCustom)); AutoPtr<CustomNotificationTask<S> > pCNT4 = new CustomNotificationTask<S>(s); tm.start(pCNT4.duplicate()); assert (tm.taskList().size() == 4); assert (tst.custom().i == 0); assert (tst.custom().str == ""); s.i = 123; s.str = "123"; pCNT4->setCustom(s); assert (tst.custom().i == 123); assert (tst.custom().str == "123"); AutoPtr<SimpleTask> pST = new SimpleTask; tm.start(pST.duplicate()); assert (tm.taskList().size() == 5); tm.cancelAll(); while (tm.count() > 0) Thread::sleep(50); assert (tm.count() == 0); }
int main(int argc, char ** argv){ NodeType type; if(strcmp(argv[1],"sink")==0){ type = SINK; } if(strcmp(argv[1],"camera")==0){ type = CAMERA; } if(strcmp(argv[1],"cooperator")==0){ type = COOPERATOR; } NodeManager *nodeMng; RadioSystem *radioSys; TaskManager *taskMng; S2GInterface *s2ginterface; MessageParser *msg_parser; //ConnectionManager *connMng; boost::asio::io_service io_service; switch(type){ case SINK:{ //create the main components nodeMng = new NodeManager(SINK, argv[6]); msg_parser = new MessageParser(); radioSys = new RadioSystem(nodeMng, msg_parser,argv[3],argv[4],argv[5]); taskMng = new TaskManager(nodeMng); nodeMng->set_radioSystem(radioSys); nodeMng->set_taskManager(taskMng); //start the task manager taskMng->start(); //start a telosb receiver radioSys->startTelosbReceiver(argv[2], argv[6]); //start the sink2gui interface tcp::resolver resolver(io_service); tcp::resolver::query query("localhost", "1234"); tcp::resolver::iterator iterator = resolver.resolve(query); s2ginterface = new S2GInterface(nodeMng, msg_parser, io_service, iterator); s2ginterface->startInterface(); nodeMng->set_s2gInterface(s2ginterface); break; } case CAMERA:{ nodeMng = new NodeManager(CAMERA, argv[6]); msg_parser = new MessageParser(); radioSys = new RadioSystem(nodeMng,msg_parser,argv[3],argv[4],argv[5]); taskMng = new TaskManager(nodeMng); //connMng = new ConnectionManager(); nodeMng->set_radioSystem(radioSys); nodeMng->set_taskManager(taskMng); //start the task manager taskMng->start(); //start a telosb receiver radioSys->startTelosbReceiver(argv[2], argv[6]); //start the WiFi manager radioSys->startWiFiReceiver(); radioSys->joinTelosbReceiver(); break; } case COOPERATOR:{ nodeMng = new NodeManager(COOPERATOR,argv[6]); msg_parser = new MessageParser(); radioSys = new RadioSystem(nodeMng,msg_parser,argv[3],argv[4],argv[5]); taskMng = new TaskManager(nodeMng); nodeMng->set_radioSystem(radioSys); nodeMng->set_taskManager(taskMng); //start the task manager taskMng->start(); radioSys->startWiFiReceiver(); //ALEXIS 15/12 WIFI CLASS break; } default: break; } taskMng->join(); return 0; }