Cleanups and refactoring.
authorDavin McCall <davmac@davmac.org>
Mon, 11 Jan 2016 20:00:40 +0000 (20:00 +0000)
committerDavin McCall <davmac@davmac.org>
Mon, 11 Jan 2016 20:00:40 +0000 (20:00 +0000)
src/service.cc
src/service.h

index 182467dc498eaffde9388c846307994221bb35b5..ecf9e091048dc3f57e28a6ddbc25f054b45511dc 100644 (file)
@@ -45,7 +45,7 @@ void ServiceSet::startService(const char *name)
     using namespace std;
     ServiceRecord *record = loadServiceRecord(name);
     
-    record->start(false);
+    record->start();
 }
 
 void ServiceSet::stopService(const std::string & name) noexcept
@@ -242,6 +242,10 @@ void ServiceRecord::require() noexcept
             ServiceRecord * to = i->getTo();
             to->require();
         }
+        
+        if (service_state != ServiceState::STOPPED) {
+            service_set->service_active(this);
+        }
     }
 }
 
@@ -273,16 +277,9 @@ void ServiceRecord::release_dependencies() noexcept
     service_set->service_inactive(this);
 }
 
-void ServiceRecord::start(bool transitive) noexcept
+void ServiceRecord::start(bool activate) noexcept
 {
-    if ((service_state == ServiceState::STARTING || service_state == ServiceState::STARTED)
-            && desired_state == ServiceState::STOPPED) {
-        // This service was starting, or started, but was set to be stopped.
-        // Cancel the stop (and continue starting/running).
-        notifyListeners(ServiceEvent::STOPCANCELLED);
-    }
-
-    if (!transitive) {
+    if (activate) {
         if (!start_explicit) require();
         start_explicit = true;
     }
@@ -290,7 +287,6 @@ void ServiceRecord::start(bool transitive) noexcept
     if (desired_state == ServiceState::STARTED && service_state != ServiceState::STOPPED) return;
 
     desired_state = ServiceState::STARTED;
-    service_set->service_active(this);
     do_start();
 }
 
@@ -342,7 +338,7 @@ bool ServiceRecord::startCheckDependencies(bool start_deps) noexcept
         if ((*i)->service_state != ServiceState::STARTED) {
             if (start_deps) {
                 all_deps_started = false;
-                (*i)->start(true);
+                (*i)->start(false);
             }
             else {
                 return false;
@@ -354,7 +350,7 @@ bool ServiceRecord::startCheckDependencies(bool start_deps) noexcept
         ServiceRecord * to = i->getTo();
         if (start_deps) {
             if (to->service_state != ServiceState::STARTED) {
-                to->start(true);
+                to->start(false);
                 i->waiting_on = true;
                 all_deps_started = false;
             }
@@ -780,12 +776,12 @@ bool ServiceRecord::stopDependents() noexcept
     for (sr_iter i = dependents.begin(); i != dependents.end(); ++i) {
         if (! (*i)->is_stopped()) {
             all_deps_stopped = false;
-            if (force_stop) {
-                (*i)->forceStop();
-            }
-            else {
-                (*i)->do_stop();
-            }
+        }
+        if (force_stop) {
+            (*i)->forceStop();
+        }
+        else {
+            (*i)->do_stop();
         }
     }
     
@@ -829,7 +825,7 @@ void ServiceRecord::allDepsStopped()
 
 void ServiceRecord::pinStart() noexcept
 {
-    start(false);
+    start(true);
     pinned_started = true;
 }
 
index 7c39395f6d26655197981d0bd451c434dbe26a1c..f8bbdebf42f6bd10ad2d72a53bf4733b93aacd1f 100644 (file)
@@ -429,7 +429,7 @@ class ServiceRecord
     const char *getServiceName() const noexcept { return service_name.c_str(); }
     ServiceState getState() const noexcept { return service_state; }
     
-    void start(bool transitive = false) noexcept;  // start the service
+    void start(bool activate = true) noexcept;  // start the service
     void stop() noexcept;   // stop the service
     
     void forceStop() noexcept; // force-stop this service and all dependents