Hermes SDK Documentation
CareTaker.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 #include <cstddef>
5 #include <thread>
6 #include <mutex>
7 #include <atomic>
8 #include <memory>
9 #include <map>
10 #include <set>
11 #include <chrono>
12 #include <functional>
13 
14 #include "HermesCallbackTypes.hpp"
15 
16 #include "grpc++/grpc++.h"
17 #include "protodefinitions/Devices.pb.h"
18 #include "protodefinitions/Hermes.pb.h"
19 #include "protodefinitions/Pipeline.pb.h"
20 #include "protodefinitions/Landscape.pb.h"
21 #include "protodefinitions/Session.pb.h"
22 #include "protodefinitions/ParameterSet.pb.h"
23 #include "protodefinitions/Hermes.grpc.pb.h"
24 
25 namespace zmq
26 {
27  class context_t;
28  class socket_t;
29 };
30 
31 namespace HermesSDK
32 {
33  class CareTaker
34  {
35  std::atomic<bool> m_isRunning;
36 
37  void DeviceDataSubscriberThreadFunction();
38  void DeviceLandscapeSubscriberThreadFunction();
39  void HeartbeatThreadFunction();
40 
41  bool Login();
42  bool Logout();
43  uint32_t Heartbeat();
44 
45  bool initHapticsSocket();
46 
47  static std::vector<uint8_t> Decompress(const std::vector<uint8_t>& in);
48  static size_t LzfDecompress( const std::vector<uint8_t> &in, std::vector<uint8_t> &out );
49 
50  std::shared_ptr<grpc::Channel> m_Channel;
51  std::unique_ptr<Hermes::Protocol::Hermes::Stub> m_Stub;
52 
53  const std::string m_clientName;
54  const std::string m_clientDescription;
55 
56  Hermes::Protocol::Session m_Session;
57  Hermes::Protocol::Pipeline m_Pipeline;
58  Hermes::Protocol::ServiceRoute m_Coordinator;
59 
60  std::unique_ptr<std::thread> m_deviceDataThread;
61  std::unique_ptr<std::thread> m_deviceLandscapeThread;
62  std::unique_ptr<std::thread> m_heartbeatThread;
63 
64  deviceDataCallback &m_dataCallback;
65  deviceLandscapeCallback &m_landscapeCallback;
66  filterSetupCallback &m_filterPipelineCallback;
67  errorMessageCallback &m_errorCallback;
68 
69  public:
70 
71  CareTaker( const std::string &clientName,
72  const std::string &clientInfo,
73  filterSetupCallback &_onFilterSetup,
74  deviceDataCallback &_onDeviceData,
75  deviceLandscapeCallback &_onDeviceLandscape,
76  errorMessageCallback &onError);
77  ~CareTaker();
78 
79  void Connect(const Hermes::Protocol::ServiceRoute& _coordinatorRoute);
80  void Stop();
81 
82  bool Rumble(uint32_t deviceId, float unitStrength, uint16_t durationInMilliseconds );
83  bool SendHapticData(uint32_t _dongleId, Hermes::Protocol::HandType _handType, const std::array<float, 5>& _powers);
86  bool SetPipeline( Hermes::Protocol::Pipeline *pipeline );
87  bool IsRunning();
88  };
89 }
HermesSDK::filterSetupCallback
std::function< void(Hermes::Protocol::Pipeline &_pipeline)> filterSetupCallback
Typedef to support callback for filter pipeline data.
Definition: HermesCallbackTypes.hpp:61
HermesSDK::errorMessageCallback
std::function< void(const ErrorMessage &msg)> errorMessageCallback
Typedef to support callback for error messages.
Definition: HermesCallbackTypes.hpp:63
HermesSDK::CareTaker
Definition: CareTaker.hpp:34
HermesSDK::CareTaker::CareTaker
CareTaker(const std::string &clientName, const std::string &clientInfo, filterSetupCallback &_onFilterSetup, deviceDataCallback &_onDeviceData, deviceLandscapeCallback &_onDeviceLandscape, errorMessageCallback &onError)
Definition: CareTaker.cpp:51
HermesSDK::CareTaker::SendHapticData
bool SendHapticData(uint32_t _dongleId, Hermes::Protocol::HandType _handType, const std::array< float, 5 > &_powers)
Definition: CareTaker.cpp:234
Hermes::Protocol::FilterInventory
Definition: Pipeline.proto:17
HermesSDK::CareTaker::Stop
void Stop()
Definition: CareTaker.cpp:136
Hermes::Protocol::Session
Definition: Session.proto:48
HermesSDK::CareTaker::Rumble
bool Rumble(uint32_t deviceId, float unitStrength, uint16_t durationInMilliseconds)
Definition: CareTaker.cpp:166
HermesCallbackTypes.hpp
HermesSDK::CareTaker::GetFilterInventory
bool GetFilterInventory(Hermes::Protocol::FilterInventory &inventory) const
Definition: CareTaker.cpp:279
HermesSDK::CareTaker::IsRunning
bool IsRunning()
Definition: CareTaker.cpp:605
HermesSDK::CareTaker::SetPipeline
bool SetPipeline(Hermes::Protocol::Pipeline *pipeline)
Definition: CareTaker.cpp:317
HermesSDK::CareTaker::GetActivePipeline
Hermes::Protocol::Pipeline * GetActivePipeline()
Definition: CareTaker.cpp:298
HermesSDK::deviceDataCallback
std::function< void(const Hermes::Protocol::Devices &_devices)> deviceDataCallback
Typedef to support callback for device data
Definition: HermesCallbackTypes.hpp:57
Hermes::Protocol::ServiceRoute
Definition: Session.proto:10
Hermes::Protocol::Pipeline
Definition: Pipeline.proto:23
HermesSDK::CareTaker::Connect
void Connect(const Hermes::Protocol::ServiceRoute &_coordinatorRoute)
Definition: CareTaker.cpp:92
HermesSDK::deviceLandscapeCallback
std::function< void(const Hermes::Protocol::Hardware::DeviceLandscape &_landscape)> deviceLandscapeCallback
Typedef to support callback for landscape (connected devices) data.
Definition: HermesCallbackTypes.hpp:59