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

Commit 88a6917

Browse files
committed
Linux - stubs for PlatformDeviceAPILinux
1 parent 90e1e2a commit 88a6917

File tree

4 files changed

+191
-1
lines changed

4 files changed

+191
-1
lines changed

src/psmoveservice/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
8686
ELSE()
8787
list(APPEND PSMOVESERVICE_PLATFORM_SRC
8888
${CMAKE_CURRENT_LIST_DIR}/Platform/BluetoothRequestsLinux.cpp
89-
${CMAKE_CURRENT_LIST_DIR}/Platform/BluetoothQueriesLinux.cpp)
89+
${CMAKE_CURRENT_LIST_DIR}/Platform/BluetoothQueriesLinux.cpp
90+
${CMAKE_CURRENT_LIST_DIR}/Platform/PlatformDeviceAPILinux.h
91+
${CMAKE_CURRENT_LIST_DIR}/Platform/PlatformDeviceAPILinux.cpp)
9092
ENDIF()
9193
source_group("Platform" FILES ${PSMOVESERVICE_PLATFORM_SRC})
9294

src/psmoveservice/Platform/BluetoothRequestsLinux.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,46 @@ AsyncBluetoothPairDeviceRequest::start()
323323
bool success= true;
324324
const int controller_id= m_controllerView->getDeviceID();
325325

326+
// Reset the pairing device state
327+
BluetoothPairDeviceState *state= reinterpret_cast<BluetoothPairDeviceState *>(m_internal_state);
328+
state->initialize(controller_id);
329+
state->bUsesAuthentication= m_controllerView->getUsesBluetoothAuthentication();
330+
state->controller_serial_string= m_controllerView->getSerial();
331+
state->controller_device_type= m_controllerView->getControllerDeviceType();
332+
333+
// Make sure the controller we're working with is a USB connection
334+
if (success && m_controllerView->getIsOpen() && m_controllerView->getIsBluetooth())
335+
{
336+
SERVER_LOG_ERROR("AsyncBluetoothPairDeviceRequest")
337+
<< "Controller " << controller_id
338+
<< " isn't an open USB device";
339+
success= false;
340+
}
341+
342+
// Find the bluetooth address of the host adapter
343+
if (success)
344+
{
345+
success= AsyncBluetoothPairDeviceRequest__findBluetoothRadio(state);
346+
}
347+
348+
// Assign this host address on the controller.
349+
// NOTE: This needs to be done on the main thread since the controller view isn't thread safe.
350+
if (success)
351+
{
352+
success= AsyncBluetoothPairDeviceRequest__registerHostAddress(m_controllerView, state);
353+
}
354+
355+
// Kick off the worker thread to do the rest of the work
356+
if (success)
357+
{
358+
359+
}
360+
361+
if (success)
362+
{
363+
m_status = AsyncBluetoothRequest::running;
364+
}
365+
326366
if (!success)
327367
{
328368
m_status = AsyncBluetoothRequest::failed;
@@ -357,4 +397,40 @@ AsyncBluetoothPairDeviceRequest::getDescription()
357397
description << "[Pair] ID: " << m_controllerView->getDeviceID() << " Conn: " << m_connectionId;
358398

359399
return description.str();
400+
}
401+
402+
//-- AsyncBluetoothPairDeviceRequest State Machine -----
403+
static bool
404+
AsyncBluetoothPairDeviceRequest__findBluetoothRadio(BluetoothPairDeviceState *state)
405+
{
406+
assert(state->isMainThread());
407+
bool bSuccess= true;
408+
409+
return bSuccess;
410+
}
411+
412+
static bool
413+
AsyncBluetoothPairDeviceRequest__registerHostAddress(
414+
ServerControllerViewPtr &controllerView,
415+
BluetoothPairDeviceState *state)
416+
{
417+
assert(state->isMainThread());
418+
const int controller_id= controllerView->getDeviceID();
419+
bool bSuccess= true;
420+
421+
if (controllerView->setHostBluetoothAddress(state->host_address_string))
422+
{
423+
SERVER_LOG_INFO("AsyncBluetoothPairDeviceRequest")
424+
<< "Assigned host address " << state->host_address_string
425+
<< " to controller id " << controller_id;
426+
}
427+
else
428+
{
429+
SERVER_LOG_ERROR("AsyncBluetoothPairDeviceRequest")
430+
<< "Failed to set host address " << state->host_address_string
431+
<< " on controller id " << controller_id;
432+
bSuccess= false;
433+
}
434+
435+
return bSuccess;
360436
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// -- include -----
2+
#include "PlatformDeviceAPILinux.h"
3+
#include "ServerLog.h"
4+
5+
#include <assert.h>
6+
7+
#include <string>
8+
#include <vector>
9+
#include <iostream>
10+
#include <iomanip>
11+
12+
//-- constants -----
13+
const char *k_reg_property_driver_desc = "DriverDesc";
14+
const char *k_reg_property_driver_version = "DriverVersion";
15+
const char *k_reg_property_matching_device_id = "MatchingDeviceId";
16+
const char *k_reg_property_provider_name = "ProviderName";
17+
const char *k_reg_property_vendor = "Vendor";
18+
19+
20+
// -- globals ----
21+
IDeviceHotplugListener *g_hotplug_broadcaster = nullptr;
22+
23+
//-- private definitions -----
24+
25+
26+
// -- definitions -----
27+
PlatformDeviceAPILinux::PlatformDeviceAPILinux()
28+
{
29+
30+
}
31+
32+
PlatformDeviceAPILinux::~PlatformDeviceAPILinux()
33+
{
34+
35+
}
36+
37+
// System
38+
bool PlatformDeviceAPILinux::startup(IDeviceHotplugListener *broadcaster)
39+
{
40+
bool bSuccess = true;
41+
42+
return bSuccess;
43+
}
44+
45+
void PlatformDeviceAPILinux::poll()
46+
{
47+
48+
}
49+
50+
void PlatformDeviceAPILinux::shutdown()
51+
{
52+
53+
}
54+
55+
// Events
56+
void PlatformDeviceAPILinux::handle_bluetooth_request_started()
57+
{
58+
59+
}
60+
61+
void PlatformDeviceAPILinux::handle_bluetooth_request_finished()
62+
{
63+
64+
}
65+
66+
// Queries
67+
bool PlatformDeviceAPILinux::get_device_property(
68+
const DeviceClass deviceClass,
69+
const int vendor_id,
70+
const int product_id,
71+
const char *property_name,
72+
char *buffer,
73+
const int buffer_size)
74+
{
75+
bool success = false;
76+
77+
78+
return success;
79+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef PLATFORM_DEVICE_API_LINUX_H
2+
#define PLATFORM_DEVICE_API_LINUX_H
3+
4+
// -- include -----
5+
#include "DevicePlatformInterface.h"
6+
7+
// -- definitions -----
8+
class PlatformDeviceAPILinux : public IPlatformDeviceAPI
9+
{
10+
public:
11+
PlatformDeviceAPILinux();
12+
virtual ~PlatformDeviceAPILinux();
13+
14+
// System
15+
bool startup(IDeviceHotplugListener *broadcaster) override;
16+
void poll() override;
17+
void shutdown() override;
18+
19+
// Events
20+
void handle_bluetooth_request_started() override;
21+
void handle_bluetooth_request_finished() override;
22+
23+
// Queries
24+
bool get_device_property(
25+
const DeviceClass deviceClass,
26+
const int vendor_id,
27+
const int product_id,
28+
const char *property_name,
29+
char *buffer,
30+
const int buffer_size) override;
31+
};
32+
33+
#endif // PLATFORM_DEVICE_API_LINUX_H

0 commit comments

Comments
 (0)