Exemplo n.º 1
0
void ECPManager::processTQR(){
  debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Begin");
  while(!_exit){
    debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] I'm waiting for requests to process");
    sem_wait(_tqrSemaphore);

		debug(
	  std::string("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Requests size: ") + \
	  std::to_string(_tqrRequests.size()));
    _tqrMutex.lock();           //Lock the queue to remove a request
                               //MultiThreading requires this mutex
    debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Getting TQR Request from the queue");

    RequestECP r = _tqrRequests.front();
    _tqrRequests.pop();

		debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] TQR Deleted from the queue");

    _tqrMutex.unlock();         //Lock the queue to remove a request

		debug(std::string("Request: ").append(r.read()));

    std::pair <std::string,int> topicsList;
    std::string answer;


	// Request beeing handled
    try{
      topicsList = topics();
      answer = "AWT ";
      answer += std::to_string(topicsList.second);
      answer += std::string(" ");
      answer += topicsList.first;
      answer += std::string("\n");
    }catch(std::string s){
      if(s == std::string("EOF")){
        answer = s;
      }
    }
	// End of Handle

    r.answer(answer);
    _answerMutex.lock();

		debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Inserting Request on Answer Queue");

    _answers.push(r);

		debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Inserted Request on Answer Queue");

    _answerMutex.unlock();

		debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Posting Answer Semaphore");

    sem_post(_answerSemaphore); //So answers thread can know that there is an
                                //answer to send
		debug("[ [MAGENT]ECPManager::processTQR[REGULAR]      ] Answer Semaphore Post");

  }
}
Exemplo n.º 2
0
/**
 * Connect to input Scrip and Field, registering it with input topic number
 */
void RTDClient::connectTopic(  long topic_id, const std::string &topic_1, const std::string &topic_2  ){
    
    if( topic_2.empty()  ){                                                 // Ignore Empty Fields
        return;
    }

    int topics_count;  is_NOW ? topics_count=3 : topics_count=2;            // TODO Workaround - Pass MktWatch as Topic 1 for NOW
    CComSafeArray<VARIANT> topics(topics_count);

    if( is_NOW ){
        topics[0] = CComBSTR( "MktWatch" );
        topics[1] = CComBSTR(topic_1.c_str());
        topics[2] = CComBSTR(topic_2.c_str());
    }
    else{
        topics[0] = CComBSTR(topic_1.c_str());
        topics[1] = CComBSTR(topic_2.c_str());
    }
    
    VARIANT_BOOL getNewValues = VARIANT_TRUE;
    CComVariant  output;

    HRESULT hr = comObjectScripRTD->ConnectData(topic_id, topics.GetSafeArrayPtr(), &getNewValues, &output);
        
    if( FAILED(hr) ){
        std::cout << "Topic Connection Failed - " << topic_1 << " | " << topic_2 << " - hr - " << hr << " - " << is_NOW << std::endl;
    }
    else{
        std::cout << "Topic Connected - " << topic_id << " - " << topic_1 << " | " << topic_2 << std::endl;    
        connected_topics.insert( topic_id );
    }
}
//--------------------------------------------------------------
void testApp::setup(){
	
	ofBackground(0);
	ofSetVerticalSync(true);
	ofSetFrameRate(60);
	
    
    //sets the HUD
    
	parser.loadFromFiles();
    
    std::set<string> topics(parser.getAllKeywords().begin(),
                            parser.getAllKeywords().end() );

	hud.setup();
    hud.setTopics(topics);
    
    empty.setup();
    empty.playSystem();
    empty.setDrawToScreen(false);

}