// 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
// 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:
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;
}
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;
}