Exemple #1
0
// Init Live Tracker services, if available
void LiveTrackerInit()
{
  if (LiveTrackerInterval == 0) {
    // If livetracker is not enabled at startup, we do nothing, 
    // but in this case LK must be restarted, if user enables it!
    #if TESTBENCH
    StartupStore(TEXT(". LiveTracker disabled.%s"), NEWLINE);
    #endif
    return;
  }
  //Init winsock if available
  if (InitWinsock()) {
    _ws_inited = true;

    // Create a thread for sending data to the server
    _Thread.start(_ThreadTarget);
    _Thread.setPriority(Poco::Thread::PRIO_NORMAL);
    TCHAR2ascii(LiveTrackersrv_Config, _server_name, SERVERNAME_MAX);
    _server_name[SERVERNAME_MAX-1]=0;
    _server_port=LiveTrackerport_Config;
    StartupStore(TEXT(". LiveTracker will use server %s if available.%s"), LiveTrackersrv_Config, NEWLINE);
    _inited = true;
  }
  if (!_inited) StartupStore(TEXT(". LiveTracker init failed.%s"),NEWLINE);
}
Exemple #2
0
  /** Start the threads and begin looking for tasks.
   *
   * @param waitSec :: how many seconds will each thread be allowed to wait (with no tasks scheduled to it)
   *        before exiting. Default 0.0 (exit right away).
   *        This allows you to start a ThreadPool before you start adding tasks.
   *        You still need to call joinAll() after you've finished!
   *
   * @throw runtime_error if called when it has already started.
   */
  void ThreadPool::start(double waitSec)
  {
    if (m_started)
      throw std::runtime_error("Threads have already started.");

    //Delete any old threads (they should NOT be running!)
    for (size_t i=0; i < m_threads.size(); ++i)
      delete m_threads[i];
    for (size_t i=0; i < m_runnables.size(); ++i)
      delete m_runnables[i];

    // Now, launch that many threads and let them wait for new tasks.
    m_threads.clear();
    m_runnables.clear();
    for (size_t i = 0; i < m_numThreads; i++)
    {
      // Make a descriptive name
      std::ostringstream name;
      name << "Thread" << i;
      // Create the thread
      Poco::Thread * thread = new Poco::Thread(name.str());
      m_threads.push_back(thread);

      // Make the runnable object and run it
      ThreadPoolRunnable * runnable = new ThreadPoolRunnable(i, m_scheduler, m_prog, waitSec);
      m_runnables.push_back(runnable);

      thread->start(*runnable);
    }
    // Yep, all the threads are running.
    m_started = true;
  }
	int main(const std::vector<std::string>& args)
	{
		if (_helpRequested)
		{
			displayHelp();
		}
		else
		{
			// get parameters from configuration file
			unsigned short port = (unsigned short)config().getInt("TimeServer.port", 9911);
			std::string format(config().getString("TimeServer.format", Poco::DateTimeFormat::ISO8601_FORMAT));

			// set-up a server socket
			Poco::Net::ServerSocket svs(port);
			// set-up a TCPServer instance
			Poco::Net::TCPServer srv(new TimeServerConnectionFactory(format), svs);
			// start the TCPServer
			srv.start();

			// start push thread
			Poco::Thread thread;
			PushRunnable runnable;
			thread.start(runnable);

			// wait for CTRL-C or kill
			waitForTerminationRequest();
			// Stop the TCPServer
			srv.stop();
		}
		return Application::EXIT_OK;
	}
Exemple #4
0
void MapWindow::CreateDrawingThread(void)
{
  Initialize();

  CLOSETHREAD = FALSE;
  THREADEXIT = FALSE;

#ifndef ENABLE_OPENGL
  MapWindowThread.start(MapWindowThreadRun);
  MapWindowThread.setPriority(Poco::Thread::PRIO_NORMAL);
#endif
}
Exemple #5
0
// Shutdown Live Tracker
void LiveTrackerShutdown()
{
  if (_Thread.isRunning()) {
    _t_end = false;
    _t_run = false;
    NewDataEvent.set();
    _Thread.join();
    StartupStore(TEXT(". LiveTracker closed.%s"),NEWLINE);
  }
#ifdef WIN32
  if (_ws_inited) {
    WSACleanup();
  }
#endif
}
Exemple #6
0
void MapWindow::CloseDrawingThread(void)
{
#ifndef ENABLE_OPENGL
  #if TESTBENCH
  StartupStore(_T("... CloseDrawingThread started\n"));
  #endif
  CLOSETHREAD = TRUE;
  drawTriggerEvent.set(); // wake self up
  SuspendDrawingThread();

  #if TESTBENCH
  StartupStore(_T("... CloseDrawingThread waitforsingleobject\n"));
  #endif
  #ifdef __linux__
  #else
  drawTriggerEvent.reset(); // on linux this is delaying 5000
  #endif
  MapWindowThread.join();

  #if TESTBENCH
  StartupStore(_T("... CloseDrawingThread wait THREADEXIT\n"));
  #endif
  while(!THREADEXIT) { Poco::Thread::sleep(50); };
  #if TESTBENCH
  StartupStore(_T("... CloseDrawingThread finished\n"));
  #endif
#else
  CLOSETHREAD = TRUE;
  THREADEXIT = TRUE;
#endif
}
void PothosUtilBase::proxyServer(const std::string &, const std::string &uriStr)
{
    Pothos::init();

    //parse the URI
    const std::string defaultUri = "tcp://0.0.0.0:"+Pothos::RemoteServer::getLocatorPort();
    Poco::URI uri(uriStr.empty()?defaultUri:uriStr);
    const std::string &host = uri.getHost();
    const std::string &port = std::to_string(uri.getPort());
    if (uri.getScheme() != "tcp")
    {
        throw Pothos::Exception("PothosUtil::proxyServer("+uriStr+")", "unsupported URI scheme");
    }

    //create server socket
    Poco::Net::SocketAddress sa(host, port);
    Poco::Net::ServerSocket serverSocket(sa);
    Poco::Net::TCPServerConnectionFactory::Ptr factory(new MyTCPServerConnectionFactory());
    Poco::Net::TCPServer tcpServer(factory, serverSocket);

    //start the server
    std::cout << "Host: " << serverSocket.address().host().toString() << std::endl;
    std::cout << "Port: " << serverSocket.address().port() << std::endl;
    serverSocket.listen();
    tcpServer.start();

    //monitor active connections in monitor mode
    if (this->config().hasOption("requireActive"))
    {
        //create a TCP connection monitor thread
        MyTCPConnectionMonitor monitor(tcpServer);
        Poco::Thread monitorThread;
        monitorThread.start(monitor);

        //wait here until the term signal is received
        this->waitForTerminationRequest();

        //end the monitor thread
        monitor.running = false;
        monitorThread.join();
    }
    else
    {
        //wait here until the term signal is received
        this->waitForTerminationRequest();
    }
}
bool MessageServer::startServer( int _port ){
	port = _port;

	Poco::Thread messageHandler;
	Poco::Thread *netThread = netServer.startServer( port );

	if( !netThread ){
		return false;
	}

	messageHandler.start( *this );

	string s;
	while(true){
		cin >> s;
		if( s.compare("quit") == 0 ){
			break;
		}
	}

	return true;
}
Exemple #9
0
// Start the node, which creates a thread for it
void
ThreadNode::start()
{
    Poco::Thread * t = new Poco::Thread();
    t->start(*this);
}
Exemple #10
0
 void FileProcessor::start() {
   Poco::Thread thread;
   thread.start(*this);
   thread.join();
 }