--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+SET(CMAKE_SKIP_BUILD_RPATH true)
+
+PROJECT(capmgr)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR ${LIB_INSTALL_DIR})
+SET(INCLUDEDIR "\${prefix}/include")
+
+## Compiler flags
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden -g -Wall -fPIE")
+
+## Linker flags
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie -ldl")
+
+#INCLUDE_DIRECTORIES(include)
+INCLUDE(FindPkgConfig)
+
+ADD_DEFINITIONS("-DPROJECT_TAG=\"CAPMGR\"")
+
+SET(CAPMGR "capmgr")
+#SET(SRCS src/main.cc)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRC)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/utils SRC_UTILS)
+
+SET(SERVER_CHECK_MODULES dlog glib-2.0 pkgmgr pkgmgr-info)
+
+PKG_CHECK_MODULES(DEPS REQUIRED ${SERVER_CHECK_MODULES})
+
+FOREACH(FLAGS ${DEPS_CFLAGS})
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
+ENDFOREACH(FLAGS)
+
+ADD_EXECUTABLE(${CAPMGR} ${SRC} ${SRC_UTILS})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+TARGET_LINK_LIBRARIES(${CAPMGR} ${DEPS_LDFLAGS})
+
+INSTALL(TARGETS ${CAPMGR} DESTINATION bin)
--- /dev/null
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+Name: capmgr
+Summary: Capability Manager
+Version: 0.0.1
+Release: 1
+Group: Application Framework/Package Management
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1001: %{name}.manifest
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+#BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(pkgmgr)
+BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: boost-devel
+
+%description
+Tizen Capability Manager
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+%build
+%cmake .
+
+%__make %{?_smp_mflags}
+
+%install
+%make_install
+
+%post
+/sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%license LICENSE
+%defattr(-,root,root,-)
+%{_bindir}/*
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef APPCONTROL_MANAGER_H_
+#define APPCONTROL_MANAGER_H_
+
+#include <glib.h>
+
+namespace capmgr {
+
+class AppControlManager {
+ public:
+ AppControlManager();
+ ~AppControlManager();
+ private:
+};
+
+} // namespace capmgr
+
+#endif // APPCONTROL_MANAGER_H_
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef CAPABILITY_H_
+#define CAPABILITY_H_
+
+#include <string>
+#include <utility>
+
+namespace capmgr {
+
+class Capability {
+ public:
+ explicit Capability(const std::string& name, const std::string& pkgid,
+ const std::string& appid)
+ : name_(std::move(name)), pkgid_(std::move(pkgid)),
+ appid_(std::move(appid)) {}
+
+ const std::string& name() const { return name_; }
+ const std::string& pkgid() const { return pkgid_; }
+ const std::string& appid() const { return appid_; }
+
+ private:
+ std::string name_;
+ std::string pkgid_;
+ std::string appid_;
+};
+
+} // namespace capmgr
+
+#endif // CAPABILITY_H_
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "src/capability_manager.h"
+
+#include <glib.h>
+#include <pkgmgr-info.h>
+
+#include <iostream>
+
+#include "src/capability.h"
+#include "src/package_event_listener.h"
+#include "src/utils/logging.h"
+
+namespace {
+
+struct CallbackData {
+ const char* pkgid;
+ const char* appid;
+ std::vector<capmgr::Capability>* list;
+};
+
+int AppControlListCb(const char* operation, const char* uri, const char* mime,
+ void* user_data) {
+ struct CallbackData* cbdata =
+ static_cast<struct CallbackData*>(user_data);
+ // test code
+ std::string capname = std::string(operation) + "|" +
+ std::string(uri ? uri : "empty_uri") + "|" +
+ std::string(mime ? mime : "empty_mime");
+
+ cbdata->list->emplace_back(capname,
+ cbdata->pkgid,
+ cbdata->appid);
+ return 0;
+}
+
+int AppListCb(const pkgmgrinfo_appinfo_h handle, void* user_data) {
+ char* appid;
+ int ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (ret != PMINFO_R_OK)
+ return 0;
+
+ struct CallbackData* cbdata = static_cast<struct CallbackData*>(user_data);
+ cbdata->appid = appid;
+
+ // load local caps
+ ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, AppControlListCb,
+ user_data);
+ if (ret)
+ return 1;
+ return 0;
+}
+
+int PkgListCb(const pkgmgrinfo_pkginfo_h handle, void* user_data) {
+ char* pkgid;
+ int ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+ if (ret != PMINFO_R_OK)
+ return 0;
+
+ struct CallbackData* cbdata = static_cast<struct CallbackData*>(user_data);
+ cbdata->pkgid = pkgid;
+
+ ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, AppListCb,
+ user_data);
+ if (ret != PMINFO_R_OK)
+ return 0;
+
+ return 0;
+}
+
+} // namespace
+
+namespace capmgr {
+
+CapabilityManager::CapabilityManager() {}
+CapabilityManager::~CapabilityManager() {}
+
+const std::vector<Capability>& CapabilityManager::GetCapabilities() const {
+ return list_;
+}
+
+bool CapabilityManager::AddCapability(const Capability& capability) {
+ list_.push_back(std::move(capability));
+ return true;
+}
+
+// debug
+bool CapabilityManager::ListCapabilities() {
+ for (const auto& cap : list_) {
+ LOG(DEBUG) << "1: " << cap.name() << ", 2: " << cap.pkgid()
+ << ", 3: " << cap.appid();
+ }
+ return true;
+}
+
+bool CapabilityManager::LoadCapabilities() {
+ struct CallbackData cbdata;
+ cbdata.list = &list_;
+ int ret = pkgmgrinfo_pkginfo_get_list(PkgListCb, static_cast<void*>(&cbdata));
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ PackageEventListener::RegisterEventHandler(std::bind(
+ &capmgr::CapabilityManager::HandlePackageEvent, this,
+ std::placeholders::_1, std::placeholders::_2));
+
+ return true;
+}
+
+void CapabilityManager::HandlePackageEvent(const std::string& pkgid,
+ PackageEventListener::EventType event_type) {
+ LOG(DEBUG) << "Event received: " << pkgid << " "
+ << static_cast<int>(event_type);
+
+ // update caps
+ switch (event_type) {
+ case PackageEventListener::EventType::INSTALL:
+ AddCapabilitiesByPkgId(pkgid);
+ break;
+ case PackageEventListener::EventType::UPDATE:
+ RemoveCapabilitiesByPkgId(pkgid);
+ AddCapabilitiesByPkgId(pkgid);
+ break;
+ case PackageEventListener::EventType::UNINSTALL:
+ RemoveCapabilitiesByPkgId(pkgid);
+ break;
+ default:
+ LOG(ERROR) << "Unknown package event";
+ break;
+ }
+
+ ListCapabilities();
+}
+
+void CapabilityManager::AddCapabilitiesByPkgId(const std::string& pkgid) {
+ pkgmgrinfo_appinfo_filter_h filter;
+ int ret = pkgmgrinfo_appinfo_filter_create(&filter);
+ if (ret != PMINFO_R_OK) {
+ LOG(ERROR) << "Out of memory";
+ return;
+ }
+
+ ret = pkgmgrinfo_appinfo_filter_add_string(filter,
+ PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid.c_str());
+ if (ret != PMINFO_R_OK) {
+ LOG(ERROR) << "Failed to set filter value";
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ return;
+ }
+
+ struct CallbackData cbdata;
+ cbdata.pkgid = pkgid.c_str();
+ cbdata.list = &list_;
+
+ // uid?
+ ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, AppListCb,
+ static_cast<void*>(&cbdata));
+ if (ret != PMINFO_R_OK) {
+ LOG(ERROR) << "Failed to get appinfo of " << pkgid;
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+ return;
+ }
+
+ pkgmgrinfo_appinfo_filter_destroy(filter);
+}
+
+void CapabilityManager::RemoveCapabilitiesByPkgId(const std::string& pkgid) {
+ list_.erase(
+ std::remove_if(list_.begin(), list_.end(),
+ [pkgid](Capability& cap) {
+ return cap.pkgid() == pkgid;
+ }),
+ list_.end());
+}
+
+} // namespace capmgr
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef CAPABILITY_MANAGER_H_
+#define CAPABILITY_MANAGER_H_
+
+#include <glib.h>
+
+#include <string>
+#include <vector>
+
+#include "src/capability.h"
+#include "src/package_event_listener.h"
+
+namespace capmgr {
+
+class CapabilityManager {
+ public:
+ CapabilityManager();
+ ~CapabilityManager();
+ const std::vector<Capability>& GetCapabilities() const;
+ bool AddCapability(const Capability& capability);
+ bool ListCapabilities();
+ bool LoadCapabilities();
+
+ private:
+ void HandlePackageEvent(const std::string& pkgid,
+ PackageEventListener::EventType event_type);
+ void AddCapabilitiesByPkgId(const std::string& pkgid);
+ void RemoveCapabilitiesByPkgId(const std::string& pkgid);
+ std::vector<Capability> list_;
+};
+
+} // namespace capmgr
+
+#endif // CAPABILITY_MANAGER_H_
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <glib.h>
+
+#include "src/capability_manager.h"
+#include "src/package_event_listener.h"
+
+int main(int argc, char* argv[]) {
+ GMainLoop* mainloop = g_main_loop_new(NULL, FALSE);
+ if (!mainloop)
+ return 1;
+ capmgr::CapabilityManager manager;
+
+ manager.LoadCapabilities();
+// manager.ListCapabilities();
+
+ capmgr::PackageEventListener pkgmgr;
+ pkgmgr.SubscribePackageEvent();
+
+ g_main_loop_run(mainloop);
+ g_main_loop_unref(mainloop);
+
+ return 0;
+}
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "src/package_event_listener.h"
+
+#include <boost/signals2.hpp>
+
+#include <package-manager.h>
+
+#include <cstring>
+#include <functional>
+#include <map>
+#include <iostream>
+
+#include "src/utils/logging.h"
+
+namespace {
+
+const std::map<std::string, capmgr::PackageEventListener::EventType>
+ kEventStrMap = {
+ {"install", capmgr::PackageEventListener::EventType::INSTALL},
+ {"update", capmgr::PackageEventListener::EventType::UPDATE},
+ {"uninstall", capmgr::PackageEventListener::EventType::UNINSTALL},
+};
+
+} // namespace
+
+namespace capmgr {
+
+PackageEventListener::PackageEventListener() {
+ pc_ = pkgmgr_client_new(PC_LISTENING);
+}
+
+PackageEventListener::~PackageEventListener() {
+ int ret = pkgmgr_client_free(pc_);
+ if (ret != PKGMGR_R_OK)
+ LOG(ERROR) << "Failed to free pc";
+ else
+ LOG(ERROR) << "pc freed";
+}
+
+void PackageEventListener::SubscribePackageEvent() {
+ int ret = pkgmgr_client_listen_status(pc_,
+ &PackageEventListener::PkgMgrEventCb, this);
+ if (ret < 0)
+ LOG(ERROR) << "Failed to subscribe pkgmgr event";
+}
+
+void PackageEventListener::UnsubscribePackageEvent() {
+}
+
+void PackageEventListener::RegisterEventHandler(
+ std::function<void(const std::string&, EventType)> handler) {
+ EventSignal().on_event.connect(handler);
+}
+
+int PackageEventListener::PkgMgrEventCb(uid_t target_uid, int req_id,
+ const char* pkg_type, const char* pkgid, const char* key, const char* val,
+ const void* pmsg, void* data) {
+ LOG(DEBUG) << "pkgid: " << pkgid << " key: " << key << " val: " << val;
+
+ PackageEventListener* p = static_cast<PackageEventListener*>(data);
+ if (std::strcmp(key, "start") == 0) {
+ auto event_type = kEventStrMap.find(val);
+ if (event_type == kEventStrMap.end())
+ return 0;
+ p->event_map_.emplace(pkgid, event_type->second);
+ }
+
+ if (std::strcmp(key, "end") == 0) {
+ auto event = p->event_map_.find(pkgid);
+ if (event == p->event_map_.end()) {
+ LOG(ERROR) << "Unknown event";
+ return 0;
+ }
+ if (std::strcmp(val, "ok") == 0) {
+ EventSignal().on_event(pkgid, event->second);
+ }
+ p->event_map_.erase(event);
+ }
+ return 0;
+}
+
+} // namespace capmgr
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef PACKAGE_EVENT_LISTENER_H_
+#define PACKAGE_EVENT_LISTENER_H_
+
+#include <boost/signals2.hpp>
+
+#include <package-manager.h>
+
+#include <functional>
+#include <map>
+#include <string>
+
+namespace capmgr {
+
+class PackageEventListener {
+ public:
+ enum class EventType {
+ INSTALL,
+ UPDATE,
+ UNINSTALL,
+ };
+
+ PackageEventListener();
+ ~PackageEventListener();
+
+ void SubscribePackageEvent();
+ void UnsubscribePackageEvent();
+
+ static void RegisterEventHandler(
+ std::function<void(const std::string&, EventType)> handler);
+
+ private:
+ class PackageEventSignal {
+ public:
+ boost::signals2::signal<void(const std::string& pkgid,
+ PackageEventListener::EventType)> on_event;
+ };
+
+ static PackageEventSignal& EventSignal() {
+ static PackageEventSignal s = PackageEventSignal();
+ return s;
+ }
+
+ static int PkgMgrEventCb(uid_t target_uid, int req_id, const char* pkg_type,
+ const char* pkgid, const char* key, const char* val, const void* pmsg,
+ void* data);
+
+ pkgmgr_client* pc_;
+ std::map<std::string, EventType> event_map_;
+};
+
+} // namespace capmgr
+
+#endif // PACKAGE_EVENT_LISTENER_H_
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTE_DEVICE_H_
+#define REMOTE_DEVICE_H_
+
+#include <string>
+#include <utility>
+
+namespace capmgr {
+
+class RemoteDevice {
+ public:
+ explicit RemoteDevice(const std::string& name, const std::string& profile_,
+ const std::string& address, const std::string& uuid_)
+ : name_(std::move(name)), profile_(std::move(profile)),
+ address_(std::move(address)), uuid_(std::move(uuid)) {}
+
+ private:
+ std::string name_;
+ std::string profile_;
+ std::string address_;
+ std::string uuid_;
+};
+
+} // namespace capmgr
+
+#endif // REMOTE_DEVICE_H_
--- /dev/null
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTE_DEVICE_MANAGER_H_
+#define REMOTE_DEVICE_MANAGER_H_
+
+#include <string>
+
+namespace capmgr {
+
+class RemoteDeviceManager {
+ public:
+ private:
+};
+
+} // namespace capmgr
+
+#endif // REMOTE_DEVICE_MANAGER_H_
--- /dev/null
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "src/utils/logging.h"
+
+namespace utils {
+
+log_priority LogLevelToPriority(LogLevel level) {
+ switch (level) {
+ case LogLevel::LOG_ERROR:
+ return log_priority::DLOG_ERROR;
+ case LogLevel::LOG_WARNING:
+ return log_priority::DLOG_WARN;
+ case LogLevel::LOG_INFO:
+ return log_priority::DLOG_INFO;
+ case LogLevel::LOG_DEBUG:
+ return log_priority::DLOG_DEBUG;
+ default:
+ return log_priority::DLOG_UNKNOWN;
+ }
+}
+
+} // namespace utils
--- /dev/null
+// Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef UTILS_LOGGING_H_
+#define UTILS_LOGGING_H_
+
+#include <dlog.h>
+
+#ifndef PROJECT_TAG
+#define PROJECT_TAG ""
+#endif
+
+#ifdef LOG
+#undef LOG
+#endif
+
+#include <cassert>
+#include <cstring>
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#ifndef __FILENAME__
+#define __FILENAME__ \
+ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+#endif
+
+namespace utils {
+
+enum class LogLevel {
+ LOG_ERROR,
+ LOG_WARNING,
+ LOG_INFO,
+ LOG_DEBUG,
+};
+
+log_priority LogLevelToPriority(LogLevel level);
+
+template<LogLevel> struct LogTag;
+template<> struct LogTag<LogLevel::LOG_ERROR> {
+ static constexpr const char* value = "\033[1;31m| ERROR |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_WARNING> {
+ static constexpr const char* value = "\033[1;33m| WARNING |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_INFO> {
+ static constexpr const char* value = "\033[1;32m| INFO |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_DEBUG> {
+ static constexpr const char* value = "\033[0m| DEBUG |\033[0m";
+};
+
+template <class charT, class traits = std::char_traits<charT>>
+class StringStream : private std::basic_ostringstream<charT, traits> {
+ public:
+ using std::basic_ostringstream<charT, traits>::str;
+
+ template <class T>
+ StringStream& operator<<(const T& value) {
+ static_cast<std::basic_ostringstream<charT, traits> &>(*this) << value;
+ return *this;
+ }
+};
+
+class LogCatcher {
+ public:
+ LogCatcher(LogLevel level, const char* tag)
+ : level_(level), tag_(tag) { }
+
+ void operator&(const StringStream<char>& str) const {
+ dlog_print(LogLevelToPriority(level_), tag_.c_str(),
+ Escape(str.str()).c_str());
+ }
+
+ private:
+ // Since LogCatcher passes input to dlog_print(), the input which contains
+ // format string(such as %d, %n) can cause unexpected result.
+ // This is simple function to escape '%'.
+ // NOTE: Is there any gorgeous way instead of this?
+ std::string Escape(const std::string& str) const {
+ std::string escaped = std::string(str);
+ size_t start_pos = 0;
+ std::string from = "%";
+ std::string to = "%%";
+ while ((start_pos = escaped.find(from, start_pos)) != std::string::npos) {
+ escaped.replace(start_pos, from.length(), to);
+ start_pos += to.length();
+ }
+ return escaped;
+ }
+ LogLevel level_;
+ std::string tag_;
+};
+
+} // namespace utils
+
+inline static const constexpr char* __tag_for_project() {
+ return PROJECT_TAG;
+}
+
+// Simple logging macro of following usage:
+// LOG(LEVEL) << object_1 << object_2 << object_n;
+// where:
+// LEVEL = ERROR | WARNING | INFO | DEBUG
+#define LOG(LEVEL) \
+ ::utils::LogCatcher( \
+ ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
+ & ::utils::StringStream<char>() \
+ << std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \
+ << " : " << std::setw(36) \
+ << (std::string(__FILENAME__) + ":" + std::to_string(__LINE__)).c_str() \
+ << std::setw(0) << " : " \
+
+#endif // UTILS_LOGGING_H_
--- /dev/null
+#!/bin/bash
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+if [ ! `which cpplint.py` ]; then
+ echo -e "\nPlease make sure cpplint.py is in your PATH. It is part of depot_tools inside Chromium repository."
+ exit 1
+fi
+
+OLDPWD=$PWD
+BASE=`dirname $0`
+cd $BASE/..
+
+# filters
+FILTERS="-readability/streams,-build/c++11"
+
+cpplint.py --root=src --filter="$FILTERS" $(find . \( -name '*.h' -o -name '*.cc' \) )
+RET=$?
+
+JS_RET_VAL=$?
+cd $OLDPWD
+
+if [ "x$RET" == "x0" ]; then
+ exit 0
+else
+ exit 1
+fi