示例#1
0
websocket_api_connection::websocket_api_connection( fc::http::websocket_connection& c )
   : _connection(c)
{
   _rpc_state.add_method( "call", [this]( const variants& args ) -> variant
   {
      FC_ASSERT( args.size() == 3 && args[2].is_array() );
      return this->receive_call(
         args[0].as_uint64(),
         args[1].as_string(),
         args[2].get_array() );
   } );

   _rpc_state.add_method( "notice", [this]( const variants& args ) -> variant
   {
      FC_ASSERT( args.size() == 2 && args[1].is_array() );
      this->receive_notice( args[0].as_uint64(), args[1].get_array() );
      return variant();
   } );

   _rpc_state.add_method( "callback", [this]( const variants& args ) -> variant
   {
      FC_ASSERT( args.size() == 2 && args[1].is_array() );
      this->receive_callback( args[0].as_uint64(), args[1].get_array() );
      return variant();
   } );

   _rpc_state.on_unhandled( [&]( const std::string& method_name, const variants& args )
   {
      return this->receive_call( 0, method_name, args );
   } );

   _connection.on_message_handler( [&]( const std::string& msg ){ on_message(msg,true); } );
   _connection.on_http_handler( [&]( const std::string& msg ){ return on_message(msg,false); } );
   _connection.closed.connect( [this](){ closed(); } );
}
示例#2
0
void SpecialZone::onEnter(const int slot_id) {
	if (type == "checkpoint") 
		onCheckpoint(slot_id);
	else if (type == "hint") 
		onHint(slot_id);
	else if (type == "message") 
		on_message(slot_id);
	else if (type == "timer-lose") 
		onTimer(slot_id, false);
	else if (type == "timer-win") 
		onTimer(slot_id, true);
	else if (type == "reset-timer") 
		GameMonitor->resetTimer();
	else if (type == "disable-ai") 
		GameMonitor->disable(name);
	else if (type == "enable-ai") 
		GameMonitor->disable(name, false);
	else if (type == "play-tune") 
		Mixer->play(name, true);
	else if (type == "reset-tune") 
		Mixer->reset();
	else if (type == "z-warp") {
		onWarp(slot_id, true);
	} else if (type == "script") {
		GameMonitor->onScriptZone(slot_id, *this, true);
	} else if (type == "local-script") {
		GameMonitor->onScriptZone(slot_id, *this, false);
	} else
		throw_ex(("unhandled enter for type '%s'", type.c_str()));
}
示例#3
0
    void on_read()
    {
        while(true) {
            pac.reserve_buffer(32*1024);

            size_t len = static_cast<size_t>(input.readsome(pac.buffer(), pac.buffer_capacity()));

            if(len == 0) {
                return;
            }

            pac.buffer_consumed(len);

            while(pac.execute()) {
                msgpack::unique_ptr<msgpack::zone> z(pac.release_zone());
                msgpack::object obj = pac.data();
                pac.reset();
                on_message(obj, msgpack::move(z));
            }

            if(pac.message_size() > 10*1024*1024) {
                throw std::runtime_error("message is too large");
            }
        }
    }
示例#4
0
long TWBaseScript::dispatch_message(sScrMsg* msg, sMultiParm* reply)
{
    // Only bother checking for fixup stuff if it hasn't been done.
    if(need_fixup) {
        // On starting sim, fix any links if possible
        if(!::_stricmp(msg -> message, "Sim") && static_cast<sSimMsg*>(msg) -> fStarting) {
            fixup_player_links();

        // Catch and handle the deferred player link fixup if needed
        } else if(!::_stricmp(msg -> message, "Timer") &&
                  !::_stricmp(static_cast<sScrTimerMsg*>(msg) -> name, "DelayInit") &&
                  static_cast<sScrTimerMsg*>(msg) -> data == "FixupPlayerLinks") { // Note: data is a cMultiParm, so == does a strcmp internally
            fixup_player_links();
        }
    }

    // Capture and bin Null messages (to prevent TornOn/TurnOff triggering in
    // subclasses when the TirnOn/TurnOff message has been set to Null)
    if(!::_stricmp(msg -> message, "Null")) {
        return S_OK;
    }

    // Invoke the message handling!
    return (on_message(msg, static_cast<cMultiParm&>(*reply)) != MS_ERROR);
}
示例#5
0
	BOOL dialog_modeless::on_message_wrap(UINT msg,WPARAM wp,LPARAM lp)
	{
		if (m_destructor_status == destructor_none)
			return on_message(msg,wp,lp);
		else
			return FALSE;
	}
    TEST(PeerConnectionClientTest, EchoTest) {
        MockPeerConnectionListener mockPeerConnectionListener;

        PeerConnectionClient *peerConnectionClient = new PeerConnectionClient();
        peerConnectionClient->connect("ws://echo.websocket.org");

        peerConnectionClient->add_listener(0, &mockPeerConnectionListener);

        EXPECT_CALL(mockPeerConnectionListener, on_message(_, _));

        // Allow 5 seconds for connection to open.
        // This could be done via signaling, but as normally we are only waiting for incomming messages, we there is no point
        // setting up a signaling architecture.
        int i = 0;
        ConnectionMetadata::Status status = peerConnectionClient->get_status(0);
        while (status != ConnectionMetadata::OPEN && i < 5) {
            sleep(1);
            status = peerConnectionClient->get_status(0);
            i++;
        }

        ASSERT_EQ(ConnectionMetadata::OPEN, peerConnectionClient->get_status(0));

        peerConnectionClient->send(0, "Hello World");
        sleep(1); // Should return in < 1sec
    };
示例#7
0
std::shared_ptr<native_endpoint> native_server_impl::on_connect(
        const std::shared_ptr<native_endpoint>& component_endpoint)
{
    auto connection = std::make_shared<native_connection>(
            m_io_service, component_endpoint);
    std::weak_ptr<native_server_impl> weak_this = shared_from_this();

    auto receive_handler = [this, weak_this](
            const std::shared_ptr<native_connection>& connection,
            std::vector<msgpack::object>&& fields,
            msgpack::zone&& zone) {
        auto shared_this = weak_this.lock();
        if (!shared_this) {
            // There is nothing to do here but silently dismiss this
            // error condition. If the server or connection has gone
            // away then the message being recevied is meaningless.
            return;
        }

        on_message(connection, std::move(fields), std::move(zone));
    };
    connection->set_receive_message_handler(
            std::bind(receive_handler, std::placeholders::_1,
                    std::placeholders::_2, std::placeholders::_3));

    auto server_endpoint = connection->get_server_endpoint();
    m_connections.insert(connection);
    m_endpoints_connected[server_endpoint] = connection;

    return server_endpoint;
}
示例#8
0
void
stream_handler::drain_read_buffer() {
   tracer.trace8("Searching the read buffer for new messages");
   int bytes_passed_to_user = 0;
   while(true) {
      int msg_break = next_message_break(read_buf + bytes_passed_to_user,
                                         bytes_read - bytes_passed_to_user);
      if(msg_break == -1) {
         break;
      }
      tracer.trace8("Message of length %d received", msg_break);
      bytes_passed_to_user += next_message_length;
      on_message(read_buf + bytes_passed_to_user, msg_break);
      bytes_passed_to_user += msg_break;
      // Ignore the delimiter message
      bytes_passed_to_user += delimiter_length; 
   }      
   bytes_read = bytes_read - bytes_passed_to_user;
   if(bytes_read) {
      tracer.trace7("Saving %zu bytes for next message", bytes_read);
   }
   // A circular buffer (like boost::circular_buffer) would make
   // this more efficient, but let's not introduce dependencies for
   // this helper example library.
   memmove(read_buf, read_buf + bytes_passed_to_user, bytes_read);
}
示例#9
0
文件: core.cpp 项目: wonghoifung/tips
int core::on_close(stream_handler* sh, const int err)
{
  if (sh) {
    outmessage msg;
    msg.begin(cmd_sock_close);
    msg.write_int(err);
    msg.end();

    inmessage fakemsg;
    fakemsg.copy(msg.buffer(), msg.size());

    on_message(sh, &fakemsg);
  }
  return 0;
}
示例#10
0
static void
msg_received(DictionaryIterator *iterator, void *context)
{
  bool added;
  
  on_message(iterator, &added);
  
  if (!added)
    return;

  // Success. Rewind to the top of the stack and reload.
  while (window_stack_get_top_window() != context)
    window_stack_pop(true);
  menu_reload(context);
}
示例#11
0
void ipc_client::trigger(int nMsg, void* data, int dlen)
{
	std::list<int>::iterator it = messages_.begin();

	// 该消息是否已经存在于已经注册的消息集合中
	for (; it != messages_.end(); ++it)
	{
		if (*it == nMsg)
		{
			on_message(nMsg, data, dlen);
			return;
		}
	}

	logger_warn("unknown msg: %d", nMsg);
}
示例#12
0
	BOOL dialog_modeless_v2::on_message_internal(UINT msg,WPARAM wp,LPARAM lp)
	{
		if (m_status == status_lifetime || m_status == status_destruction_requested)
		{
			if (msg == WM_DESTROY)
			{
				assert(m_status == status_lifetime);
				m_status = status_destruction_requested;
				delete this;
				return TRUE;
			}
			else 
				return on_message(msg,wp,lp);
		}
		else if (m_status == status_construction)
		{
			if (msg == WM_INITDIALOG) return m_stealfocus ? TRUE : FALSE;
			else return FALSE;
		}
		else return FALSE;
	}
示例#13
0
    void on_read()
    {
        while(true) {
            pac.reserve_buffer(32*1024);

            size_t len = static_cast<size_t>(input.readsome(pac.buffer(), pac.buffer_capacity()));

            if(len == 0) {
                return;
            }

            pac.buffer_consumed(len);

            msgpack::object_handle oh;
            while(pac.next(oh)) {
                on_message(oh.get(), msgpack::move(oh.zone()));
            }

            if(pac.message_size() > 10*1024*1024) {
                throw std::runtime_error("message is too large");
            }
        }
    }
示例#14
0
void avim_group_impl::internal_loop_coroutine(boost::asio::yield_context yield_context)
{

	for(;!m_quitting;)
	{
		std::string sender, data;

		m_core.async_recvfrom(sender, data, yield_context);

		if(is_group_message(data))
		{
			if (group_message_get_sender(data) == sender)
			{
				// 转发
				recive_client_message(data);

				// 看是否能解码 group 消息
				if (!is_encrypted_message(data))
				{
					auto im = decode_im_message(data);

					std::vector<avim_msg> avmsg;

					for (const message::avim_message& im_item : im.impkt.avim())
					{
						avim_msg item;
						if (im_item.has_item_text())
						{
							item.text = im_item.item_text().text();
						}
						if (im_item.has_item_image())
						{
							item.image = im_item.item_image().image();
						}
						avmsg.push_back(item);
					}
					on_message(m_me_addr, im.sender, avmsg);
				}
			}
		}
        else if (is_control_message(data))
		{
			// 无非就是获取群列表嘛!
			std::string _sender;
			auto bufmsg = decode_control_message(data, _sender);

			if (bufmsg->GetTypeName() == "proto.group.list_request")
			{
				auto list_request= reinterpret_cast<proto::group::list_request*>(bufmsg.get());

				proto::group::list_response list_response;
				list_response.set_result(proto::group::list_response::OK);

				auto avs =  get_lines(m_groupdef);

				for ( auto a : avs )
					list_response.add_list()->assign(a);

				m_core.async_sendto(sender, encode_control_message(list_response), yield_context);
			}
		}
	}
}
示例#15
0
文件: app.c 项目: joyxuyichao/JUMP
void ble_device_on_message(uint8_t type, uint16_t length, uint8_t* value)
{
  if(on_message) on_message(type, length, value);
}
示例#16
0
void MulticastHandler::dispatch(
	boost::asio::ip::address senderAddress,
	MulticastNetwork::Command command,
	char *args,
	unsigned char argsSize,
	bool forward)
{
	typedef MulticastNetwork::Command Command;

	m_senderAddress = &senderAddress;
	bool valid = false;

	if (Command::Candidate == command && sizeof(uint32_t) == argsSize) {
		valid = true;
		on_candidate(ntohl(*reinterpret_cast<uint32_t*>(args)));
	}
	else if (Command::ElectGateway == command && 0 == argsSize) {
		valid = true;
		on_electGateway();
	}
	else if (Command::Forward == command && 0 < argsSize)
	{
		valid = true;
		on_forward(static_cast<Command>(args[0]), args + 1, argsSize - 1);
	}
	else if (Command::Gateway == command && 0 == argsSize)
	{
		valid = true;
		on_gateway();
	}
	else if (Command::Hello == command && sizeof(float) < argsSize) {
		valid = true;
		uint32_t b = ntohl(*reinterpret_cast<uint32_t*>(args + argsSize - sizeof(float)));
		on_hello(std::string(args, argsSize - sizeof(float)),
			*reinterpret_cast<float*>(&b));
	}
	else if (Command::Message == command && 0 < argsSize) {
		valid = true;
		on_message(std::string(args, argsSize));
	}
	else if (Command::RemoteGateway == command && 0 == argsSize) {
		valid = true;
		on_remoteGateway();
	}
	else if (Command::SearchBlock == command && sizeof(uint32_t) < argsSize) {
		valid = true;
		on_searchBlock(std::string(args, argsSize - sizeof(uint32_t)),
			*reinterpret_cast<uint32_t*>(args + argsSize - sizeof(uint32_t)));
	}
	else if (Command::SearchFileName == command && 0 < argsSize) {
		valid = true;
		on_searchFileName(std::string(args, argsSize));
	}
	else if (Command::SearchFileNameReply == command && 0 < argsSize) {
		valid = true;
		std::map<std::string, std::pair<float, std::string>> results;

		int index = 0;
		while (index < argsSize) {
			float filesize;
			int stringLength = 0;
			for (int i = index + Hash::SIZE + sizeof filesize; i < argsSize; i++) {
				if (args[i] == '\0') {
					break;
				}

				++stringLength;
			}

			if (index + stringLength + Hash::SIZE + sizeof filesize >= argsSize) {
				break;
			}

			std::string hash(args + index, Hash::SIZE);
			filesize = *reinterpret_cast<float*>(args + index + Hash::SIZE);

			std::string filename(args + index + Hash::SIZE + sizeof filesize, stringLength);
			results[filename] = std::pair<float, std::string>(filesize, hash);
			index += Hash::SIZE + sizeof filesize + stringLength + 1;
		}

		on_searchFileNameReply(results);
	}

	if (valid && forward) {
		m_gateway->forward(*m_senderAddress, command, args, argsSize);
	}
}
示例#17
0
void Player::handle_message(Message msg) {
    if (msg.type == Message::TypeEmpty) {
        // status package, discard
        return;
    }
    
    Bus &bus = buses[msg.bus];
    Channel &values = bus.channels[msg.bus_channel];
    
    if (msg.type == Message::TypeMIDI) {
        if (msg.command == MIDI::CommandControlChange) {
            switch(msg.data1) {
                case MIDI::ControllerAllNotesOff:
                {
                    for (NoteArray::iterator iter = bus.notes.begin();
                         iter != bus.notes.end(); ++iter) {
                        *iter = -1;
                    }
                    on_message(msg);
                } break;
                default:
                {
                    on_message(msg);
                } break;
            }
            return;
        } else if (msg.command == MIDI::CommandAftertouch) {
            if (values.note != ValueNone) {
                // insert note and pass on
                msg.data1 = values.note;
                on_message(msg);
            } else {
                msg.command = MIDI::CommandChannelPressure;
                msg.data1 = msg.data2;
                msg.data2 = 0;
                on_message(msg);
            }
            return;
        } else if (msg.command == MIDI::CommandNoteOff) {
            if (values.note != ValueNone) {
                int note = values.note;
                values.note = ValueNone;
                // see if that note is actually being played
                // on our channel, if yes, kill it.
                if (bus.notes[note] == msg.bus_channel) {
                    bus.notes[note] = -1;
                    msg.data1 = note;
                    msg.data2 = 0;
                    on_message(msg);
                }
            }
            return;
        } else if (msg.command == MIDI::CommandNoteOn) {
            if (values.note != ValueNone) {
                int note = values.note;
                values.note = ValueNone;
                // no matter where the note is played, kill it.
                bus.notes[note] = -1;
                Message off_msg(msg);
                off_msg.command = MIDI::CommandNoteOff;
                off_msg.data1 = note;
                off_msg.data2 = 0;
                on_message(off_msg);
            }
            values.note = msg.data1;
            int volume = std::min((int)((float)(msg.data2) * values.volume), 0x7f);
            msg.data2 = volume;
            bus.notes[values.note] = msg.bus_channel;
            on_message(msg);
            return;
        }
    } else if (msg.type == Message::TypeCommandChannelVolume) {
        values.volume = std::min((float)(msg.status) / 0x7f, 1.0f);
    }
}
示例#18
0
LRESULT
Window::on_message(HWND _hWnd, UINT message,
                       WPARAM wParam, LPARAM lParam)
{
  if (IsEmbedded() && !IsAltair()) {
    /* some older iPaqs such as the H3900 send only WM_KEYUP for
       VK_APP*, but never VK_KEYDOWN; the hx4700 has an additional set
       of undocumented key codes (0xca..0xcd) for the APP keys, but
       sends WM_KEYUP/VK_APP* additionally; the following rules
       hopefully catch all of these obscurities */
    if (message == WM_KEYUP && wParam >= 0x80)
      /* convert to WM_KEYDOWN to make all handlers catch it */
      message = WM_KEYDOWN;
    else if (message == WM_KEYDOWN && wParam >= 0x80)
      /* ignore the real WM_KEYDOWN, just in case it really happens */
      return 0;
  }

  switch (message) {
  case WM_CREATE:
    on_create();
    return 0;

  case WM_DESTROY:
    on_destroy();
    return 0;

  case WM_CLOSE:
    if (on_close())
      /* true returned: message was handled */
      return 0;
    break;

  case WM_SIZE:
    on_resize(LOWORD(lParam), HIWORD(lParam));
    return 0;

  case WM_MOUSEMOVE:
    if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam))
      return 0;
    break;

  case WM_LBUTTONDOWN:
    if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_LBUTTONUP:
    if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_LBUTTONDBLCLK:
    if (!double_clicks)
      /* instead of disabling CS_DBLCLKS (which would affect all
         instances of a window class), we just translate
         WM_LBUTTONDBLCLK to WM_LBUTTONDOWN here; this even works for
         built-in window class such as BUTTON */
      return on_message(_hWnd, WM_LBUTTONDOWN, wParam, lParam);

    if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }

    break;

#ifdef WM_MOUSEWHEEL
  case WM_MOUSEWHEEL:
    if (on_mouse_wheel(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
                       GET_WHEEL_DELTA_WPARAM(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;
#endif

  case WM_KEYDOWN:
    if (on_key_down(::TranscodeKey(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_KEYUP:
    if (on_key_up(::TranscodeKey(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_COMMAND:
    if (on_command(LOWORD(wParam), HIWORD(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_CANCELMODE:
    if (on_cancel_mode())
      return 0;
    break;

  case WM_SETFOCUS:
    on_setfocus();
    return 0;

  case WM_KILLFOCUS:
    on_killfocus();
    return 0;

  case WM_TIMER:
    if (on_timer(*(WindowTimer *)wParam))
      return 0;
    break;

  case WM_PAINT:
    if (custom_painting) {
      PaintCanvas canvas(*this);
      on_paint(canvas, canvas.get_dirty());
      return 0;
    }
    break;

  case WM_GETDLGCODE:
    if (on_key_check(wParam))
      return DLGC_WANTMESSAGE;
    break;
  }

  if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER))
    return 0;

  return on_unhandled_message(_hWnd, message, wParam, lParam);
}