Initial import to Git
[profile/ivi/common-api-dbus-runtime.git] / src / CommonAPI / DBus / DBusUtils.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef DBUSUTILS_H_
5 #define DBUSUTILS_H_
6
7 #include <algorithm>
8 #include <string>
9 #include <sstream>
10 #include <vector>
11
12 namespace CommonAPI {
13 namespace DBus {
14
15 inline std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems) {
16     std::istringstream ss(s);
17     std::string item;
18     while (std::getline(ss, item, delim)) {
19         elems.push_back(item);
20     }
21     return elems;
22 }
23
24 inline std::vector<std::string> split(const std::string& s, char delim) {
25     std::vector<std::string> elems;
26     return split(s, delim, elems);
27 }
28
29 inline void findFallbackInstanceIdMapping(const std::string& instanceId,
30                                           std::string& connectionName,
31                                           std::string& objectPath) {
32     connectionName = instanceId;
33     objectPath = '/' + instanceId;
34     std::replace(objectPath.begin(), objectPath.end(), '.', '/');
35 }
36
37 inline std::string findCommonAPIAddressForDBusAddress(const std::string& conName,
38                                                const std::string& objName,
39                                                const std::string& intName) {
40
41     return "local:" + intName + ":" + conName;
42 }
43
44 inline std::string findFallbackInstanceIdMapping(const std::string& connectionName, const std::string& objectPath) {
45     return connectionName;
46 }
47
48 template<typename _FutureWaitType>
49 inline bool checkReady(_FutureWaitType&);
50
51 template<>
52 inline bool checkReady<bool>(bool& returnedValue) {
53         return returnedValue;
54 }
55
56 template<>
57 inline bool checkReady<std::future_status>(std::future_status& returnedValue) {
58         return returnedValue == std::future_status::ready;
59 }
60
61 }
62 }
63
64 #endif /* DBUSUTILS_H_ */