From 804e38dacc643db2e78ba3121a5060fafcceee30 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 28 Dec 2015 16:33:09 +0000 Subject: [PATCH] Add a publicly-accessible method to load a service (and return a pointer to its service record). --- service.cc | 2 +- service.h | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/service.cc b/service.cc index 5f0b3b4..705bb44 100644 --- a/service.cc +++ b/service.cc @@ -28,7 +28,7 @@ static ServiceRecord * findService(const std::list & records, return (ServiceRecord *)0; } -ServiceRecord * ServiceSet::findService(std::string name) noexcept +ServiceRecord * ServiceSet::findService(const std::string &name) noexcept { return ::findService(records, name.c_str()); } diff --git a/service.h b/service.h index 202f01a..7c5f956 100644 --- a/service.h +++ b/service.h @@ -308,6 +308,11 @@ class ServiceRecord } // TODO write a destructor + + ServiceState getState() noexcept + { + return service_state; + } // Set logfile, should be done before service is started void setLogfile(string logfile) @@ -373,10 +378,7 @@ class ServiceSet ControlConn *rollback_handler; // recieves notification when all services stopped // Private methods - - // Locate an existing service record. - ServiceRecord *findService(std::string name) noexcept; - + // Load a service description, and dependencies, if there is no existing // record for the given name. // Throws: @@ -402,6 +404,22 @@ class ServiceSet // Throws std::bad_alloc if out of memory. void startService(const char *name); + // Locate an existing service record. + ServiceRecord *findService(const std::string &name) noexcept; + + // Find a loaded service record, or load it if it is not loaded. + // Throws: + // ServiceLoadException (or subclass) on problem with service description + // std::bad_alloc on out-of-memory condition + ServiceRecord *loadService(const std::string &name) + { + ServiceRecord *record = findService(name); + if (record == nullptr) { + loadServiceRecord(name.c_str()); + } + return record; + } + // Stop the service with the given name. The named service will begin // transition to the 'stopped' state. void stopService(const std::string &name) noexcept; -- 2.25.1