Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Converted rumble and set LED requests to no-reply requests to prevent…
Browse files Browse the repository at this point in the history
… murdering the response queue. Converted rumble and LED logging to debug.
  • Loading branch information
HipsterSloth committed Jun 9, 2016
1 parent 03f74bc commit 4dab49a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 71 deletions.
32 changes: 10 additions & 22 deletions src/psmoveclient/ClientPSMoveAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -253,16 +253,14 @@ class ClientPSMoveAPIImpl :
request->mutable_request_rumble()->set_controller_id(view->GetControllerID());
request->mutable_request_rumble()->set_rumble(static_cast<int>(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());
Expand All @@ -275,9 +273,7 @@ class ClientPSMoveAPIImpl :
request->mutable_set_led_color_request()->set_g(static_cast<int>(g));
request->mutable_set_led_color_request()->set_b(static_cast<int>(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(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/psmoveclient/ClientPSMoveAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 19 additions & 0 deletions src/psmoveclient/ClientRequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/psmoveclient/ClientRequestManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/psmoveconfigtool/AppStage_ColorCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions src/psmoveconfigtool/AppStage_MagnetometerCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 2 additions & 6 deletions src/psmoveservice/Device/Manager/ControllerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/psmoveservice/Device/Manager/ControllerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 8 additions & 5 deletions src/psmoveservice/Server/ServerNetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ClientConnection : public boost::enable_shared_from_this<ClientConnection>
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";

Expand Down Expand Up @@ -396,7 +396,7 @@ class ClientConnection : public boost::enable_shared_from_this<ClientConnection>
{
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);

Expand Down Expand Up @@ -425,9 +425,12 @@ class ClientConnection : public boost::enable_shared_from_this<ClientConnection>
<< "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
Expand Down
Loading

0 comments on commit 4dab49a

Please sign in to comment.