int main(int argc, char ** argv) { el::Configurations confFromFile("./dev_controller-logger.conf"); el::Loggers::reconfigureAllLoggers(confFromFile); if (argc < 10) { std::cout<<"dev_controller mqtt_clientid mqtt_username mqtt_password mqtt_connuri, zmq_listenuri redisIPAddr redisPort zookeeperAddrList mongodbUri"<<std::endl; return -1; } char hostName[64] = {0}; int ret = gethostname(hostName, sizeof(hostName)-1); if (ret != 0) { strcpy(hostName, "pigeon-host"); } pid_t procId = getpid(); char postfix[128] = {0}; sprintf(postfix, ":%s_%d:", hostName, procId); dev_ctl_id += postfix; g_stopflag.test_and_set(); signal(SIGINT, sigIntHandler); signal(SIGTERM, sigIntHandler); auto upListener = std::make_shared<UsrPortalMsgListener>(); gPtrZmqEndInst = std::make_shared<pigeon::ZmqEnd>(argv[5]); gPtrZmqEndInst->setMsgListener(upListener); gPtrZmqEndInst->startMsgLoop(); //reg own service into zookeeper char svcid[128] = {0}; sprintf(svcid, "%s_%d", hostName, procId); DevCtlServiceInfo sInfo(argv[5], svcid); DevCtlServiceReg sGeg(argv[8], service_path, sInfo.getServiceInfoJson()); ret = sGeg.RegService(); if (ret != 0) { LOG(ERROR) << "reg own service into zookeeper fail!"; gPtrZmqEndInst->finMsgLoop(); return -1; } //DevQueryEnd gPtrDqEnd = std::unique_ptr<DevQueryEnd>(new DevQueryEnd(gPtrZmqEndInst, argv[6], atoi(argv[7]))); gPtrDqEnd->start(); //DevOptEnd gPtrDOpEnd = std::unique_ptr<DevOptEnd>(new DevOptEnd(dev_ctl_id, gPtrZmqEndInst, argv[1], argv[2], argv[3], argv[4], argv[6], atoi(argv[7]), argv[9])); gPtrDOpEnd->start(); while(g_stopflag.test_and_set()) { std::this_thread::sleep_for(std::chrono::milliseconds(200)); } gPtrZmqEndInst->finMsgLoop(); gPtrDqEnd->stop(); gPtrDOpEnd->stop(); return 0; }
void ThrottlingOperationStarterTest::testFinishingOperationsAllowsMoreToStart() { _operationStarter->setMaxPendingRange(1, 1); CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(255))); CPPUNIT_ASSERT(!_operationStarter->start(createMockOperation(), OperationStarter::Priority(255))); CPPUNIT_ASSERT(!_starterImpl->getOperations().empty()); _starterImpl->getOperations().pop_back(); CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(255))); CPPUNIT_ASSERT(!_starterImpl->getOperations().empty()); }
static int run_server(int argc, char **argv) { try { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " <port>\n"; return 1; } short port = std::atoi(argv[1]); listen_signals(); storage = std::make_shared<MmapStorage>(MMAP_STORAGE, MMAP_SIZE); cache = std::make_shared<Cache>(storage); Protocol protocol(cache); std::cout << "server listen localhost on port " << port << "\n" << "accepted commands:\n" << "set <key> <val> [<time to live in sec>]\n" << "get <key>\n" << "remove <key>\n"; server.reset(new ThreadedServer(port, protocol)); //server.reset(new AsyncServer(port, protocol)); server->start(); } catch (const std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } return 0; }
void ThrottlingOperationStarterTest::testOperationThrottledWhenNoAvailableSlots() { _operationStarter->setMaxPendingRange(0, 0); CPPUNIT_ASSERT(!_operationStarter->start(createMockOperation(), OperationStarter::Priority(0))); }
bool TestServer::TestTakeoverServer() { // start a server snprintf(s_filename, MAXPATHLEN, "/tmp/hphp_takeover_XXXXXX"); int tmpfd = mkstemp(s_filename); close(tmpfd); s_func.reset(new AsyncFunc<TestServer>(this, &TestServer::RunServer)); s_func->start(); // Wait for the server to actually start HttpClient http; StringBuffer response; vector<String> responseHeaders; string url = "http://127.0.0.1:" + lexical_cast<string>(s_server_port) + "/status.php"; HeaderMap headers; for (int i = 0; i < 10; i++) { int code = http.get(url.c_str(), response, &headers, &responseHeaders); if (code > 0) { break; } sleep(1); } // will start a second server, which should takeover VSR("<?php print 'Hello, World!';", "Hello, World!"); unlink(s_filename); s_filename[0] = 0; return true; }
void Task_Controller_UpdateTarget(Eigen::Vector3f targetVel) { pidController.setTargetVel(targetVel); // reset timeout commandTimedOut = false; if (commandTimeoutTimer) commandTimeoutTimer->start(COMMAND_TIMEOUT_INTERVAL); }
/// Start instant of the path virtual RobotInstant start() const override { RobotInstant instant = path->start(); if (angleFunction) { instant.angle = angleFunction->operator()(instant.motion); return instant; } return instant; }
void ThrottlingOperationStarterTest::testOperationStartingIsForwardedToImplementation() { CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(0))); CPPUNIT_ASSERT_EQUAL(std::string("Bucket(BucketSpace(0x0000000000000001), BucketId(0x4000000000000001)), pri 0\n"), _starterImpl->toString()); }
void resume() { if (started) tmr->resume(); else { started = true; tmr->start(); } }
void start() { auto &init = wsServer->endpoint["^/tunator$"]; init.onmessage = [this](std::shared_ptr<typename WsServer::Connection> connection, std::shared_ptr<typename WsServer::Message> message) { auto wsPacket = WsPacket<WsServer>::from(*message); auto tunDev = tunDevices.find(connection); if ("JSON" == wsPacket.header) { if (tunDev == tunDevices.end()) { processJson(0, connection, wsPacket); } else { processJson(tunDev->second.get(), connection, wsPacket); } } else { if (tunDev == tunDevices.end()) { LOG(ERROR) << "Can not find connection"; return; } if ("PAKT" == wsPacket.header) { processPacket(tunDev->second, connection, wsPacket); } } return; }; init.onopen = [](std::shared_ptr<typename WsServer::Connection> connection) { LOG(INFO) << "Server: Opened connection " << (size_t)connection.get(); }; init.onclose = [this](std::shared_ptr<typename WsServer::Connection> connection, int status, const std::string & /*reason*/) { LOG(INFO) << "Server: Closed connection " << (size_t)connection.get() << " with status code " << status; this->disconnect(connection); }; init.onerror = [this](std::shared_ptr<typename WsServer::Connection> connection, const boost::system::error_code &ec) { LOG(INFO) << "Server: Error for connection " << (size_t)connection.get() << ". " << "Error: " << ec << ", error message: " << ec.message(); this->disconnect(connection); }; wsServer->start(); }
bool on_accept() { if (!task) { cout << "In listener::on_accept()" << endl; task.reset(new server_work_thread); task->sock = std::move(connect_sock); task->start(); cout << "server thread started." << endl; // shutdown the listener thead.. our work is done here. return false; } else { connect_sock->close(); cerr << "Multiple attempts to connect to server" << endl; }; };
void ThrottlingOperationStarterTest::testStartingOperationsFillsUpPendingWindow() { _operationStarter->setMaxPendingRange(1, 3); CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(255))); CPPUNIT_ASSERT(!_operationStarter->start(createMockOperation(), OperationStarter::Priority(255))); CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(100))); CPPUNIT_ASSERT(!_operationStarter->start(createMockOperation(), OperationStarter::Priority(100))); CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(0))); CPPUNIT_ASSERT(!_operationStarter->start(createMockOperation(), OperationStarter::Priority(0))); }
int main(int argc, char** argv) { paddle::initMain(argc, argv); testing::InitGoogleTest(&argc, argv); FLAGS_num_gradient_servers = 2; if (FLAGS_rdma_tcp == "rdma") { g_server.reset(new ParameterServer2Tester( FLAGS_server_addr, FLAGS_port, FLAGS_server_cpu)); } else { g_server.reset(new ParameterServer2Tester(FLAGS_server_addr, FLAGS_port)); } g_server->start(); sleep(2); int ret = RUN_ALL_TESTS(); g_server.reset(); exit(ret); }
int main(int argc, char* argv[]) { llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry(); // initializePollyPasses(Registry); TODO use in LLVM 3.5+ initializeCore(Registry); initializeDebugIRPass(Registry); initializeScalarOpts(Registry); initializeObjCARCOpts(Registry); initializeVectorization(Registry); initializeIPO(Registry); initializeAnalysis(Registry); initializeIPA(Registry); initializeTransformUtils(Registry); initializeInstCombine(Registry); initializeInstrumentation(Registry); initializeTarget(Registry); llvm::cl::ParseCommandLineOptions(argc, argv); struct sigaction signal_action; memset( &signal_action, 0, sizeof(signal_action) ); signal_action.sa_handler = &handleSignal; sigfillset(&signal_action.sa_mask); sigaction(SIGINT,&signal_action,NULL); switch (ServerCommunicationType) { case socket: server.reset(new SocketServer(backendType)); break; case sharedmem: server.reset(new ShmemServer(backendType)); break; } if (server) server->start(); server->end(); return 0; }
void start_profiler(std::uint32_t max_seconds, std::uint8_t stack_depth) override { m_sampling_profiler = std::make_unique<sampling_profiler>(max_seconds, stack_depth); m_sampling_profiler->start(); }
// ---------------------------------------------------------------------------- void run(const options& options) { dm::init(); loop_.reset(new dripcore::loop); jsonrpc::service service; player player(options.audio_device); if ( signal(SIGPIPE, sig_handler) == SIG_ERR ) { std::cerr << "Error installing SIGPIPE handler!" << std::endl; } if ( signal(SIGINT, sig_handler) == SIG_ERR ) { std::cerr << "Error installing SIGINT handler!" << std::endl; } if ( signal(SIGTERM, sig_handler) == SIG_ERR ) { std::cerr << "Error installing SIGTERM handler!" << std::endl; } spotify_source_config sp_cfg{ options.spotify_username, options.spotify_password, }; player.add_source("spotify", std::make_shared<spotify_source>(sp_cfg)); player.add_source("local", std::make_shared<local_source>()); using std::placeholders::_1; service.add_method("player/play", std::bind(&json_rpc::play, std::ref(player), _1)); service.add_method("player/queue", std::bind(&json_rpc::queue, std::ref(player), _1)); service.add_method("player/skip", std::bind(&json_rpc::skip, std::ref(player), _1)); service.add_method("player/stop", std::bind(&json_rpc::stop, std::ref(player), _1)); service.add_method("player/state", std::bind(&json_rpc::state, std::ref(player), _1)); #if 0 service.add_method("db/tags", std::bind(&json_rpc::tags, std::ref(player), _1)); service.add_method("db/export-tracks", std::bind(&json_rpc::export_tracks, std::ref(player), _1)); #endif service.add_method("db/index", std::bind(&json_rpc::index, _1)); service.add_method("db/save", std::bind(&json_rpc::save, _1)); service.add_method("db/delete", std::bind(&json_rpc::erase, _1)); service.add_method("db/import-tracks", std::bind(&json_rpc::import_tracks, _1)); service.add_method("db/cover", std::bind(&json_rpc::cover, _1)); service.add_method("db/get/artists", std::bind(&json_rpc::get_artists, _1)); service.add_method("db/get/albums", std::bind(&json_rpc::get_albums, _1)); service.add_method("db/set/album", std::bind(&json_rpc::set_album, _1)); service.add_method("db/get/album/tracks", std::bind(&json_rpc::get_album_tracks, _1)); service.add_method("db/get/tracks", std::bind(&json_rpc::get_tracks, _1)); service.add_method("db/get/source_local", std::bind(&json_rpc::get_source_local, _1)); service.add_method("db/set/source_local", std::bind(&json_rpc::set_source_local, _1)); service.add_method("sources/local/scan", std::bind(&json_rpc::sources_local_scan, _1)); service.add_method("sources/spotify/uris", std::bind(&json_rpc::sources_spotify_uris, _1)); ///// // Setup callback to get player state info. Note that the callback is // called from player thread context. The service send_notification method // will push a send notifition for each connection to be executed in dripcore // context. // player.set_state_info_callback([&](const player_state_info& info) { json::object params { { "state", info.state }, { "track", info.track.to_json() }, { "source", info.source } }; service.send_notification(json_rpc_notification("player/event", params)); }); auto acceptor = std::make_shared<dripcore::acceptor>("0.0.0.0", 8212, [&](dripcore::socket client) { loop_->start(std::make_shared<jsonrpc::server::connection>(service, std::move(client))); }); loop_->start(acceptor); loop_->run(); std::cerr << "shutdown player!" << std::endl; player.shutdown(); }
void ThrottlingOperationStarterTest::testOperationNotThrottledWhenSlotAvailable() { CPPUNIT_ASSERT(_operationStarter->start(createMockOperation(), OperationStarter::Priority(0))); }