Add a command to test notify
authorKyle Fuller <redacted>
Mon, 18 Mar 2013 21:35:44 +0000 (21:35 +0000)
committerKyle Fuller <redacted>
Mon, 18 Mar 2013 21:37:50 +0000 (21:37 +0000)
palaver.cpp

index c41747fa09ecaa59a5f4d91eddabdf158fb58133..55f35bbe1ee2e5302ce29e2a7452c3a52e0f63f9 100644 (file)
@@ -340,7 +340,11 @@ private:
 
 class CPalaverMod : public CModule {
 public:
-       MODCONSTRUCTOR(CPalaverMod) {}
+       MODCONSTRUCTOR(CPalaverMod) {
+               AddHelpCommand();
+               AddCommand("test", static_cast<CModCommand::ModCmdFunc>(&CPalaverMod::HandleTestCommand),
+                       "", "Send notifications to registered devices");
+       }
 
 #pragma mark - Cap
 
@@ -547,6 +551,29 @@ public:
                return CONTINUE;
        }
 
+#pragma mark - Commands
+
+       void HandleTestCommand(const CString& sLine) {
+               if (m_pNetwork) {
+                       unsigned int count = 0;
+
+                       for (std::vector<CDevice*>::const_iterator it = m_vDevices.begin();
+                                       it != m_vDevices.end(); ++it)
+                       {
+                               CDevice& device = **it;
+
+                               if (device.HasNetwork(*m_pNetwork)) {
+                                       count++;
+                                       device.SendNotification(*this, "palaver", "Test notification", NULL);
+                               }
+                       }
+
+                       PutModule("Notification sent to " + CString(count) + " clients.");
+               } else {
+                       PutModule("You need to connect with a network.");
+               }
+       }
+
 private:
 
        std::vector<CDevice*> m_vDevices;
git clone https://git.99rst.org/PROJECT