Improve socket-activated service handling

This patch provides a more generic way of handling socket-activated
services like dropbear. A socket-activated service only has base socket
unit and spawns service unit with instance name on incoming connection,
so the instanced units of it need to be ignored. And whether a service
is socket-activated can be determined by checking the existance of its
service object path.

Tested:
* Two socket-activated service, dropbear and obmc-console-ssh, can be
  controlled as expected.
* Instances of socket-activated services are no loger added to monitor
  list.

Change-Id: If8faa2248e5794a410f804125410608aa69b858d
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/src/main.cpp b/src/main.cpp
index 3d67800..8e7a8a7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -23,6 +23,7 @@
 
 #include <filesystem>
 #include <fstream>
+#include <unordered_map>
 
 std::unique_ptr<boost::asio::steady_timer> timer = nullptr;
 std::unique_ptr<boost::asio::steady_timer> initTimer = nullptr;
@@ -35,9 +36,11 @@
 
 // Base service name list. All instance of these services and
 // units(service/socket) will be managed by this daemon.
-static std::array<std::string, 6> serviceNames = {
-    "phosphor-ipmi-net", "bmcweb",       "phosphor-ipmi-kcs",
-    "start-ipkvm",       "obmc-console", "dropbear"};
+static std::unordered_map<std::string /* unitName */,
+                          bool /* isSocketActivated */>
+    managedServices = {{"phosphor-ipmi-net", false}, {"bmcweb", false},
+                       {"phosphor-ipmi-kcs", false}, {"start-ipkvm", false},
+                       {"obmc-console", false},      {"dropbear", true}};
 
 enum class UnitType
 {
@@ -118,9 +121,14 @@
             std::get<static_cast<int>(ListUnitElements::name)>(unit);
         auto [unitName, type, instanceName] =
             getUnitNameTypeAndInstance(fullUnitName);
-        if (std::find(serviceNames.begin(), serviceNames.end(), unitName) !=
-            serviceNames.end())
+        if (managedServices.count(unitName))
         {
+            // For socket-activated units, ignore all its instances
+            if (managedServices.at(unitName) == true && !instanceName.empty())
+            {
+                continue;
+            }
+
             std::string instantiatedUnitName =
                 unitName + addInstanceName(instanceName, "_40");
             boost::replace_all(instantiatedUnitName, "-", "_2d");