Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: content/browser/gamepad/gamepad_platform_data_fetcher_linux.cc

Issue 165983005: Updating Gamepad API to match latest spec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ifdef-gaurds Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/gamepad/gamepad_platform_data_fetcher_linux.h" 5 #include "content/browser/gamepad/gamepad_platform_data_fetcher_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <libudev.h> 8 #include <libudev.h>
9 #include <linux/joystick.h> 9 #include <linux/joystick.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // Replace the previous name string with one containing the better 175 // Replace the previous name string with one containing the better
176 // information, again driver returns utf-8 strings here so combine 176 // information, again driver returns utf-8 strings here so combine
177 // in utf-8 for conversion to WebUChar below. 177 // in utf-8 for conversion to WebUChar below.
178 name_string = base::StringPrintf("%s %s", manufacturer, product); 178 name_string = base::StringPrintf("%s %s", manufacturer, product);
179 } 179 }
180 } 180 }
181 181
182 // Append the vendor and product information then convert the utf-8 182 // Append the vendor and product information then convert the utf-8
183 // id string to WebUChar. 183 // id string to WebUChar.
184 #ifdef ENABLE_NEW_GAMEPAD_API
scottmg 2014/02/18 23:45:26 I'm not sure I like the #ifs. How are we going to
bajones 2014/02/18 23:54:04 Sorry, I should have clarified this. These #ifdefs
scottmg 2014/02/18 23:57:30 Gotcha, that sounds good. My concern then is that
185 std::string id = name_string + base::StringPrintf(
186 " (Vendor: %s Product: %s)",
187 vendor_id,
188 product_id);
189 base::TruncateUTF8ToByteSize(id, WebGamepad::idLengthCap - 1, &id);
190 base::string16 tmp16 = base::UTF8ToUTF16(id);
191 memset(pad.id, 0, sizeof(pad.id));
192 tmp16.copy(pad.id, arraysize(pad.id) - 1);
193
194 if (mapper) {
195 std::string mapping = "standard";
196 base::TruncateUTF8ToByteSize(mapping, WebGamepad::mappingLengthCap - 1,
197 &mapping);
198 tmp16 = base::UTF8ToUTF16(mapping);
199 memset(pad.mapping, 0, sizeof(pad.mapping));
200 tmp16.copy(pad.mapping, arraysize(pad.mapping) - 1);
201 } else {
202 pad.mapping[0] = 0;
203 }
204 #else
184 std::string id = name_string + base::StringPrintf( 205 std::string id = name_string + base::StringPrintf(
185 " (%sVendor: %s Product: %s)", 206 " (%sVendor: %s Product: %s)",
186 mapper ? "STANDARD GAMEPAD " : "", 207 mapper ? "STANDARD GAMEPAD " : "",
187 vendor_id, 208 vendor_id,
188 product_id); 209 product_id);
189 base::TruncateUTF8ToByteSize(id, WebGamepad::idLengthCap - 1, &id); 210 base::TruncateUTF8ToByteSize(id, WebGamepad::idLengthCap - 1, &id);
190 base::string16 tmp16 = base::UTF8ToUTF16(id); 211 base::string16 tmp16 = base::UTF8ToUTF16(id);
191 memset(pad.id, 0, sizeof(pad.id)); 212 memset(pad.id, 0, sizeof(pad.id));
192 tmp16.copy(pad.id, arraysize(pad.id) - 1); 213 tmp16.copy(pad.id, arraysize(pad.id) - 1);
214 #endif
193 215
194 pad.connected = true; 216 pad.connected = true;
195 } 217 }
196 } 218 }
197 219
198 void GamepadPlatformDataFetcherLinux::EnumerateDevices() { 220 void GamepadPlatformDataFetcherLinux::EnumerateDevices() {
199 udev_enumerate* enumerate = udev_enumerate_new(udev_->udev_handle()); 221 udev_enumerate* enumerate = udev_enumerate_new(udev_->udev_handle());
200 if (!enumerate) 222 if (!enumerate)
201 return; 223 return;
202 int ret = udev_enumerate_add_match_subsystem(enumerate, kInputSubsystem); 224 int ret = udev_enumerate_add_match_subsystem(enumerate, kInputSubsystem);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 continue; 270 continue;
249 pad.buttons[item] = event.value ? 1.0 : 0.0; 271 pad.buttons[item] = event.value ? 1.0 : 0.0;
250 if (item >= pad.buttonsLength) 272 if (item >= pad.buttonsLength)
251 pad.buttonsLength = item + 1; 273 pad.buttonsLength = item + 1;
252 } 274 }
253 pad.timestamp = event.time; 275 pad.timestamp = event.time;
254 } 276 }
255 } 277 }
256 278
257 } // namespace content 279 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm » ('j') | ppapi/shared_impl/ppb_gamepad_shared.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698