Ejemplo n.º 1
0
bool JsAgent::dispatchAndReturn(JsValue& ret) {
	ArchiveReader<Channel> ar(*m_channel);
	while(true) {
		Debug::println("Waiting for MessageHeader...");
		MessageHeader mh;
		if(!mh.serialize(ar))
			return false;

		switch(mh.getMessageType()) {
			case MT_DefineFunction:
				Debug::println("MT_DefineFunction");
				MSG_DISPATCH(DefineFunctionMessage, onDefineFunction);
				break;
			case MT_InvokeFunction:
				Debug::println("MT_InvokeFunction");
				MSG_DISPATCH(InvokeFunctionMessage, onInvokeFunction);
				break;
			case MT_Return: {
					Debug::println("MT_Return");
					ReturnMessage msg; 
					msg.serialize(ar); 
					return onReturn(msg, ret);
				}
			case MT_Quit:
				Debug::println("MT_Quit");
				return true;
			default:
				Debug::println("Unknown message type!");
				return false;
		}

	}
	return false;
}
Ejemplo n.º 2
0
bool JsAgent::getTypeInfo(uint32_t targetId, GetTypeResponseMessage& ret) {
	Debug::println("JsAgent::getTypeInfo: %d", targetId);

	GetTypeRequestMessage msg;
	msg.targetId = targetId;

	ArchiveWriter<Channel> writer(*m_channel);
	if(!Message::send(msg, writer))
		return false;

	ArchiveReader<Channel> reader(*m_channel);
	MessageHeader mh;
	if(!mh.serialize(reader))
		return false;

	if(mh.getMessageType() != MT_GetTypeResponse)
		return false;

	return ret.serialize(reader);
}