]> git.vomp.tv Git - vompclient.git/commitdiff
Fix hardware key type to u8 in input system
authorChris Tallon <chris@vomp.tv>
Mon, 15 Aug 2022 14:46:53 +0000 (14:46 +0000)
committerChris Tallon <chris@vomp.tv>
Mon, 15 Aug 2022 14:46:53 +0000 (14:46 +0000)
src/input.cc
src/input.h
src/inputcec.cc
src/inputcec.h
src/inputlinux.cc
src/inputlinux.h
src/inputlirc.cc
src/inputlirc.h
src/inputudp.cc
src/inputudp.h
src/threadp.h

index cc42c9ca208fd22e3a0d8824caa1f73f35d3ca9b..4f09e4ff08f1ada80607426b13acd4d594be2bf8 100644 (file)
@@ -35,7 +35,7 @@ void Input::ResetToDefault()
   InitHWCListwithDefaults();
 }
 
-u1 Input::TranslateHWC(HWC_TYPE code)
+u1 Input::TranslateHWC(u8 code)
 {
   u1 ret = TranslateHWCFixed(code);
 
@@ -48,7 +48,7 @@ u1 Input::TranslateHWC(HWC_TYPE code)
   return TranslateHWCList(code);
 }
 
-u1 Input::TranslateHWCList(HWC_TYPE code)
+u1 Input::TranslateHWCList(u8 code)
 {
   if (learnMode != NOLEARNMODE)
   {
@@ -67,12 +67,12 @@ u1 Input::TranslateHWCList(HWC_TYPE code)
   }
 }
 
-void Input::setHWCtoCommand(HWC_TYPE hcw, u1 command)
+void Input::setHWCtoCommand(u8 hcw, u1 command)
 {
   translist[hcw] = command;
 }
 
-void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used
+void Input::unsetHWC(u8 hcw) // FIXME never used
 {
   translist.erase(hcw);
 }
@@ -80,16 +80,16 @@ void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used
 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
 {
        u4 number=0;
-       if (sscanf(cfg,"%ld",&number) != 1) return;
+       if (sscanf(cfg,"%d",&number) != 1) return;
        LogNT::getInstance()->info(TAG, "Config Input/Remote keys num keys {}", number);
        char keybuf[1024];
        for (u4 i = 0; i < number; i++) {
-               sprintf(keybuf, "RemoteKey%lu", i);
+               sprintf(keybuf, "RemoteKey%u", i);
                const char *keytrans = vdr->configLoad(modName(), keybuf);
                if (keytrans) {
                        u4 ul1, ul2;
                        u4 uc;
-                       if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
+                       if (sscanf(keytrans, "%XI%XK%X", &ul1, &ul2, &uc) == 3) {
                                translist[((u8) ul1) | ((u8) ul2) << 32] = (u1) uc;
                        }
                        delete[] keytrans;
@@ -109,8 +109,7 @@ void Input::SaveKeysConfig()
   RemoteTranslationList::const_iterator it;
   for (it = translist.begin(); it != translist.end(); it++)
   {
-         sprintf(buffer,"%08lXI%08lXK%02X",
-                         (u4)it->first ,(u4) (it->first >> 32), it->second);
+         sprintf(buffer,"%08XI%08XK%02X", (u4)it->first, (u4)(it->first >> 32), it->second);
          sprintf(keybuf,"RemoteKey%d",number);
          VDR::getInstance()->configSave(modName(), keybuf, buffer);
          number++;
index a6e38eff055010b71f2cfe5703b7f202a1eba946..fcb0b682e39864a94aa51e7c3ea8c3909f31f0db 100644 (file)
 #include "defines.h"
 #include "abstractoption.h"
 
-#ifdef WIN32
-#define HWC_TYPE u8
-#else
-#define HWC_TYPE int
-#endif
-
-
 class VDR;
 
-typedef std::map<HWC_TYPE, u1> RemoteTranslationList;
+typedef std::map<u8, u1> RemoteTranslationList;
 
 class Input: public AbstractOption
 {
@@ -51,8 +44,8 @@ class Input: public AbstractOption
 
     static void sendInputKey(int key);
 
-    void setHWCtoCommand(HWC_TYPE hcw, u1 command);
-    void unsetHWC(HWC_TYPE hcw);
+    void setHWCtoCommand(u8 hcw, u1 command);
+    void unsetHWC(u8 hcw);
     void LoadKeysConfig(VDR* vdr, const char* keynum);
     void SaveKeysConfig();
 
@@ -71,7 +64,7 @@ class Input: public AbstractOption
     void EnterLearnMode(u1 /* command */ ) {}; // Override and set lernMode to command
     void cancelLearnMode() { learnMode = NOLEARNMODE; }
     void ResetToDefault();
-    virtual std::string getHardwareKeyName(HWC_TYPE hardwareKey) = 0;
+    virtual std::string getHardwareKeyName(u8 hardwareKey) = 0;
 
 
     const static u4 NOLEARNMODE = 256;
@@ -145,9 +138,9 @@ class Input: public AbstractOption
     RemoteTranslationList translist;
     int learnMode{NOLEARNMODE};
 
-    virtual u1 TranslateHWCFixed(HWC_TYPE code) = 0;
-    u1 TranslateHWCList(HWC_TYPE code);
-    u1 TranslateHWC(HWC_TYPE code);
+    virtual u1 TranslateHWCFixed(u8 code) = 0;
+    u1 TranslateHWCList(u8 code);
+    u1 TranslateHWC(u8 code);
 };
 
 #endif
index c2bfcaffcffb11c7b2a1ad5467425c7961de6733..00cf2dd77bfca28a6e46b7afe8ea5233fa23477b 100644 (file)
@@ -332,7 +332,7 @@ void InputCEC::InitHWCListwithDefaults()
   translist[CEC_USER_CONTROL_CODE_CHANNEL_DOWN] = CHANNELDOWN;
 }
 
-u1 InputCEC::TranslateHWCFixed(int code)
+u1 InputCEC::TranslateHWCFixed(u8 code)
 {
   switch (code)
   {
@@ -453,12 +453,12 @@ const char* InputCEC::getHardCodedHardwareKeyNamesForVompKey(u1 /* vompKey */)
   return ""; // FIXME
 }
 
-std::string InputCEC::getHardwareKeyName(int hardwareKey)
+std::string InputCEC::getHardwareKeyName(u8 hardwareKey)
 {
-  const char* desc = cec_keymap[hardwareKey];
-
   std::string retval;
+  if (hardwareKey > CEC_USER_CONTROL_CODE_MAX) return retval;
 
+  const char* desc = cec_keymap[hardwareKey];
   if (desc)
   {
     retval = desc;
@@ -466,7 +466,7 @@ std::string InputCEC::getHardwareKeyName(int hardwareKey)
   else
   {
     char* rt = new char[10];
-    sprintf(rt, "0x%x", hardwareKey);
+    sprintf(rt, "0x%llx", hardwareKey);
     retval = rt;
   }
 
index fbf750dafab45b24717adf3d32a5fe38aee60558..434049c6c590f9acb87358042fee40bcd2e4d9c9 100644 (file)
@@ -41,7 +41,7 @@ class InputCEC : public Input
     bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane);
     bool handleOptionChanges(Option* option);
 
-    std::string getHardwareKeyName(int hardwareKey);
+    std::string getHardwareKeyName(u8 hardwareKey);
     const char* getHardCodedHardwareKeyNamesForVompKey(u1 vompKey);
 
   private:
@@ -49,7 +49,7 @@ class InputCEC : public Input
     const char* modName() { return myModName; }
     void InitKeymap();
     void InitHWCListwithDefaults();
-    u1 TranslateHWCFixed(int code);
+    u1 TranslateHWCFixed(u8 code);
 
     bool cechandlesvolume{};
 
index af130558a34ee9fae92c66e07a17703323f88bf4..48af605a8c4c2cf12075a80b1f2e381536e816c1 100644 (file)
@@ -106,7 +106,7 @@ void InputLinux::shutdown()
   initted = 0;
 }
 
-u1 InputLinux::TranslateHWCFixed(int code)
+u1 InputLinux::TranslateHWCFixed(u8 code)
 {
   // Translate /dev/input codes to VOMP codes for the hard coded buttons
   switch (code)
@@ -490,12 +490,12 @@ const char* InputLinux::getHardCodedHardwareKeyNamesForVompKey(u1 vompKey)
   }
 }
 
-std::string InputLinux::getHardwareKeyName(int hardwareKey)
+std::string InputLinux::getHardwareKeyName(u8 hardwareKey)
 {
-  const char* desc = linux_keymap[hardwareKey];
-
   std::string retval;
+  if (hardwareKey > KEY_MAX) return retval;
 
+  const char* desc = linux_keymap[hardwareKey];
   if (desc)
   {
     retval = desc;
@@ -503,7 +503,7 @@ std::string InputLinux::getHardwareKeyName(int hardwareKey)
   else
   {
     char* rt = new char[10];
-    sprintf(rt, "0x%x", hardwareKey);
+    sprintf(rt, "0x%llx", hardwareKey);
     retval = rt;
   }
 
index e4a30b06f60c33a2aa497231f09fe4772fe25069..1b98a5cbd4e36fcc4efb6447ecf43822aaf0ea1c 100644 (file)
@@ -34,7 +34,7 @@ class InputLinux : public Input
     bool init();
     void shutdown();
 
-    std::string getHardwareKeyName(int hardwareKey);
+    std::string getHardwareKeyName(u8 hardwareKey);
     const char* getHardCodedHardwareKeyNamesForVompKey(u1 vompKey);
     void EnterLearningMode(u1 vompKey);
 
@@ -49,7 +49,7 @@ class InputLinux : public Input
 
     void InitKeymap();
     void InitHWCListwithDefaults();
-    u1 TranslateHWCFixed(int code);
+    u1 TranslateHWCFixed(u8 code);
 
     std::vector<int> devices;
 
index 4acad37707d9a191738c6ded31731ef0db9e0a17..70bd52688eaad64163afce6082af00763a93e0fe 100644 (file)
@@ -239,7 +239,7 @@ bool InputLIRC::parse(const std::string& input, std::string& remoteName, std::st
 //   return "";
 // }
 
-std::string InputLIRC::getHardwareKeyName(HWC_TYPE /* hardwareKey */)
+std::string InputLIRC::getHardwareKeyName(u8 /* hardwareKey */)
 {
   std::string retval;
   return retval;
index 679eccd7e637936d9e67fac8141801aacbf3e4eb..44a979375ca421d111270faa2d2b29b4e65c828d 100644 (file)
@@ -42,7 +42,7 @@ class InputLIRC : public Input
     void stop();
 
     void InitHWCListwithDefaults() {};
-    std::string getHardwareKeyName(HWC_TYPE hardwareKey);
+    std::string getHardwareKeyName(u8 hardwareKey);
 
   private:
     LogNT* log{};
@@ -56,7 +56,7 @@ class InputLIRC : public Input
     bool threadReqStop{};
 
     bool parse(const std::string& input, std::string& remoteName, std::string& remoteButton, int& repeatCount);
-    u1 TranslateHWCFixed(HWC_TYPE code) { return static_cast<u1>(code); };
+    u1 TranslateHWCFixed(u8 code) { return static_cast<u1>(code); };
 
     bool initted{};
     TCP tcp;
index dcde094d88e52af1abcf3280b4f01d7e1e9e4962..289c7a0546bb3338358ef1fa5607a672693ef821 100644 (file)
@@ -164,7 +164,7 @@ const char* InputUDP::getHardCodedHardwareKeyNamesForVompKey(u1 /* vompKey */)
   return "";
 }
 
-std::string InputUDP::getHardwareKeyName(HWC_TYPE /* hardwareKey */)
+std::string InputUDP::getHardwareKeyName(u8 /* hardwareKey */)
 {
   std::string retval;
   return retval;
index 911f3c7b41003ac00e6ff5b127a5ba6085853e0b..2d5682e25d277a149aed54a2ed68415802bf76d8 100644 (file)
@@ -45,9 +45,9 @@ class InputUDP : public Input
 
     // InputUDP doesn't do any translation stuff so just keep everything happy here
     void InitHWCListwithDefaults() {};
-    u1 TranslateHWCFixed(HWC_TYPE code) { return static_cast<u1>(code); };
+    u1 TranslateHWCFixed(u8 code) { return static_cast<u1>(code); };
     const char* getHardCodedHardwareKeyNamesForVompKey(u1 vompKey);
-    std::string getHardwareKeyName(HWC_TYPE hardwareKey);
+    std::string getHardwareKeyName(u8 hardwareKey);
 
   private:
     static const char* myModName;
index db68e5c549dabfd436e3eb8121000626e44b3f15..5519f4f3c8654a7b3f037b652935534881f58714 100644 (file)
@@ -61,7 +61,7 @@ class ThreadP : public Thread
 
 
     static pthread_t thisThreadID();    // Self identification - returns ID of calling thread
-    static void threadSuicide();        // Self termination
+    [[ noreturn ]] static void threadSuicide();        // Self termination
 };
 
 #endif