SinricPro Library
KeypadController.h
1 #pragma once
2 
3 #include "../SinricProRequest.h"
4 #include "../SinricProStrings.h"
5 
6 #include "../SinricProNamespace.h"
7 namespace SINRICPRO_NAMESPACE {
8 
9 FSTR(KEYPAD, sendKeystroke); // "sendKeystroke"
10 FSTR(KEYPAD, keystroke); // "keystroke"
11 
26 using KeystrokeCallback = std::function<bool(const String &, String &)>;
27 
28 
33 template <typename T>
35  public:
37 
38  void onKeystroke(KeystrokeCallback cb);
39 
40  protected:
41  bool handleKeypadController(SinricProRequest &request);
42 
43  private:
44  KeystrokeCallback keystrokeCallback;
45 };
46 
47 template <typename T>
49  T* device = static_cast<T*>(this);
50  device->registerRequestHandler(std::bind(&KeypadController<T>::handleKeypadController, this, std::placeholders::_1));
51 }
52 
60 template <typename T>
61 void KeypadController<T>::onKeystroke(KeystrokeCallback cb) { keystrokeCallback = cb; }
62 
63 
64 template <typename T>
65 bool KeypadController<T>::handleKeypadController(SinricProRequest &request) {
66  T* device = static_cast<T*>(this);
67 
68  bool success = false;
69  if (request.action != FSTR_KEYPAD_sendKeystroke) return false;
70 
71  if (keystrokeCallback) {
72  String keystroke = request.request_value[FSTR_KEYPAD_keystroke] | "";
73  success = keystrokeCallback(device->deviceId, keystroke);
74  request.response_value[FSTR_KEYPAD_keystroke] = keystroke;
75  return success;
76  }
77 
78  return success;
79 }
80 
81 } // SINRICPRO_NAMESPACE
82 
83 template <typename T>
84 using KeypadController = SINRICPRO_NAMESPACE::KeypadController<T>;
KeypadController.
Definition: KeypadController.h:34
std::function< bool(const String &, String &)> KeystrokeCallback
Callback definition for onKeystroke function.
Definition: KeypadController.h:26