예제 #1
0
void EventHandler::raise_event( const std::string& ename, SignalArgs& args)
{
  if ( signal_exists(ename) == false ) return;

  // event exists so dispatch

  call_signal(ename, args);
}
예제 #2
0
void ServerNetworkComm::callback_read( TCPConnection::Ptr conn,
                                       const boost::system::error_code & error )
{
  if( !error )
  {
    std::string error_msg;
    ClientInfo& info = m_clients[conn];
    SignalFrame & buffer = info.buffer;

    std::string target = buffer.node.attribute_value( "target" );
    std::string receiver = buffer.node.attribute_value( "receiver" );
    std::string clientid = buffer.node.attribute_value( "clientid" );
    std::string frameid = buffer.node.attribute_value( "frameid" );

    // check if the client is attempting to register
    if( target == "client_registration" )
    {
      if( !info.uuid.empty() )
        error_msg = "This client has already been registered.";
      else
      {
        info.uuid = clientid;

        // Build and send the reply
        SignalFrame reply = buffer.create_reply();
        SignalOptions & roptions = reply.options();

        roptions.add("accepted", true);
        roptions.flush();

        this->init_send(conn, buffer );

        // tell listeners a new client has arrived
        SignalFrame frame("new_client_connected", "cpath:/", "cpath:/");
        frame.options().add( "clientid", clientid );
        call_signal( "new_client_connected", frame );
      }
    }
    else
    {
      if( info.uuid.empty() )
        error_msg = "The signal came from an unregistered client.";
      else if( info.uuid != clientid )
        error_msg = "The client id '" + info.uuid + "' (used for registration) "
            + "and '" + clientid + "' (used for identification) do not match.";
      else
        ServerRoot::instance().process_signal(target, receiver, clientid, frameid, buffer);
    }

    if( !error_msg.empty() )
      this->send_frame_rejected( conn, frameid, SERVER_CORE_PATH, error_msg );

    init_read( info );
  }
  else if( error != boost::asio::error::eof )
    CFerror << "Could not read from [" << conn->socket().remote_endpoint()
            << "]: " << error.message() << CFendl;

  if( error )
  {
    std::string uuid = m_clients[conn].uuid;
    conn->disconnect();
    m_clients.erase( conn );

    if( error == boost::asio::error::eof )
      CFinfo << "Cliemt [" << uuid << "] has disconnected. ("
             << m_clients.size() << " left)." << CFendl;
  }

}
예제 #3
0
 /* -------------------------------------------------------------------
 * helper to call the sigalarm function
 * ------------------------------------------------------------------- */
void call_sigalrm() {
    call_signal(SIGALRM);
} // end call_sigalrm