system adapter: add files

This patchs adds the system adapter files.
They are meant to make the bridge between the daemon and the app
concerning system related communications.
It also registers handles to daemon callbacks.

Tuleap: #1550
Change-Id: Ib07c391afb1ddb0ec1207cc36c4b2a05675fe41b
Reviewed-by: Silbino Gonçalves Matado <silbino.gmatado@savoirfairelinux.com>
diff --git a/Ring/Ring.xcodeproj/project.pbxproj b/Ring/Ring.xcodeproj/project.pbxproj
index 227070a..9c56ed5 100644
--- a/Ring/Ring.xcodeproj/project.pbxproj
+++ b/Ring/Ring.xcodeproj/project.pbxproj
@@ -108,6 +108,7 @@
 		5557FD4D1E81AFF50043E394 /* ConfigKeyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DD80CC1E1EB2E4009A3510 /* ConfigKeyModel.swift */; };
 		5557FD4E1E81B1F20043E394 /* AccountModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5516C29E1E71CEFF009D3D2D /* AccountModelHelper.swift */; };
 		5557FD4F1E81B2990043E394 /* AccountCredentialsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DD80C91E1EAF1A009A3510 /* AccountCredentialsModel.swift */; };
+		557086521E8ADB9D001A7CE4 /* SystemAdapter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 557086511E8ADB9D001A7CE4 /* SystemAdapter.mm */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -238,6 +239,8 @@
 		5516C29E1E71CEFF009D3D2D /* AccountModelHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AccountModelHelper.swift; path = Account/AccountModelHelper.swift; sourceTree = "<group>"; };
 		56AC64D41E7C7F4000EA1AA9 /* WelcomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeViewController.swift; sourceTree = "<group>"; };
 		5557FD491E81AE850043E394 /* AccountModelHelperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountModelHelperTests.swift; sourceTree = "<group>"; };
+		557086501E8ADB9D001A7CE4 /* SystemAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SystemAdapter.h; path = Bridging/SystemAdapter.h; sourceTree = "<group>"; };
+		557086511E8ADB9D001A7CE4 /* SystemAdapter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SystemAdapter.mm; path = Bridging/SystemAdapter.mm; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -403,6 +406,8 @@
 				04399AA91D1C304300E99CD9 /* Ring-Bridging-Header.h */,
 				04399AA51D1C304300E99CD9 /* AccountAdapter.h */,
 				04399AA61D1C304300E99CD9 /* AccountAdapter.mm */,
+				557086501E8ADB9D001A7CE4 /* SystemAdapter.h */,
+				557086511E8ADB9D001A7CE4 /* SystemAdapter.mm */,
 				04399AA71D1C304300E99CD9 /* DRingAdapter.h */,
 				04399AA81D1C304300E99CD9 /* DRingAdapter.mm */,
 				04399AAA1D1C304300E99CD9 /* Utils.h */,
@@ -739,6 +744,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				557086521E8ADB9D001A7CE4 /* SystemAdapter.mm in Sources */,
 				0273C3051E0C68B100CF00BA /* CreateProfileViewController.swift in Sources */,
 				02E1A0251DDE4ABA00D75B59 /* BoolStringExtension.swift in Sources */,
 				04399AAC1D1C304300E99CD9 /* AccountAdapter.mm in Sources */,
diff --git a/Ring/Ring/AppDelegate.swift b/Ring/Ring/AppDelegate.swift
index e99143b..709f31b 100644
--- a/Ring/Ring/AppDelegate.swift
+++ b/Ring/Ring/AppDelegate.swift
@@ -26,9 +26,10 @@
 class AppDelegate: UIResponder, UIApplicationDelegate {
 
     var window: UIWindow?
-    let daemonService = DaemonService.init(dRingAdaptor: DRingAdapter())
+    let daemonService = DaemonService(dRingAdaptor: DRingAdapter())
 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
+        SystemAdapter().registerConfigurationHandler()
         self.startDaemon()
         return true
     }
diff --git a/Ring/Ring/Bridging/Ring-Bridging-Header.h b/Ring/Ring/Bridging/Ring-Bridging-Header.h
index 834ccd1..4273a27 100644
--- a/Ring/Ring/Bridging/Ring-Bridging-Header.h
+++ b/Ring/Ring/Bridging/Ring-Bridging-Header.h
@@ -23,4 +23,5 @@
  Expose Objective-C bridging classes to Swift.
  */
 #import "AccountAdapter.h"
+#import "SystemAdapter.h"
 #import "DRingAdapter.h"
diff --git a/Ring/Ring/Bridging/SystemAdapter.h b/Ring/Ring/Bridging/SystemAdapter.h
new file mode 100644
index 0000000..11da312
--- /dev/null
+++ b/Ring/Ring/Bridging/SystemAdapter.h
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (C) 2017 Savoir-faire Linux Inc.
+ *
+ *  Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface SystemAdapter : NSObject
+
+- (void)registerConfigurationHandler;
+
+@end
diff --git a/Ring/Ring/Bridging/SystemAdapter.mm b/Ring/Ring/Bridging/SystemAdapter.mm
new file mode 100644
index 0000000..53942ab
--- /dev/null
+++ b/Ring/Ring/Bridging/SystemAdapter.mm
@@ -0,0 +1,51 @@
+/*
+ *  Copyright (C) 2017 Savoir-faire Linux Inc.
+ *
+ *  Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
+ */
+
+#import "Ring-Swift.h"
+
+#import "SystemAdapter.h"
+
+#import "dring/configurationmanager_interface.h"
+
+@implementation SystemAdapter
+
+using namespace DRing;
+
+#pragma mark Callbacks registration
+- (void)registerConfigurationHandler {
+    std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers;
+    confHandlers.insert(exportable_callback<ConfigurationSignal::GetAppDataPath>([&](const std::string& name,
+                                                                                     std::vector<std::string>* ret) {
+        if (name == "cache") {
+            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+            NSString *documentsDirectory = [paths objectAtIndex:0];
+            ret->push_back(std::string([documentsDirectory UTF8String]));
+        }
+        else {
+            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+            NSString *documentsDirectory = [paths objectAtIndex:0];
+            ret->push_back(std::string([documentsDirectory UTF8String]));
+        }
+    }));
+    registerConfHandlers(confHandlers);
+}
+#pragma mark -
+
+@end