From 5d2b9a1d40720c8cc3306e7dab4e850271a1f00e Mon Sep 17 00:00:00 2001
From: Stefan Saraev <stefan@saraev.ca>
Date: Fri, 8 Aug 2014 18:22:44 +0300
Subject: [PATCH] service addons: use a wrapper to setup systemd

---
 xbmc/addons/Service.cpp | 12 ++++++++++++
 xbmc/addons/Service.h   |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/xbmc/addons/Service.cpp b/xbmc/addons/Service.cpp
index c406b11..c23b18a 100644
--- a/xbmc/addons/Service.cpp
+++ b/xbmc/addons/Service.cpp
@@ -53,6 +53,9 @@ AddonPtr CService::Clone() const
 bool CService::Start()
 {
   bool ret = true;
+
+  CallOEWrapper(ID(), false);
+
   switch (m_type)
   {
 #ifdef HAS_PYTHON
@@ -88,6 +91,8 @@ bool CService::Stop()
     break;
   }
 
+  CallOEWrapper(ID(), true);
+
   return ret;
 }
 
@@ -113,6 +118,13 @@ void CService::BuildServiceType()
   }
 }
 
+void CService::CallOEWrapper(const std::string& ID, bool disable)
+{
+  char cmd[255];
+  snprintf(cmd, sizeof(cmd), "/usr/lib/openelec/systemd-addon-wrapper %s %d", ID.c_str(), disable);
+  system(cmd);
+}
+
 void CService::OnDisabled()
 {
   Stop();
diff --git a/xbmc/addons/Service.h b/xbmc/addons/Service.h
index 98ec8b6..36e4109 100644
--- a/xbmc/addons/Service.h
+++ b/xbmc/addons/Service.h
@@ -47,6 +47,9 @@ namespace ADDON
     bool Stop();
     TYPE GetServiceType() { return m_type; }
     START_OPTION GetStartOption() { return m_startOption; }
+
+    void CallOEWrapper(const std::string& ID, bool disable);
+
     virtual void OnDisabled();
     virtual void OnEnabled();
     virtual bool OnPreInstall();
-- 
1.9.1

