Beispiel #1
0
int
Task::handle_input( ACE_HANDLE h )
{
    const size_t size = 2000;
    ACE_Message_Block * mb = new ACE_Message_Block( size );
    ACE_Message_Block * pfrom = new ACE_Message_Block( sizeof( ACE_INET_Addr ) );
	ACE_INET_Addr * addr = new ( pfrom->wr_ptr() ) ACE_INET_Addr();

    int res = 0;
	if ( mcast_handler_ && ( h == mcast_handler_->get_handle() ) ) {

		mb->msg_type( constants::MB_MCAST );
		res = mcast_handler_->recv( mb->wr_ptr(), size, *addr );

	}
	if ( res == (-1) ) {
		DWORD err = GetLastError();
		(void)err;
		ACE_Message_Block::release( mb );
		ACE_Message_Block::release( pfrom );
		return 0;
	}
	mb->length( res );
	mb->cont( pfrom );

	putq( mb );

	return 0;
}
Beispiel #2
0
  virtual int svc (void)
  {
    ACE_Thread_ID id;
    thread_id_ = id;
    while (1)
      {
        ACE_Message_Block *mb = 0;
        if (this->getq (mb) == -1)
          ACE_ERROR_BREAK
            ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("getq")));
        if (mb->msg_type () == ACE_Message_Block::MB_HANGUP)
          {
            ACE_DEBUG ((LM_INFO,
                        ACE_TEXT ("(%t) Shutting down\n")));
            mb->release ();
            break;
          }
        // Process the message.
        process_message (mb);
        // Return to work.
        this->manager_->return_to_work (this);
      }

    return 0;
  }
  ////////////////////////////////////////////////////////////////////////
  // Now the svc() method where everything interesting happens.
  //
  int 
  LaserTask::svc()
  {
    MIRO_DBG_OSTR(SICK, LL_DEBUG, "("<<(void *) this <<"|"<<ACE_Thread::self ()<<") Task 0x%x starts in thread %u\n");

    // Where we getq() the message
    ACE_Message_Block *message;
    LaserMessage * data;

    while (true) {
      // Get the message...
      if (getq (message) == -1) {
	throw Miro::Exception("LaserTask::svc: could not getq from message queue");
      }

      // Is it a shutdown request?
      if (message->msg_type () == ACE_Message_Block::MB_HANGUP) {
	break;
      }

      // Get the LaserMessage pointer out of the ACE message block.
      data = (LaserMessage*)message->rd_ptr ();
      if (!data) 
	throw Miro::Exception("LaserTask::svc: got empty message block");
      
      doPkt( data );

      // throw away message block
      message->release ();
    }

    MIRO_LOG(LL_NOTICE, "left service.");

    return (0);
  }
Beispiel #4
0
int
Terminator::svc()
{
  while (1)
    {
      ACE_Message_Block* mb = 0;
      if (this->getq(mb) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%P|%t|%T) ERROR: Terminator::svc() could not get "
                             "message block from queue"), -1);
        }

      if (mb->msg_type () == ACE_Message_Block::MB_HANGUP)
        {
          mb->release ();
          break;
        }
      int delay_secs = ACE_OS::atoi(mb->rd_ptr());
      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t|%T) Terminator::svc() Sleeping %d seconds before aborting\n", delay_secs));
      ACE_OS::sleep(delay_secs);
      ACE_OS::abort();
    }
  return 0;
}
void ZigbeeSerialportService::connect_to_serialport()
{
    ACE_Message_Block *b = new ACE_Message_Block();

    b->msg_type(ZIGBEE_SERIAL_PORT_CMD_CONNECT_PORT);

    task_->message_queue.enqueue_tail(b);
}
Beispiel #6
0
 static ACE_Message_Block * put( const T& t, unsigned long msg_type = 0  ) {
     ACE_Message_Block * mb = new ACE_Message_Block( sizeof(T) );
     *reinterpret_cast<T*>( mb->wr_ptr() ) = t;
     mb->wr_ptr( sizeof(T) );
     if ( msg_type >= ACE_Message_Block::MB_USER )
         mb->msg_type( msg_type );
     return mb;
 }
void ZigbeeSerialportService::exit_and_wait_thread()
{
    ACE_Message_Block *b = new ACE_Message_Block();
    b->msg_type(ZIGBEE_SERIAL_PORT_CMD_EXIT_THREAD);

    task_->message_queue.enqueue_head(b);
    task_->wait();
}
Beispiel #8
0
void
tofSession_i::tof_debug( const CORBA::WChar * text, const CORBA::WChar * key )
{
    ACE_OutputCDR cdr;
    cdr.write_wstring( text );
    cdr.write_wstring( key );
    ACE_Message_Block * mb = cdr.begin()->duplicate();
    mb->msg_type( constants::MB_DEBUG );
    pTask_->putq( mb );
}
Beispiel #9
0
void
Logging::commit_to_task()
{
    // Broker::EventLog, that is not EventLog
    if ( msg.get().format.in() && *msg.get().format.in() != 0 ) {
        TAO_OutputCDR cdr;
        cdr << msg.get();
        ACE_Message_Block * mb = cdr.begin()->duplicate();
        mb->msg_type( constants::MB_EVENTLOG );
        iTask::instance()->putq( mb );
    }
}
Beispiel #10
0
  virtual int put (ACE_Message_Block *mblk, ACE_Time_Value *) 
  {
  
    for (ACE_Message_Block *temp = mblk;      temp != 0;   temp = temp->cont ())    
    {     
    	 if (temp->msg_type () != ACE_Message_Block::MB_STOP)
      {
      	format_data(temp);
      }
    }
    
    return put_next (mblk);
 } 
void RASocket::commandFinished(void* callbackArg, bool /*success*/)
{
    if (!callbackArg)
        return;

    RASocket* socket = static_cast<RASocket*>(callbackArg);
    ACE_Message_Block* mb = new ACE_Message_Block();
    mb->msg_type(ACE_Message_Block::MB_BREAK);
    if (socket->putq(mb) == -1)
    {
        sLog.outRemote("Failed to enqueue command end message. Error is %s", ACE_OS::strerror(errno));
        mb->release();
    }
}
void SiteWorkTask::StopTask()
{
	if (_pSiteRenderTask)
	{
		_pSiteRenderTask->StopTask();

		DEL_PTR(_pSiteRenderTask);
	}

	m_bStopped = true;

	ACE_Message_Block *mb = new ACE_Message_Block();
	mb->msg_type( ACE_Message_Block::MB_STOP );
	this->putq( mb );

}
int ZigbeeSerialportService::handle_input (ACE_HANDLE fd)
{
    {
        ACE_Message_Block *b = new ACE_Message_Block();
        b->msg_type(ZIGBEE_SERIAL_PORT_CMD_GET_RES);

        if (task_->message_queue.enqueue_tail(b)== -1 )
        {
            ACE_DEBUG((LM_DEBUG, "faild to input reactor block into queue\n"));
        }

        reactor()->suspend_handler(this);
    }

    return 0;
}
int SiteWorkTask::svc()
{
	ImageCommRequestArgs *pImageCommRequestArgs = NULL;

	SetupDefaultComments();

	while(true)
	{
		try
		{
			ACE_Message_Block *mb = NULL;
			if( getq(mb) == -1 )
			{
				break;
			}

			if( mb->msg_type() == ACE_Message_Block::MB_STOP )
			{
				mb->release();
				break;
			}

			if (NULL == mb)
			{
				continue;
			}

			memcpy(&pImageCommRequestArgs, mb->rd_ptr(), sizeof(pImageCommRequestArgs));
			onCommandRequest(pImageCommRequestArgs);

			delete pImageCommRequestArgs;
			mb->release();

			if (_pSiteRenderTask)
			{
				_pSiteRenderTask->Process();
			}
		}
		catch(...)
		{
			//throw "work task crashed";
			LOG_ERROR("catch exception.");
		}
	}

	return 0;
}
Beispiel #15
0
 virtual int svc () 
 {
   int stop = 0;          
   for (ACE_Message_Block *mb; !stop && getq (mb) != -1; ) 
   {
     if (mb->msg_type () == ACE_Message_Block::MB_STOP)
     {
       stop = 1;
     }
     else
     {  	      	    
 	    ACE_DEBUG ((LM_DEBUG, "%s",mb->base()));    	                           
     }
     put_next (mb);
   }
   return 0;
 }
int ZigbeeSerialportService::send(ZigbeeRequest  *req)
{
    {
        ACE_Message_Block *b = new ACE_Message_Block(req->size());
        ACE_OS::memcpy(b->base(), req->base(), req->size());

        b->msg_type(ZIGBEE_SERIAL_PORT_CMD_SEND_REQ);

        if (task_->message_queue.enqueue_tail(b) == -1 )
        {
            ACE_DEBUG((LM_DEBUG, "ZigbeeSerialportService faild to input node block into queue\n"));
        }

        delete req;
    }

    return 0;
}
Beispiel #17
0
  virtual int svc (void)
  {
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) starting up %C\n"),
                name_));

    ACE_OS::sleep (2);
    ACE_Message_Block *mb = 0;
    while (this->getq (mb) != -1)
      {
        if (mb->msg_type () == ACE_Message_Block::MB_BREAK)
          {
            mb->release ();
            break;
          }
        process_message (mb);
        mb->release ();
      }
    return 0;
  }
Beispiel #18
0
void RASocket::commandFinished(void* callbackArg, bool /*success*/) {
	if (!callbackArg)
		return;

	RASocket* socket = static_cast<RASocket*>(callbackArg);

	ACE_Message_Block* mb = new ACE_Message_Block();

	mb->msg_type(ACE_Message_Block::MB_BREAK);

	// the message is 0 size control message to tell that command output is finished
	// hence we don't put timeout, because it shouldn't increase queue size and shouldn't block
	if (socket->putq(mb) == -1) {
		// getting here is bad, command can't be marked as complete
		sLog->outRemote("Failed to enqueue command end message. Error is %s",
				ACE_OS::strerror(errno));
		mb->release();
	}
}
Beispiel #19
0
bool CLogManager::Dispose_Queue()
{
    ACE_Message_Block* mb = NULL;
    ACE_OS::last_error(0);

    if (getq(mb, 0) == -1)
    {
        OUR_DEBUG((LM_ERROR, "[CLogManager::svc] get error errno = [%d].\n", ACE_OS::last_error()));
        m_blRun = false;
        return false;
    }
    else if (mb->msg_type() == ACE_Message_Block::MB_STOP)
    {
        m_mutex.acquire();
        mb->release();
        this->msg_queue()->deactivate();
        m_cond.signal();
        m_mutex.release();
        m_blRun = false;
        return true;
    }
    else
    {
        _LogBlockInfo* pLogBlockInfo = *((_LogBlockInfo**)mb->base());

        if (!pLogBlockInfo)
        {
            OUR_DEBUG((LM_ERROR, "[CLogManager::svc] CLogManager mb log == NULL!\n"));
            return true;
        }

        if (0 != ProcessLog(pLogBlockInfo))
        {
            OUR_DEBUG((LM_ERROR, "[CLogManager::svc] ProcessLog is false.\n"));
        }

        //回收日志块
        m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo);
    }

    return true;
}
int AC_Output_Handler::svc () {
  ACE_Message_Block *chunk[ACE_IOV_MAX];
  size_t message_index = 0;
  ACE_Time_Value time_of_last_send (ACE_OS::gettimeofday ());
  ACE_Time_Value timeout;
  ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN);
  ACE_Sig_Action original_action;
  no_sigpipe.register_action (SIGPIPE, &original_action);

  for (;;) {
    if (message_index == 0) {
      timeout = ACE_OS::gettimeofday ();
      timeout += FLUSH_TIMEOUT;
    }
    ACE_Message_Block *mblk = 0;
    if (getq (mblk, &timeout) == -1) {
      if (errno == ESHUTDOWN) {
        if (connector_->reconnect () == -1) break;
        continue;
      } else if (errno != EWOULDBLOCK) break;
      else if (message_index == 0) continue;
    } else {
      if (mblk->size () == 0
          && mblk->msg_type () == ACE_Message_Block::MB_STOP)
        { mblk->release (); break; }
      chunk[message_index] = mblk;
      ++message_index;
    }
    if (message_index >= ACE_IOV_MAX ||
        (ACE_OS::gettimeofday () - time_of_last_send
         >= ACE_Time_Value(FLUSH_TIMEOUT))) {
      if (this->send (chunk, message_index) == -1) break;
      time_of_last_send = ACE_OS::gettimeofday ();
    }
  }

  if (message_index > 0)
    this->send (chunk, message_index);
  no_sigpipe.restore_action (SIGPIPE, original_action);
  return 0;
}
Beispiel #21
0
int ACE_TMAIN (int, ACE_TCHAR **)
{
#if 0
// Just for the book...

// Listing 1 code/ch12
  ACE_Message_Block *mb;
  ACE_NEW_RETURN (mb, ACE_Message_Block (128), -1);

  const char *deviceAddr= "Dev#12";
  mb->copy (deviceAddr, ACE_OS::strlen (deviceAddr)+1);
// Listing 1
#endif /* 0 */
// Listing 2 code/ch12
  ACE_Message_Block *mb;
  ACE_NEW_RETURN (mb, ACE_Message_Block (128), -1);

  const char *commandSeq= "CommandSeq#14";
  ACE_OS::sprintf (mb->wr_ptr (), commandSeq);
  // Move the wr_ptr() forward in the buffer by the
  // amount of data we just put in.
  mb->wr_ptr (ACE_OS::strlen (commandSeq) +1);
// Listing 2
// Listing 3 code/ch12
  ACE_DEBUG((LM_DEBUG,
             ACE_TEXT ("Command Sequence --> %C\n"),
             mb->rd_ptr ()));
  mb->rd_ptr (ACE_OS::strlen (mb->rd_ptr ())+1);
  mb->release ();
// Listing 3
// Listing 4 code/ch12
  // Send a hangup notification to the receiver.
  ACE_NEW_RETURN
    (mb, ACE_Message_Block (128, ACE_Message_Block::MB_HANGUP), -1);
  // Send an error notification to the receiver.
  mb->msg_type (ACE_Message_Block::MB_ERROR);
// Listing 4
  mb->release ();

  return 0;
}
Beispiel #22
0
int RASocket::process_command (const std::string& command)
{
    if (command.length() == 0)
        return 0;

    sLog->outRemote("Got command: %s", command.c_str());

    // handle quit, exit and logout commands to terminate connection
    if (command == "quit" || command == "exit" || command == "logout")
    {
        (void) send("Bye\r\n");
        return -1;
    }

    CliCommandHolder* cmd = new CliCommandHolder(this, command.c_str(), &RASocket::zprint, &RASocket::commandFinished);
    sWorld->QueueCliCommand(cmd);

    // wait for result
    ACE_Message_Block* mb;
    for (;;)
    {
        if (getq(mb) == -1)
            return -1;

        if (mb->msg_type() == ACE_Message_Block::MB_BREAK)
        {
            mb->release();
            break;
        }

        if (size_t(peer().send(mb->rd_ptr(), mb->length())) != mb->length())
        {
            mb->release();
            return -1;
        }

        mb->release();
    }

    return 0;
}
Beispiel #23
0
int RASocket::process_command(const std::string& command)
{
    if (command.length() == 0)
        return 0;

    TC_LOG_INFO(LOG_FILTER_REMOTECOMMAND, "Received command: %s", command.c_str());

    // handle quit, exit and logout commands to terminate connection
    if (command == "quit" || command == "exit" || command == "logout") {
        (void) send("Bye\r\n");
        return -1;
    }

    _commandExecuting = true;
    CliCommandHolder* cmd = new CliCommandHolder(this, command.c_str(), &RASocket::zprint, &RASocket::commandFinished);
    sWorld->QueueCliCommand(cmd);

    // wait for result
    ACE_Message_Block* mb;
    for (;;)
    {
        if (getq(mb) == -1)
            return -1;

        if (mb->msg_type() == ACE_Message_Block::MB_BREAK)
        {
            mb->release();
            break;
        }

        if (send(std::string(mb->rd_ptr(), mb->length())) == -1)
        {
            mb->release();
            return -1;
        }

        mb->release();
    }

    return 0;
}
Beispiel #24
0
int
Task::handle_timeout( const ACE_Time_Value& tv, const void * )
{
	do {
		ACE_Message_Block * mb = new ACE_Message_Block( sizeof( tv ) );
		*reinterpret_cast< ACE_Time_Value *>(mb->wr_ptr()) = tv;
		mb->wr_ptr( sizeof(tv) );
		putq( mb );
	} while(0);
	do {
        TAO_OutputCDR cdr;
		cdr << constants::SESSION_QUERY_DEVICE;
		cdr << TOFConstants::ClassID_AnalyzerDeviceData;
		cdr << TOFConstants::ClassID_MSMethod;
        cdr << GlobalConstants::EOR;
        ACE_Message_Block * mb = cdr.begin()->duplicate();
        mb->msg_type( constants::MB_QUERY_DEVICE );
		this->putq( mb );
	} while(0);
	return 0;
}
// Listing 05 code/ch18
int CommandTask::close (u_long flags)
{
  int rval = 0;
  if (flags == 1)
    {
      ACE_Message_Block *hangup = new ACE_Message_Block;
      hangup->msg_type (ACE_Message_Block::MB_HANGUP);
      if (this->putq (hangup->duplicate ()) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("%p\n"),
                             ACE_TEXT ("Task::close() putq")),
                            -1);
        }

      hangup->release ();
      rval = this->wait ();
    }

  return rval;
}
Beispiel #26
0
 void consume_item ()
 {
   csema_.acquire ();
   if (!is_closed ())
     {
       ACE_Message_Block *mb = 0;
       this->getq (mb);
       if (mb->msg_type () == ACE_Message_Block::MB_HANGUP)
         {
           this->shutdown ();
           mb->release ();
           return;
         }
       else
         {
           ACE_DEBUG ((LM_DEBUG,
                       ACE_TEXT ("(%t) Consumed %d\n"),
                       *((int*)mb->rd_ptr ())));
           mb->release();
         }
       psema_.release ();
     }
 }
Beispiel #27
0
int ZigbeeRequest::get()
{
    ACE_Message_Block *b = new ACE_Message_Block(this->size());

    if(b)
    {
        ACE_OS::memcpy(b->base(), this->base(), this->size());
        b->msg_type(EventNotifyHandler::EventSerialportSendData);

        if ( -1 == _zigbeeHelper::instance()->eventQ()->putQ(b))
        {
            b->release();
        }

        delete this;
    }
    else
    {
        delete this;
    }

    return 0;
}
  ////////////////////////////////////////////////////////////////////////
  // Now the svc() method where everything interesting happens.
  //
  int 
  LaserTask::svc()
  {
#ifdef DEBUG
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) Task 0x%x starts in thread %u\n", (void *) this, ACE_Thread::self ()));
#endif

    // Where we getq() the message
    ACE_Message_Block *message;
    LaserMessage * data;

    while (true) {
      // Get the message...
      if (getq (message) == -1) {
	throw Miro::Exception("LaserTask::svc: could not getq from message queue");
      }

      // Is it a shutdown request?
      if (message->msg_type () == ACE_Message_Block::MB_HANGUP) {
	break;
      }

      // Get the LaserMessage pointer out of the ACE message block.
      data = (LaserMessage*)message->rd_ptr ();
      if (!data) 
	throw Miro::Exception("LaserTask::svc: got empty message block");
      
      doPkt( data );

      // throw away message block
      message->release ();
    }

    log(INFO, "left service.");

    return (0);
  }
  virtual int svc (void)
  {
    thread_id_ = ACE_Thread::self ();
    while (1)
      {
        ACE_Message_Block *mb = NULL;
        ACE_ASSERT (this->getq (mb) != -1);
        if (mb->msg_type () == ACE_Message_Block::MB_HANGUP)
          {
            ACE_DEBUG ((LM_INFO,
                        ACE_TEXT ("(%t) Shutting down\n")));
            mb->release ();
            break;
          }

        // Process the message.
        process_message (mb);

        // Return to work.
        this->manager_->return_to_work (this);
      }

    return 0;
  }
Beispiel #30
0
int
Task::svc()
{
	barrier_.wait();

	for ( ;; ) {

		ACE_Message_Block * mblk = 0;

		if ( this->getq( mblk ) == (-1) ) {
			if ( errno == ESHUTDOWN )
				ACE_ERROR_RETURN((LM_ERROR, "(%t) queue is deactivated\n"), 0);
			else
				ACE_ERROR_RETURN((LM_ERROR, "(%t) %p\n", "putq"), -1);
		}
		if ( mblk->msg_type() == ACE_Message_Block::MB_HANGUP ) {
			this->putq( mblk ); // forward the request to any peer threads
			break;
		}
		doit( mblk );
		ACE_Message_Block::release( mblk );
	}
	return 0;
}