//=============================================================================
// METHOD: SPELLlistenerContext::onNewContext
//=============================================================================
void SPELLlistenerContext::onNewContext( const SPELLipcMessage& msg )
{
    ContextInfo* ctxInfo;

    std::string ctxName = msg.get(MessageField::FIELD_CTX_NAME);

    ctxInfo = &m_openContexts[ctxName];
    ctxInfo->m_key = msg.getKey();
    ctxInfo->m_port = STRI(msg.get(MessageField::FIELD_CTX_PORT));
    ctxInfo->m_status = MessageValue::DATA_CTX_RUNNING;

    DEBUG("New context:");
    DEBUG("- Name=" + ctxInfo->m_name);
    DEBUG("- Key=" + ISTR(ctxInfo->m_key));
    DEBUG("- Port=" + ISTR(ctxInfo->m_port));
    DEBUG("- Status=" + ctxInfo->m_status);

    m_waitForContextStart.set();

    // Notify to other clients
    SPELLipcMessage notify( msg );
    notify.setId( ListenerMessages::MSG_CONTEXT_OP );
    notify.setType( MSG_TYPE_ONEWAY );
    notify.set( MessageField::FIELD_CTX_STATUS, MessageValue::DATA_CTX_RUNNING );
    notify.setSender("LST");
    notify.setReceiver("GUI");
    m_gui->displace(&notify);

    // Send notification to peer if any, and if alignment is enabled
    if (m_peer) m_peer->displace(msg);
}
Esempio n. 2
0
//=============================================================================
// METHOD: SPELLclientIPC::
//=============================================================================
void SPELLclientIPC::processMessage( const SPELLipcMessage& msg )
{
	// Get the peer key
	int clientKey = msg.getKey();

	SPELLclientInterestList* list = getClientInterestList(clientKey);
	if (list != NULL)
	{
		list->distributeMessage(msg);
	}
}
Esempio n. 3
0
//=============================================================================
// METHOD: SPELLclientIPC::
//=============================================================================
SPELLipcMessage SPELLclientIPC::processRequest( const SPELLipcMessage& msg )
{
	int clientKey = msg.getKey();
	DEBUG("[CLTRCV] Received request from client: " + msg.getId());
	SPELLipcMessage resp = VOID_MESSAGE;
	SPELLclientInterestList* list = getClientInterestList(clientKey);
	// If the message is a login message, redirect it to the client manager
	if (msg.getId() == ContextMessages::REQ_GUI_LOGIN)
	{
		SPELLclientManager::instance().clientLogin(clientKey, msg.get( MessageField::FIELD_HOST ));
		resp = SPELLipcHelper::createResponse(ContextMessages::RSP_GUI_LOGIN, msg);
	}
	// If the message is a logout message, redirect it to the client manager
	else if (msg.getId() == ContextMessages::REQ_GUI_LOGOUT )
	{
		// No need to close IPC here. When the GUI receives the response,
		// it will close the channel by sending EOC. There, IPC layer will
		// automatically close the corresponding channel.
		SPELLclientManager::instance().clientLogout(clientKey);
		resp = SPELLipcHelper::createResponse(ContextMessages::RSP_GUI_LOGOUT, msg);
	}
	else if (list != NULL)
	{
		//DEBUG("[CLTRCV] Distribute client request: " + msg.getId());
		resp = list->distributeRequest(msg);
		//DEBUG("[CLTRCV] Got response for client request: " + msg.getId());

		// Executor request additional processing (request attended by executor that need to be processed in context also)
		// But only if the response is not an error
		if (resp.getType() != MSG_TYPE_ERROR)
		{
			if (msg.getId() == ExecutorMessages::REQ_SET_CONFIG)
			{
				SPELLipcMessage cfgChange( msg );
				cfgChange.setId( ContextMessages::MSG_EXEC_CONFIG );
				cfgChange.setType( MSG_TYPE_ONEWAY );
				SPELLclientManager::instance().notifyMonitoringClients(&cfgChange);
			}
		}

		if (resp.isVoid())
		{
			LOG_ERROR("Unable to get response for client request " + msg.getId());
		}
	}
	else
	{
		LOG_ERROR("No listeners for client " + ISTR(clientKey) + " to distribute request: " + msg.getId());
	}
	return resp;
}
Esempio n. 4
0
//=============================================================================
// METHOD: SPELLclientManager::
//=============================================================================
void SPELLclientManager::notifyMonitoringClients( const SPELLipcMessage& msg )
{
	DEBUG("Notify monitoring clients TRY-IN");
	SPELLmonitor m(m_clientLock);
	DEBUG("Notify monitoring clients IN");
	ClientMap::const_iterator it;
	int controllingKey = msg.getKey();
	for( it = m_clientMap.begin(); it != m_clientMap.end(); it++ )
	{
		SPELLclient* client = it->second;
		if (it->first == controllingKey) continue;
		DEBUG("    - client " + ISTR(it->first));
		client->sendMessageToClient(msg);
	}
	DEBUG("Notify monitoring clients done");
}