summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/gamepad_resource.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 19:54:30 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 19:54:30 +0000
commitf511881bed1a46d2110f36e6b60e28f2b306b935 (patch)
tree58d69490432a1176a56ee2c0bdd6dd8016162e46 /ppapi/proxy/gamepad_resource.cc
parent5d67452f563f0d6eddc932dd67f7e84579b77831 (diff)
downloadchromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.zip
chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.tar.gz
chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.tar.bz2
Add a skeleton gamepad resource.
This implements the skeleton of the gamepad resource for the IPC proxy. It is not actually hooked up. Hooking it up will require moving some gamepad lock code to a shared location. This also hooks up the browser message routing for implementing resource hosts in the browser process. BUG= Review URL: https://chromiumcodereview.appspot.com/10824272 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/gamepad_resource.cc')
-rw-r--r--ppapi/proxy/gamepad_resource.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/ppapi/proxy/gamepad_resource.cc b/ppapi/proxy/gamepad_resource.cc
new file mode 100644
index 0000000..21ee02d
--- /dev/null
+++ b/ppapi/proxy/gamepad_resource.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/gamepad_resource.h"
+
+#include <string.h>
+
+#include "ppapi/c/ppb_gamepad.h"
+#include "ppapi/proxy/dispatch_reply_message.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace ppapi {
+namespace proxy {
+
+GamepadResource::GamepadResource(Connection connection, PP_Instance instance)
+ : PluginResource(connection, instance),
+ buffer_(NULL) {
+ SendCreateToBrowser(PpapiHostMsg_Gamepad_Create());
+ CallBrowser(PpapiHostMsg_Gamepad_RequestMemory());
+}
+
+GamepadResource::~GamepadResource() {
+}
+
+void GamepadResource::Sample(PP_GamepadsSampleData* data) {
+ if (!buffer_) {
+ // Browser hasn't sent back our shared memory, give the plugin gamepad
+ // data corresponding to "not connected".
+ memset(data, 0, sizeof(PP_GamepadsSampleData));
+ } else {
+ memcpy(data, buffer_, sizeof(PP_GamepadsSampleData));
+ }
+}
+
+void GamepadResource::OnReplyReceived(const ResourceMessageReplyParams& params,
+ const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(GamepadResource, msg)
+ PPAPI_DISPATCH_RESOURCE_REPLY(PpapiPluginMsg_Gamepad_SendMemory,
+ OnPluginMsgSendMemory)
+ IPC_END_MESSAGE_MAP()
+}
+
+void GamepadResource::OnPluginMsgSendMemory(
+ const ResourceMessageReplyParams& params,
+ base::SharedMemoryHandle shared_memory_handle) {
+ /* TODO(brettw) implement this when we have shared gamepad code. It would be
+ something like this:
+ shared_memory_.reset(
+ new base::SharedMemory(shared_memory_handle, true));
+ CHECK(shared_memory_->Map(sizeof(GamepadHardwareBuffer)));
+ void *memory = shared_memory_->memory();
+ // Use the memory...
+ */
+}
+
+} // namespace proxy
+} // namespace ppapi