diff --git a/src/psmoveclient/ClientPSMoveAPI.cpp b/src/psmoveclient/ClientPSMoveAPI.cpp index db3e2cfa..06f3b5ff 100644 --- a/src/psmoveclient/ClientPSMoveAPI.cpp +++ b/src/psmoveclient/ClientPSMoveAPI.cpp @@ -240,9 +240,9 @@ class ClientPSMoveAPIImpl : return request->request_id(); } - ClientPSMoveAPI::t_request_id set_controller_rumble(ClientControllerView * view, float rumble_amount) + void set_controller_rumble(ClientControllerView * view, float rumble_amount) { - CLIENT_LOG_INFO("set_controller_rumble") << "request set rumble to " << rumble_amount << " for ControllerID: " << view->GetControllerID() << std::endl; + CLIENT_LOG_DEBUG("set_controller_rumble") << "request set rumble to " << rumble_amount << " for ControllerID: " << view->GetControllerID() << std::endl; assert(m_controller_view_map.find(view->GetControllerID()) != m_controller_view_map.end()); @@ -253,16 +253,14 @@ class ClientPSMoveAPIImpl : request->mutable_request_rumble()->set_controller_id(view->GetControllerID()); request->mutable_request_rumble()->set_rumble(static_cast(rumble_amount * 255.f)); - m_request_manager.send_request(request); - - return request->request_id(); + m_request_manager.send_request_no_reply(request); } - ClientPSMoveAPI::t_request_id set_led_color( + void set_led_color( ClientControllerView *view, unsigned char r, unsigned char g, unsigned b) { - CLIENT_LOG_INFO("set_controller_rumble") << "request set color to " << r << "," << g << "," << b << + CLIENT_LOG_DEBUG("set_controller_rumble") << "request set color to " << (int)r << "," << (int)g << "," << (int)b << " for PSMoveID: " << view->GetControllerID() << std::endl; assert(m_controller_view_map.find(view->GetControllerID()) != m_controller_view_map.end()); @@ -275,9 +273,7 @@ class ClientPSMoveAPIImpl : request->mutable_set_led_color_request()->set_g(static_cast(g)); request->mutable_set_led_color_request()->set_b(static_cast(b)); - m_request_manager.send_request(request); - - return request->request_id(); + m_request_manager.send_request_no_reply(request); } ClientPSMoveAPI::t_request_id set_led_tracking_color( @@ -813,34 +809,26 @@ ClientPSMoveAPI::stop_controller_data_stream( return request_id; } -ClientPSMoveAPI::t_request_id +void ClientPSMoveAPI::set_controller_rumble( ClientControllerView * view, float rumble_amount) { - ClientPSMoveAPI::t_request_id request_id= ClientPSMoveAPI::INVALID_REQUEST_ID; - if (ClientPSMoveAPI::m_implementation_ptr != nullptr) { - request_id= ClientPSMoveAPI::m_implementation_ptr->set_controller_rumble(view, rumble_amount); + ClientPSMoveAPI::m_implementation_ptr->set_controller_rumble(view, rumble_amount); } - - return request_id; } -ClientPSMoveAPI::t_request_id +void ClientPSMoveAPI::set_led_color( ClientControllerView *view, unsigned char r, unsigned char g, unsigned b) { - ClientPSMoveAPI::t_request_id request_id= ClientPSMoveAPI::INVALID_REQUEST_ID; - if (ClientPSMoveAPI::m_implementation_ptr != nullptr) { - request_id= ClientPSMoveAPI::m_implementation_ptr->set_led_color(view, r, g, b); + ClientPSMoveAPI::m_implementation_ptr->set_led_color(view, r, g, b); } - - return request_id; } ClientPSMoveAPI::t_request_id diff --git a/src/psmoveclient/ClientPSMoveAPI.h b/src/psmoveclient/ClientPSMoveAPI.h index 8c9ff67f..4eb0600a 100644 --- a/src/psmoveclient/ClientPSMoveAPI.h +++ b/src/psmoveclient/ClientPSMoveAPI.h @@ -185,8 +185,8 @@ class CLIENTPSMOVEAPI ClientPSMoveAPI static t_request_id get_controller_list(); static t_request_id start_controller_data_stream(ClientControllerView *view, unsigned int data_stream_flags); static t_request_id stop_controller_data_stream(ClientControllerView *view); - static t_request_id set_controller_rumble(ClientControllerView *view, float rumble_amount); - static t_request_id set_led_color(ClientControllerView *view, unsigned char r, unsigned char g, unsigned b); + static void set_controller_rumble(ClientControllerView *view, float rumble_amount); + static void set_led_color(ClientControllerView *view, unsigned char r, unsigned char g, unsigned b); static t_request_id set_led_tracking_color(ClientControllerView *view, PSMoveTrackingColorType tracking_color); static t_request_id reset_pose(ClientControllerView *view); diff --git a/src/psmoveclient/ClientRequestManager.cpp b/src/psmoveclient/ClientRequestManager.cpp index 693c6c36..e235de46 100644 --- a/src/psmoveclient/ClientRequestManager.cpp +++ b/src/psmoveclient/ClientRequestManager.cpp @@ -58,6 +58,19 @@ class ClientRequestManagerImpl ClientNetworkManager::get_instance()->send_request(request); } + void send_request_no_reply(RequestPtr request) + { + RequestContext context; + + request->set_request_id(m_next_request_id); + ++m_next_request_id; + + context.request = request; + + // Send the request off to the network manager to get sent to the server + ClientNetworkManager::get_instance()->send_request(request); + } + void handle_request_canceled(RequestPtr request) { // Create a general canceled result @@ -349,6 +362,12 @@ void ClientRequestManager::send_request( m_implementation_ptr->send_request(request); } +void ClientRequestManager::send_request_no_reply( + RequestPtr request) +{ + m_implementation_ptr->send_request_no_reply(request); +} + void ClientRequestManager::handle_request_canceled(RequestPtr request) { m_implementation_ptr->handle_request_canceled(request); diff --git a/src/psmoveclient/ClientRequestManager.h b/src/psmoveclient/ClientRequestManager.h index 07944bcf..8fad2758 100644 --- a/src/psmoveclient/ClientRequestManager.h +++ b/src/psmoveclient/ClientRequestManager.h @@ -13,6 +13,7 @@ class ClientRequestManager : public IResponseListener virtual ~ClientRequestManager(); void send_request(RequestPtr request); + void send_request_no_reply(RequestPtr request); virtual void handle_request_canceled(RequestPtr request) override; virtual void handle_response(ResponsePtr response) override; diff --git a/src/psmoveconfigtool/AppStage_ColorCalibration.cpp b/src/psmoveconfigtool/AppStage_ColorCalibration.cpp index 2a044a93..0befc40f 100644 --- a/src/psmoveconfigtool/AppStage_ColorCalibration.cpp +++ b/src/psmoveconfigtool/AppStage_ColorCalibration.cpp @@ -666,7 +666,7 @@ void AppStage_ColorCalibration::request_set_controller_tracking_color( assert(0 && "unreachable"); } - ClientPSMoveAPI::eat_response(ClientPSMoveAPI::set_led_color(m_controllerView, r, g, b)); + ClientPSMoveAPI::set_led_color(m_controllerView, r, g, b); } void AppStage_ColorCalibration::request_tracker_start_stream() @@ -1011,7 +1011,7 @@ void AppStage_ColorCalibration::release_devices() if (m_controllerView != nullptr) { - ClientPSMoveAPI::eat_response(ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0)); + ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0); ClientPSMoveAPI::eat_response(ClientPSMoveAPI::stop_controller_data_stream(m_controllerView)); ClientPSMoveAPI::free_controller_view(m_controllerView); m_controllerView = nullptr; diff --git a/src/psmoveconfigtool/AppStage_MagnetometerCalibration.cpp b/src/psmoveconfigtool/AppStage_MagnetometerCalibration.cpp index 9bd93ee7..563ca060 100644 --- a/src/psmoveconfigtool/AppStage_MagnetometerCalibration.cpp +++ b/src/psmoveconfigtool/AppStage_MagnetometerCalibration.cpp @@ -243,9 +243,8 @@ void AppStage_MagnetometerCalibration::update() m_led_color_r = led_color_r; m_led_color_g = led_color_g; m_led_color_b = led_color_b; - ClientPSMoveAPI::eat_response( - ClientPSMoveAPI::set_led_color( - m_controllerView, m_led_color_r, m_led_color_g, m_led_color_b)); + ClientPSMoveAPI::set_led_color( + m_controllerView, m_led_color_r, m_led_color_g, m_led_color_b); } } } @@ -598,7 +597,7 @@ void AppStage_MagnetometerCalibration::renderUI() if ((m_samplePercentage > 60) && ImGui::Button("Force Accept")) { - ClientPSMoveAPI::eat_response(ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0)); + ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0); m_menuState = waitForGravityAlignment; } ImGui::SameLine(); @@ -607,7 +606,7 @@ void AppStage_MagnetometerCalibration::renderUI() { if (ImGui::Button("Ok")) { - ClientPSMoveAPI::eat_response(ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0)); + ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0); m_menuState = waitForGravityAlignment; } ImGui::SameLine(); @@ -802,7 +801,7 @@ void AppStage_MagnetometerCalibration::request_exit_to_app_stage(const char *app if (m_isControllerStreamActive) { m_pendingAppStage= app_stage_name; - ClientPSMoveAPI::eat_response(ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0)); + ClientPSMoveAPI::set_led_color(m_controllerView, 0, 0, 0); ClientPSMoveAPI::register_callback( ClientPSMoveAPI::stop_controller_data_stream(m_controllerView), diff --git a/src/psmoveservice/Device/Manager/ControllerManager.cpp b/src/psmoveservice/Device/Manager/ControllerManager.cpp index f87fe9ff..3f6b4913 100644 --- a/src/psmoveservice/Device/Manager/ControllerManager.cpp +++ b/src/psmoveservice/Device/Manager/ControllerManager.cpp @@ -95,17 +95,13 @@ ControllerManager::allocate_device_view(int device_id) return new ServerControllerView(device_id); } -bool +void ControllerManager::setControllerRumble(int controller_id, int rumble_amount) { - bool result = false; - if (ServerUtility::is_index_valid(controller_id, k_max_devices)) { - result = getControllerViewPtr(controller_id)->setControllerRumble(rumble_amount); + getControllerViewPtr(controller_id)->setControllerRumble(rumble_amount); } - - return result; } bool diff --git a/src/psmoveservice/Device/Manager/ControllerManager.h b/src/psmoveservice/Device/Manager/ControllerManager.h index e38ad4c7..35daec92 100644 --- a/src/psmoveservice/Device/Manager/ControllerManager.h +++ b/src/psmoveservice/Device/Manager/ControllerManager.h @@ -41,7 +41,7 @@ class ControllerManager : public DeviceTypeManager ServerControllerViewPtr getControllerViewPtr(int device_id); - bool setControllerRumble(int controller_id, int rumble_amount); + void setControllerRumble(int controller_id, int rumble_amount); bool resetPose(int controller_id); eCommonTrackingColorID allocateTrackingColorID(); diff --git a/src/psmoveservice/Server/ServerNetworkManager.cpp b/src/psmoveservice/Server/ServerNetworkManager.cpp index 960c6638..f9d280b6 100644 --- a/src/psmoveservice/Server/ServerNetworkManager.cpp +++ b/src/psmoveservice/Server/ServerNetworkManager.cpp @@ -176,7 +176,7 @@ class ClientConnection : public boost::enable_shared_from_this m_packed_response.set_msg(response); m_packed_response.pack(m_response_write_buffer); - SERVER_LOG_INFO("ClientConnection::start_tcp_write_queued_response") << "Sending TCP response"; + SERVER_LOG_DEBUG("ClientConnection::start_tcp_write_queued_response") << "Sending TCP response"; SERVER_LOG_DEBUG(" ") << show_hex(m_response_write_buffer); SERVER_LOG_DEBUG(" ") << m_packed_response.get_msg()->ByteSize() << " bytes"; @@ -396,7 +396,7 @@ class ClientConnection : public boost::enable_shared_from_this { if (!error) { - SERVER_LOG_INFO("ClientConnection::handle_tcp_read_request_body") + SERVER_LOG_DEBUG("ClientConnection::handle_tcp_read_request_body") << "Read request body on connection" << m_connection_id; SERVER_LOG_DEBUG(" ") << show_hex(m_request_read_buffer); @@ -425,9 +425,12 @@ class ClientConnection : public boost::enable_shared_from_this << "Handle request type " << request->request_id() << " on connection id to client " << m_connection_id; - ResponsePtr response = m_request_handler_ref.handle_request(m_connection_id, request); - - add_tcp_response_to_write_queue(response); + ResponsePtr response = m_request_handler_ref.handle_request(m_connection_id, request); + if (response) + { + add_tcp_response_to_write_queue(response); + } + start_tcp_write_queued_response(); } else diff --git a/src/psmoveservice/Server/ServerRequestHandler.cpp b/src/psmoveservice/Server/ServerRequestHandler.cpp index 2daf0d8c..bbcc1266 100644 --- a/src/psmoveservice/Server/ServerRequestHandler.cpp +++ b/src/psmoveservice/Server/ServerRequestHandler.cpp @@ -159,89 +159,111 @@ class ServerRequestHandlerImpl context.connection_state= FindOrCreateConnectionState(connection_id); // All responses track which request they came from - PSMoveProtocol::Response *response= new PSMoveProtocol::Response; - response->set_request_id(request->request_id()); + PSMoveProtocol::Response *response= nullptr; switch (request->type()) { // Controller Requests case PSMoveProtocol::Request_RequestType_GET_CONTROLLER_LIST: + response = new PSMoveProtocol::Response; handle_request__get_controller_list(context, response); break; case PSMoveProtocol::Request_RequestType_START_CONTROLLER_DATA_STREAM: + response = new PSMoveProtocol::Response; handle_request__start_controller_data_stream(context, response); break; case PSMoveProtocol::Request_RequestType_STOP_CONTROLLER_DATA_STREAM: + response = new PSMoveProtocol::Response; handle_request__stop_controller_data_stream(context, response); break; case PSMoveProtocol::Request_RequestType_SET_RUMBLE: - handle_request__set_rumble(context, response); + handle_request__set_rumble(context); break; case PSMoveProtocol::Request_RequestType_RESET_POSE: + response = new PSMoveProtocol::Response; handle_request__reset_pose(context, response); break; case PSMoveProtocol::Request_RequestType_UNPAIR_CONTROLLER: + response = new PSMoveProtocol::Response; handle_request__unpair_controller(context, response); break; case PSMoveProtocol::Request_RequestType_PAIR_CONTROLLER: + response = new PSMoveProtocol::Response; handle_request__pair_controller(context, response); break; case PSMoveProtocol::Request_RequestType_CANCEL_BLUETOOTH_REQUEST: + response = new PSMoveProtocol::Response; handle_request__cancel_bluetooth_request(context, response); break; case PSMoveProtocol::Request_RequestType_SET_LED_COLOR: - handle_request__set_led_color(context, response); + handle_request__set_led_color(context); break; case PSMoveProtocol::Request_RequestType_SET_LED_TRACKING_COLOR: + response = new PSMoveProtocol::Response; handle_request__set_led_tracking_color(context, response); break; case PSMoveProtocol::Request_RequestType_SET_MAGNETOMETER_CALIBRATION: + response = new PSMoveProtocol::Response; handle_request__set_magnetometer_calibration(context, response); break; // Tracker Requests case PSMoveProtocol::Request_RequestType_GET_TRACKER_LIST: + response = new PSMoveProtocol::Response; handle_request__get_tracker_list(context, response); break; case PSMoveProtocol::Request_RequestType_START_TRACKER_DATA_STREAM: + response = new PSMoveProtocol::Response; handle_request__start_tracker_data_stream(context, response); break; case PSMoveProtocol::Request_RequestType_STOP_TRACKER_DATA_STREAM: + response = new PSMoveProtocol::Response; handle_request__stop_tracker_data_stream(context, response); break; case PSMoveProtocol::Request_RequestType_GET_TRACKER_SETTINGS: + response = new PSMoveProtocol::Response; handle_request__get_tracker_settings(context, response); break; case PSMoveProtocol::Request_RequestType_SET_TRACKER_EXPOSURE: + response = new PSMoveProtocol::Response; handle_request__set_tracker_exposure(context, response); break; case PSMoveProtocol::Request_RequestType_SET_TRACKER_GAIN: + response = new PSMoveProtocol::Response; handle_request__set_tracker_gain(context, response); break; case PSMoveProtocol::Request_RequestType_SET_TRACKER_OPTION: + response = new PSMoveProtocol::Response; handle_request__set_tracker_option(context, response); break; case PSMoveProtocol::Request_RequestType_SET_TRACKER_COLOR_PRESET: + response = new PSMoveProtocol::Response; handle_request__set_tracker_color_preset(context, response); break; case PSMoveProtocol::Request_RequestType_SET_TRACKER_POSE: + response = new PSMoveProtocol::Response; handle_request__set_tracker_pose(context, response); break; case PSMoveProtocol::Request_RequestType_SAVE_TRACKER_PROFILE: + response = new PSMoveProtocol::Response; handle_request__save_tracker_profile(context, response); break; case PSMoveProtocol::Request_RequestType_APPLY_TRACKER_PROFILE: + response = new PSMoveProtocol::Response; handle_request__apply_tracker_profile(context, response); break; case PSMoveProtocol::Request_RequestType_SEARCH_FOR_NEW_TRACKERS: + response = new PSMoveProtocol::Response; handle_request__search_for_new_trackers(context, response); break; // HMD Requests case PSMoveProtocol::Request_RequestType_GET_HMD_TRACKING_SPACE_SETTINGS: + response = new PSMoveProtocol::Response; handle_request__get_hmd_tracking_space_settings(context, response); break; case PSMoveProtocol::Request_RequestType_SET_HMD_TRACKING_SPACE_ORIGIN: + response = new PSMoveProtocol::Response; handle_request__set_hmd_tracking_space_origin(context, response); break; @@ -249,6 +271,11 @@ class ServerRequestHandlerImpl assert(0 && "Whoops, bad request!"); } + if (response != nullptr) + { + response->set_request_id(request->request_id()); + } + return ResponsePtr(response); } @@ -519,20 +546,12 @@ class ServerRequestHandlerImpl } void handle_request__set_rumble( - const RequestContext &context, - PSMoveProtocol::Response *response) + const RequestContext &context) { const int controller_id= context.request->request_rumble().controller_id(); const int rumble_amount= context.request->request_rumble().rumble(); - if (m_device_manager.m_controller_manager->setControllerRumble(controller_id, rumble_amount)) - { - response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK); - } - else - { - response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); - } + m_device_manager.m_controller_manager->setControllerRumble(controller_id, rumble_amount); } void handle_request__reset_pose( @@ -668,8 +687,7 @@ class ServerRequestHandlerImpl } void handle_request__set_led_color( - const RequestContext &context, - PSMoveProtocol::Response *response) + const RequestContext &context) { const int connection_id= context.connection_state->connection_id; const int controller_id= context.request->set_led_color_request().controller_id(); @@ -691,11 +709,6 @@ class ServerRequestHandlerImpl // of the controller is currently being tracked ControllerView->clearLEDOverride(); - response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK); - } - else - { - response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); } } // Otherwise we are setting the override to a new color @@ -704,14 +717,8 @@ class ServerRequestHandlerImpl // Sets the bulb LED color to some new override color // If tracking was active this likely will affect controller tracking ControllerView->setLEDOverride(r, g, b); - - response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK); } } - else - { - response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); - } } void handle_request__set_led_tracking_color(