-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PluginKit API for plugins to trigger hardware detection.
- Loading branch information
Showing
9 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
examples/plugin/org_osvr_example_TriggerHardwareDetect.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** @date 2016 | ||
@author | ||
Sensics, Inc. | ||
<http://sensics.com/osvr> | ||
*/ | ||
|
||
// Copyright 2016 Sensics Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Internal Includes | ||
#include <osvr/PluginKit/PluginKit.h> | ||
#include <osvr/PluginKit/ButtonInterfaceC.h> | ||
|
||
// Library/third-party includes | ||
|
||
// Standard includes | ||
#include <iostream> | ||
#include <chrono> | ||
#include <thread> | ||
#include <mutex> | ||
|
||
|
||
// Anonymous namespace to avoid symbol collision | ||
namespace { | ||
|
||
/** | ||
* @brief This fake device just triggers an autodetect every few seconds. | ||
*/ | ||
class FakeDevice { | ||
public: | ||
FakeDevice(OSVR_PluginRegContext ctx) : m_context(ctx) { | ||
/// Create the initialization options | ||
OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx); | ||
|
||
// configure our tracker | ||
osvrDeviceButtonConfigure(opts, &m_button, 1); | ||
|
||
/// Create the device token with the options | ||
m_dev.initAsync(ctx, "Hardware detection trigger", opts); | ||
|
||
/// Send JSON descriptor | ||
//m_dev.sendJsonDescriptor("{}"); | ||
|
||
/// Register update callback | ||
m_dev.registerUpdateCallback(this); | ||
} | ||
|
||
OSVR_ReturnCode update() { | ||
std::this_thread::sleep_for(std::chrono::seconds(3)); | ||
|
||
osvr::pluginkit::triggerHardwareDetect(m_context); | ||
|
||
return OSVR_RETURN_SUCCESS; | ||
} | ||
|
||
private: | ||
OSVR_PluginRegContext m_context; | ||
osvr::pluginkit::DeviceToken m_dev; | ||
OSVR_ButtonDeviceInterface m_button; | ||
}; | ||
|
||
class HardwareDetection { | ||
public: | ||
HardwareDetection() : m_found(false), m_count(0), m_mutex() {} | ||
|
||
OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx) { | ||
std::lock_guard<std::mutex> guard(m_mutex); | ||
|
||
m_count++; | ||
std::cout << "[org_osvr_example_TriggerHardwareDetect] Hardware detection triggered " << m_count << " times." << std::endl; | ||
|
||
if (m_found) | ||
return OSVR_RETURN_SUCCESS; | ||
|
||
osvr::pluginkit::registerObjectForDeletion(ctx, new FakeDevice(ctx)); | ||
m_found = true; | ||
|
||
return OSVR_RETURN_SUCCESS; | ||
} | ||
|
||
private: | ||
bool m_found; | ||
int m_count; | ||
std::mutex m_mutex; | ||
}; | ||
|
||
} // namespace | ||
|
||
OSVR_PLUGIN(org_osvr_example_TriggerHardwareDetect) { | ||
|
||
osvr::pluginkit::PluginContext context(ctx); | ||
|
||
/// Register a detection callback function object. | ||
context.registerHardwareDetectCallback(new HardwareDetection()); | ||
|
||
return OSVR_RETURN_SUCCESS; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters