Refactor/fix control commands, add a few start/stop alternatives
authorDavin McCall <davmac@davmac.org>
Mon, 11 Jan 2016 23:52:36 +0000 (23:52 +0000)
committerDavin McCall <davmac@davmac.org>
Mon, 11 Jan 2016 23:52:36 +0000 (23:52 +0000)
src/control-cmds.h
src/control.cc

index 263f61aaccdbf82f0555126455bb90faa45d2793..31c0b1c7ac7bdf462e89366979d3a90be7f8bd4c 100644 (file)
@@ -14,9 +14,11 @@ constexpr static int DINIT_CP_LOADSERVICE = 2;
 // Start or stop a service:
 constexpr static int DINIT_CP_STARTSERVICE = 3;
 constexpr static int DINIT_CP_STOPSERVICE  = 4;
+constexpr static int DINIT_CP_WAKESERVICE = 5;
+constexpr static int DINIT_CP_RELEASESERVICE = 6;
 
 // Shutdown:
-constexpr static int DINIT_CP_SHUTDOWN = 5;
+constexpr static int DINIT_CP_SHUTDOWN = 10;
  // followed by 1-byte shutdown type
 
 
@@ -50,6 +52,9 @@ constexpr static int DINIT_RP_SERVICERECORD = 59;
 // Couldn't find/load service
 constexpr static int DINIT_RP_NOSERVICE = 60;
 
+// Service is already started/stopped
+constexpr static int DINIT_RP_ALREADYSS = 61;
+
 
 
 // Information:
index 22f43785551bb2f81164053b11bef8601d4c8de0..88431fff935c5b092fbf27b6d7e67ad465dea11b 100644 (file)
@@ -22,7 +22,8 @@ void ControlConn::processPacket()
         processFindLoad(pktType);
         return;
     }
-    if (pktType == DINIT_CP_STARTSERVICE || pktType == DINIT_CP_STOPSERVICE) {
+    if (pktType == DINIT_CP_STARTSERVICE || pktType == DINIT_CP_STOPSERVICE
+            || pktType == DINIT_CP_WAKESERVICE || pktType == DINIT_CP_RELEASESERVICE) {
         processStartStop(pktType);
         return;
     }
@@ -154,24 +155,40 @@ void ControlConn::processStartStop(int pktType)
         return;
     }
     else {
-        if (pktType == DINIT_CP_STARTSERVICE) {
+        bool already_there = false;
+        switch (pktType) {
+        case DINIT_CP_STARTSERVICE:
             if (do_pin) {
                 service->pinStart();
             }
             else {
                 service->start();
             }
-        }
-        else {
+            already_there = service->getState() == ServiceState::STARTED;
+            break;
+        case DINIT_CP_STOPSERVICE:
             if (do_pin) {
                 service->pinStop();
             }
             else {
                 service->stop();
             }
+            already_there = service->getState() == ServiceState::STOPPED;
+            break;
+        case DINIT_CP_WAKESERVICE:
+            // re-start a stopped service.
+            // TODO pinning
+            service->start(false);
+            already_there = service->getState() == ServiceState::STARTED;
+            break;
+        default: /* DINIT_CP_RELEASESERVICE */
+            // remove explicit start from a service, without necessarily stopping it.
+            // TODO.
+            break;
         }
         
-        char ack_buf[] = { DINIT_RP_ACK };
+        char ack_buf[] = { (char)(already_there ? DINIT_RP_ALREADYSS : DINIT_RP_ACK) };
+        
         if (! queuePacket(ack_buf, 1)) return;
     }