Move krate service and library from device-policy-manager git 51/82351/5
authorSungbae Yoo <sungbae.yoo@samsung.com>
Wed, 3 Aug 2016 06:10:27 +0000 (15:10 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 4 Aug 2016 09:42:00 +0000 (18:42 +0900)
Change-Id: I41078b9ba27da5947fa2d4b30b7edf94c540bf69
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
66 files changed:
CMakeLists.txt
krate.manifest
lib/CMakeLists.txt [new file with mode: 0755]
lib/app-proxy.cpp [new file with mode: 0644]
lib/client.cpp [new file with mode: 0644]
lib/client.h [new file with mode: 0644]
lib/context.h [new file with mode: 0644]
lib/krate.pc.in [new file with mode: 0644]
lib/krate/app-info-internal.h [new file with mode: 0644]
lib/krate/app-proxy.cpp [new file with mode: 0644]
lib/krate/app-proxy.h [new file with mode: 0644]
lib/krate/debug.h [new file with mode: 0644]
lib/krate/krate.cpp [new file with mode: 0644]
lib/krate/krate.h [new file with mode: 0644]
lib/krate/package-info-internal.h [new file with mode: 0644]
lib/krate/package-proxy.cpp [new file with mode: 0644]
lib/krate/package-proxy.h [new file with mode: 0644]
lib/manager.cpp [new file with mode: 0644]
lib/package-proxy.cpp [new file with mode: 0644]
module/CMakeLists.txt
module/krate.cpp
packaging/krate.spec
rmi/app-proxy.h [new file with mode: 0644]
rmi/manager.h [new file with mode: 0644]
rmi/package-proxy.h [new file with mode: 0644]
server/CMakeLists.txt
server/app-bundle.cpp [new file with mode: 0644]
server/app-bundle.h [new file with mode: 0644]
server/app-proxy.cpp [new file with mode: 0644]
server/context.h [new file with mode: 0644]
server/launchpad.cpp [new file with mode: 0644]
server/launchpad.h [new file with mode: 0644]
server/main.cpp [new file with mode: 0644]
server/manager.cpp [new file with mode: 0644]
server/package-proxy.cpp [new file with mode: 0644]
server/packman.cpp [new file with mode: 0644]
server/packman.h [new file with mode: 0644]
server/server.cpp [new file with mode: 0644]
server/server.h [new file with mode: 0644]
server/systemd/krate.service.in
tools/CMakeLists.txt
tools/apps/kaskit/src/main.c
tools/apps/kaskit/src/widget.c
tools/apps/keyguard/CMakeLists.txt
tools/apps/keyguard/include/keyguard.h
tools/apps/keyguard/include/widget.h
tools/apps/keyguard/res/edje/keyguard.edc
tools/apps/keyguard/src/main.c
tools/apps/keyguard/src/ui.c
tools/apps/keyguard/src/widget.c
tools/apps/setup-wizard/CMakeLists.txt
tools/apps/setup-wizard/include/krate-setup.h
tools/apps/setup-wizard/include/setup-text.h
tools/apps/setup-wizard/include/widget.h
tools/apps/setup-wizard/res/edje/layout.edc
tools/apps/setup-wizard/res/edje/setup.edc
tools/apps/setup-wizard/res/edje/welcome.edc
tools/apps/setup-wizard/src/main.c
tools/apps/setup-wizard/src/security.c
tools/apps/setup-wizard/src/ui.c
tools/apps/setup-wizard/src/util.c
tools/apps/setup-wizard/src/widget.c
tools/cli/CMakeLists.txt
tools/cli/krate-admin-cli.cpp
tools/gumd-scripts/20_krate-add.post
tools/gumd-scripts/20_krate-remove.post

index f3f02d5..5fb2706 100755 (executable)
@@ -86,7 +86,7 @@ ENDIF(NOT DEFINED CONF_DIR)
 
 ADD_DEFINITIONS(-DUG_WAYLAND)
 
-#ADD_SUBDIRECTORY(${KRATE_LIB})
+ADD_SUBDIRECTORY(${KRATE_LIB})
 ADD_SUBDIRECTORY(${KRATE_SERVER})
 ADD_SUBDIRECTORY(${KRATE_MODULE})
 ADD_SUBDIRECTORY(${KRATE_VOLUME})
index a76fdba..1badf9e 100644 (file)
@@ -2,4 +2,7 @@
        <request>
                <domain name="_" />
        </request>
+       <assign>
+               <filesystem path="/opt/etc/krate" label="System::Shared" type="transmutable" />
+       </assign>
 </manifest>
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..f205925
--- /dev/null
@@ -0,0 +1,59 @@
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# 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.
+#
+SET(LIB_VERSION "${VERSION}")
+SET(LIB_SOVERSION "0")
+
+SET(PC_FILE "${PROJECT_NAME}.pc")
+
+SET(SOURCES client.cpp
+                       manager.cpp
+                       app-proxy.cpp
+                       package-proxy.cpp
+                       krate/krate.cpp
+                       krate/app-proxy.cpp
+                       krate/package-proxy.cpp
+)
+
+SET(CAPI_INCLUDE_FILES  krate/krate.h
+                                               krate/app-proxy.h
+                                               krate/package-proxy.h
+)
+
+
+SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
+
+PKG_CHECK_MODULES(LIBS_DEPS    REQUIRED
+                                                       klay
+                                                       glib-2.0
+                                                       capi-appfw-package-manager
+                                                       capi-appfw-app-manager
+                                                       capi-appfw-app-control
+                                                       libtzplatform-config
+)
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${LIB_SOVERSION})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION   ${LIB_VERSION})
+
+INCLUDE_DIRECTORIES(SYSTEM ${LIBS_DEPS_INCLUDE_DIRS} ${DPM_POLICY} ${KRATE_LIB} ${PROJECT_SOURCE_DIR})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS_DEPS_LIBRARIES} pthread)
+
+CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY)
+
+INSTALL(FILES ${CMAKE_BINARY_DIR}/${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CAPI_INCLUDE_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/krate)
diff --git a/lib/app-proxy.cpp b/lib/app-proxy.cpp
new file mode 100644 (file)
index 0000000..112e673
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include "rmi/app-proxy.h"
+
+namespace Krate {
+
+AppProxy::AppProxy(KrateControlContext& ctx)
+       : context(ctx)
+{
+}
+
+AppProxy::~AppProxy()
+{
+}
+
+AppProxy::AppInfo AppProxy::getAppInfo(const std::string& name, const std::string& appid)
+{
+       try {
+               return context->methodCall<AppProxy::AppInfo>("AppProxy::getAppInfo", name, appid);
+       } catch (runtime::Exception& e) {}
+       return AppProxy::AppInfo();
+}
+
+int AppProxy::createIterator(const std::string& krate)
+{
+       try {
+               return context->methodCall<int>("AppProxy::createIterator", krate);
+       } catch (runtime::Exception& e) {}
+       return -1;
+}
+
+AppProxy::AppInfo AppProxy::getIteratorValue(int iterator)
+{
+       try {
+               return context->methodCall<AppProxy::AppInfo>("AppProxy::getIteratorValue", iterator);
+       } catch (runtime::Exception& e) {}
+       return AppProxy::AppInfo();
+}
+
+bool AppProxy::nextIterator(int iterator)
+{
+       try {
+               return context->methodCall<bool>("AppProxy::nextIterator", iterator);
+       } catch (runtime::Exception& e) {}
+       return false;
+}
+
+int AppProxy::destroyIterator(int iterator)
+{
+       try {
+               return context->methodCall<int>("AppProxy::destroyIterator", iterator);
+       } catch (runtime::Exception& e) {}
+       return -1;
+}
+
+int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle)
+{
+       try {
+               return context->methodCall<int>("AppProxy::launch", name, bundle);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int AppProxy::resume(const std::string& name, const std::string& appid)
+{
+       try {
+               return context->methodCall<int>("AppProxy::resume", name, appid);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int AppProxy::terminate(const std::string& name, const std::string& appid)
+{
+       try {
+               return context->methodCall<int>("AppProxy::terminate", name, appid);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+bool AppProxy::isRunning(const std::string& name, const std::string& appid)
+{
+       try {
+               return context->methodCall<bool>("AppProxy::isRunning", name, appid);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+} // namespace Krate
diff --git a/lib/client.cpp b/lib/client.cpp
new file mode 100644 (file)
index 0000000..3e3bc58
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include "client.h"
+
+namespace {
+
+const std::string SUBSCRIBER_REGISTER = "Server::registerNotificationSubscriber";
+const std::string SUBSCRIBER_UNREGISTER = "Server::unregisterNotificationSubscriber";
+
+const std::string KRATE_MANAGER_ADDRESS = "/tmp/.krate.sock";
+
+} // namespace
+
+
+KrateContext::KrateContext() noexcept
+{
+}
+
+KrateContext::~KrateContext() noexcept
+{
+       disconnect();
+}
+
+int KrateContext::connect(const std::string& address) noexcept
+{
+       try {
+               client.reset(new rmi::Client(address));
+               client->connect();
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+
+       return 0;
+}
+
+int KrateContext::connect() noexcept
+{
+       return connect(KRATE_MANAGER_ADDRESS);
+}
+
+void KrateContext::disconnect() noexcept
+{
+       client.reset();
+}
+
+int KrateContext::subscribeSignal(const std::string& name,
+                                                                       const SignalListener& listener,
+                                                                       void* data)
+{
+       auto listenerDispatcher = [listener, data](std::string &name, std::string &from, std::string &object) {
+               listener(from.c_str(), object.c_str(), data);
+       };
+
+       try {
+               return client->subscribe<std::string, std::string, std::string>(SUBSCRIBER_REGISTER,
+                                                                                                                                               name, listenerDispatcher);
+       } catch (runtime::Exception& e) {
+               std::cout << e.what() << std::endl;
+               return -1;
+       }
+}
+
+int KrateContext::unsubscribeSignal(int subscriberId)
+{
+       return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId);
+}
diff --git a/lib/client.h b/lib/client.h
new file mode 100644 (file)
index 0000000..f8d1678
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __POLICY_CLIENT_H__
+#define __POLICY_CLIENT_H__
+
+#include <string>
+#include <memory>
+#include <functional>
+
+#include <klay/rmi/client.h>
+
+typedef std::function<void(const char*, const char*, void*)> KrateChangeListener;
+typedef std::function<void(const char*, const char*, void*)> SignalListener;
+
+class KrateContext {
+public:
+       typedef std::unique_ptr<rmi::Client> KrateControlContext;
+
+       KrateContext() noexcept;
+       ~KrateContext() noexcept;
+
+       int connect() noexcept;
+       int connect(const std::string& address) noexcept;
+       void disconnect() noexcept;
+
+       int subscribeSignal(const std::string& name, const SignalListener& listener, void* data);
+       int unsubscribeSignal(int subscriberId);
+
+       template<typename Krate, typename... Args>
+       Krate createKrateInterface(Args&&... args) noexcept
+       {
+               return Krate(getKrateControlContext(), std::forward<Args>(args)...);
+       }
+
+private:
+       KrateControlContext& getKrateControlContext()
+       {
+               return client;
+       }
+
+       KrateControlContext client;
+};
+
+KrateContext& GetKrateContext(void* handle);
+#endif //__POLICY_CLIENT_H__
diff --git a/lib/context.h b/lib/context.h
new file mode 100644 (file)
index 0000000..f1908d1
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __KRATE_CONTEXT__
+#define __KRATE_CONTEXT__
+
+#include "client.h"
+
+using KrateControlContext = ::KrateContext::KrateControlContext;
+
+#endif //!__KRATE_CONTEXT__
diff --git a/lib/krate.pc.in b/lib/krate.pc.in
new file mode 100644 (file)
index 0000000..175f23b
--- /dev/null
@@ -0,0 +1,12 @@
+# Package Information for pkg-config
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: @PROJECT_NAME@
+Description: Tizen @PROJECT_NAME@ Client library
+Version: @VERSION@
+Libs: -L${libdir} -l@PROJECT_NAME@
+Cflags: -I${includedir}/@PROJECT_NAME@
diff --git a/lib/krate/app-info-internal.h b/lib/krate/app-info-internal.h
new file mode 100644 (file)
index 0000000..96f1a7a
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __DPM_APP_INFO_INTERNAL_H__
+#define __DPM_APP_INFO_INTERNAL_H__
+
+#include <glib.h>
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct icon_x {
+               char *text;
+               char *lang;
+               char *section;
+               char *size;
+               char *resolution;
+               char *dpi;
+} icon_x;
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct label_x {
+               char *name;
+               char *text;
+               char *lang;
+} label_x;
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct application_x {
+       char *appid;    /*attr*/
+       char *exec;     /*attr*/
+       char *nodisplay;    /*attr, default: "false"*/
+       char *multiple; /*attr, default: "false"*/
+       char *taskmanage;       /*attr, default: "true"*/
+       char *enabled;  /*attr, default: "true"*/
+       char *type;     /*attr*/
+       char *categories;       /*attr*/
+       char *extraid;  /*attr*/
+       char *hwacceleration;   /*attr, default: "default"*/
+       char *screenreader;     /*attr, default: "use-system-setting"*/
+       char *mainapp;  /*attr, default: "false"*/
+       char *package;  /*set from package_x*/
+       char *recentimage;      /*attr, default: "false"*/
+       char *launchcondition;  /*attr, default: "false"*/
+       char *indicatordisplay; /*attr, default: "true"*/
+       char *portraitimg;      /*attr*/
+       char *landscapeimg;     /*attr*/
+       char *effectimage_type; /*attr, default: "image"*/
+       char *guestmode_visibility;     /*attr, default: "true"*/
+       char *component;    /*no xml part*/
+       char *permission_type;  /*attr, default: "normal"*/
+       char *component_type;   /*attr, default: "uiapp"*/
+       char *preload;  /*no xml part*/
+       char *submode;  /*attr, default: "false"*/
+       char *submode_mainid;   /*attr, default: "false"*/
+       char *process_pool;     /*attr, default: "false"*/
+       char *installed_storage;
+       char *autorestart;      /*attr, default: "false"*/
+       char *onboot;   /*attr, default: "false"*/
+       char *support_disable;  /*set from package_x*/
+       char *ui_gadget;    /*attr, default: "false"*/
+       char *launch_mode;      /*attr, default: "single"*/
+       char *ambient_support;  /*attr, default: "false"*/
+       char *alias_appid;      /*attr*/
+       char *effective_appid;  /*attr*/
+       char *package_type;     /*set from package_x*/
+       char *tep_name; /*set from package_x*/
+       char *zip_mount_file;   /*set from package_x*/
+       char *root_path;    /*set from package_x*/
+       char *api_version;      /*set from package_x*/
+       char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only, no xml part*/
+       char *is_disabled; /**< Flag that indicates if the application is disabled or not, no xml part*/
+       char *splash_screen_display; /*attr, default: "true"*/
+       GList *label;   /*element*/
+       GList *icon;    /*element*/
+       GList *image;   /*element*/
+       GList *category; /*element*/
+       GList *metadata;    /*element*/
+       GList *permission;      /*element*/
+       GList *launchconditions;    /*element*/
+       GList *notification;    /*element*/
+       GList *datashare;       /*element*/
+       GList *datacontrol; /*element*/
+       GList *background_category; /*element*/
+       GList *appcontrol; /*element*/
+       GList *splashscreens; /*element*/
+} application_x;
+
+// pkgmgr-info : include/pkgmgrinfo_private.h
+typedef struct _pkgmgr_appinfo_x {
+       const char *package;
+       char *locale;
+       int app_component;
+       application_x *app_info;
+} pkgmgr_appinfo_x;
+
+// app-manager : src/app_info.c
+typedef struct app_info_s {
+       char *app_id;
+       pkgmgr_appinfo_x *pkg_app_info;
+} app_info_s;
+
+
+#endif //__DPM_APP_INFO_INTERNAL_H__
diff --git a/lib/krate/app-proxy.cpp b/lib/krate/app-proxy.cpp
new file mode 100644 (file)
index 0000000..449520d
--- /dev/null
@@ -0,0 +1,258 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include <cstdlib>
+#include <cstring>
+
+#include "debug.h"
+#include "krate.h"
+#include "app-proxy.h"
+#include "app-info-internal.h"
+
+#include "client.h"
+#include "rmi/app-proxy.h"
+
+using namespace Krate;
+
+struct krate_app_proxy_s {
+       Krate::AppProxy proxy;
+       std::string krateName;
+};
+
+static inline krate_app_proxy_s* getInstance(krate_app_proxy_h handle)
+{
+       return reinterpret_cast<krate_app_proxy_s *>(handle);
+}
+
+static app_info_h make_app_info_handle(const Krate::AppProxy::AppInfo& info)
+{
+       if (info.id.empty()) {
+               return NULL;
+       }
+
+       application_x* app = (application_x*)::malloc(sizeof(application_x));
+       pkgmgr_appinfo_x* pkgappinfo = (pkgmgr_appinfo_x*)::malloc(sizeof(pkgmgr_appinfo_x));
+       app_info_s* appinfo = (app_info_s*)::malloc(sizeof(struct app_info_s));
+
+       ::memset(appinfo, 0, sizeof(app_info_s));
+       appinfo->app_id = ::strdup(info.id.c_str());
+       appinfo->pkg_app_info = pkgappinfo;
+
+       ::memset(pkgappinfo, 0, sizeof(pkgmgr_appinfo_x));
+       pkgappinfo->package = ::strdup(info.package.c_str());
+       pkgappinfo->locale = ::strdup(info.locale.c_str());
+       pkgappinfo->app_component = info.componentType;
+       pkgappinfo->app_info = app;
+
+       ::memset(app, 0, sizeof(application_x));
+       app->appid = ::strdup(info.id.c_str());
+       app->nodisplay = ::strdup(info.isNoDisplayed? "true":"false");
+       app->taskmanage = ::strdup(info.isTaskManaged? "true":"false");
+       app->type = ::strdup(info.type.c_str());
+
+       icon_x* icon = (icon_x*)::calloc(1, sizeof(icon_x));
+       icon->text = ::strdup(info.icon.c_str());
+       icon->lang = ::strdup(info.locale.c_str());
+       app->icon = ::g_list_append(NULL, icon);
+
+       label_x* label = (label_x*)::calloc(1, sizeof(label_x));
+       label->text = ::strdup(info.label.c_str());
+       label->lang = ::strdup(info.locale.c_str());
+       app->label = ::g_list_append(NULL, label);
+
+       return reinterpret_cast<app_info_h>(appinfo);
+}
+
+int krate_app_proxy_create(krate_manager_h manager, const char* name, krate_app_proxy_h *handle)
+{
+       RET_ON_FAILURE(manager, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       krate_app_proxy_s* instance = new krate_app_proxy_s {
+               GetKrateContext(manager).createKrateInterface<Krate::AppProxy>(),
+               name
+       };
+
+       *handle = reinterpret_cast<krate_app_proxy_h>(instance);
+       return KRATE_ERROR_NONE;
+}
+
+int krate_app_proxy_destroy(krate_app_proxy_h handle)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       delete reinterpret_cast<Krate::AppProxy*>(handle);
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_app_proxy_get_app_info(krate_app_proxy_h handle, const char* app_id, app_info_h* app_info)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(app_info, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       const auto info = proxy.getAppInfo(name, app_id);
+       app_info_h ret = make_app_info_handle(info);
+       if (ret == NULL) {
+               return KRATE_ERROR_INVALID_PARAMETER;
+       }
+
+       *app_info = ret;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_app_proxy_foreach_app_info(krate_app_proxy_h handle, app_manager_app_info_cb callback, void *user_data)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       int iter = proxy.createIterator(name);
+       do {
+               app_info_h info = make_app_info_handle(proxy.getIteratorValue(iter));
+               int ret = callback(info, user_data);
+               app_info_destroy(info);
+               if (!ret) {
+                       break;
+               }
+       } while (proxy.nextIterator(iter));
+       proxy.destroyIterator(iter);
+
+       return KRATE_ERROR_NONE;
+}
+
+static bool appExtraCallback(app_control_h app_control, const char *key, void *user_data)
+{
+       Krate::AppProxy::Bundle *bundle = reinterpret_cast<Krate::AppProxy::Bundle*>(user_data);
+       Krate::AppProxy::Bundle::Extra extra;
+       bool isArray;
+
+       extra.key = key;
+
+       app_control_is_extra_data_array(app_control, key, &isArray);
+       if (isArray) {
+               char **values;
+               int length = 0;
+               app_control_get_extra_data_array(app_control, key, &values, &length);
+               for (int i = 0; i < length; i++) {
+                       extra.value.push_back(values[i]);
+                       free(values[i]);
+               }
+               free(values);
+       } else {
+               char *value;
+               app_control_get_extra_data(app_control, key, &value);
+               extra.value.push_back(value);
+               free(value);
+       }
+       bundle->extraData.push_back(extra);
+
+       return true;
+}
+
+int krate_app_proxy_send_launch_request(krate_app_proxy_h handle, app_control_h app_control)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(app_control, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+       char *str;
+
+       Krate::AppProxy::Bundle bundle;
+       app_control_get_operation(app_control, &str);
+       if (str != NULL) {
+               bundle.operation = str;
+               free(str);
+               str = NULL;
+       }
+       app_control_get_uri(app_control, &str);
+       if (str != NULL) {
+               bundle.uri = str;
+               free(str);
+               str = NULL;
+       }
+       app_control_get_mime(app_control, &str);
+       if (str != NULL) {
+               bundle.mime = str;
+               free(str);
+               str = NULL;
+       }
+       app_control_get_category(app_control, &str);
+       if (str != NULL) {
+               bundle.category = str;
+               free(str);
+               str = NULL;
+       }
+       app_control_get_app_id(app_control, &str);
+       if (str != NULL) {
+               bundle.appId = str;
+               free(str);
+               str = NULL;
+       }
+       app_control_foreach_extra_data(app_control, appExtraCallback, &bundle);
+
+       return proxy.launch(name, bundle);
+}
+
+int krate_app_proxy_terminate(krate_app_proxy_h handle, const char* app_id)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       return proxy.terminate(name, app_id);
+}
+
+int krate_app_proxy_resume(krate_app_proxy_h handle, const char* app_id)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       return proxy.resume(name, app_id);
+}
+
+int krate_app_proxy_is_running(krate_app_proxy_h handle, const char* app_id, int *result)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(result, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       *result = proxy.isRunning(name, app_id);
+       return KRATE_ERROR_NONE;
+}
diff --git a/lib/krate/app-proxy.h b/lib/krate/app-proxy.h
new file mode 100644 (file)
index 0000000..02ec714
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __CAPI_KRATE_APP_PROXY_H__
+#define __CAPI_KRATE_APP_PROXY_H__
+
+#include <app_info.h>
+#include <app_control.h>
+#include <app_manager.h>
+
+#include <krate/krate.h>
+
+/**
+ * @file app-info.h
+ * @brief This file provides APIs to get the information of applications in the krate
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  CAPI_KRATE_APPLICATION_INFO_MODULE
+ * @{
+ */
+
+/**
+ * @brief       The krate application manager handle
+ * @since_tizen 3.0
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_destroy()
+ */
+typedef void* krate_app_proxy_h;
+
+/**
+ * @brief       Acquires the krate application manager handle
+ * @details     This API acquires krate application manager handle required to call
+ *              the krate application manager APIs.
+ * @since_tizen 3.0
+ * @param[in]   manager The krate manager handle
+ * @param[in]   name The krate name
+ * @param[out]  handle The krate app proxy handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_CONNECTION_REFUSED Connection refused
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @see         krate_manager_create()
+ * @see         krate_app_proxy_create()
+ * @see         get_last_result()
+ */
+KRATE_API int krate_app_proxy_create(krate_manager_h manager, const char* name, krate_app_proxy_h* handle);
+
+/**
+ * @brief       Releases the krate application manager handle
+ * @details     This API must be called if interaction with the krate application
+ *              manager handle is no longer required.
+ * @since_tizen 3.0
+ * @param[in]   context The device policy manager context
+ * @param[in]   handle The krate application manager handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_app_proxy_create()
+ * @see         krate_app_proxy_create()
+ */
+KRATE_API int krate_app_proxy_destroy(krate_app_proxy_h handle);
+
+/**
+ * @brief       Gets the application information for the given application in the krate.
+ * @details     This API gets application information handle required to get
+ *              information of the application in the krate
+ * @since_tizen 3.0
+ * @param[in]   handle The krate application manager handle
+ * @param[in]   appid The application ID
+ * @return      Krate application handle on success, otherwise NULL
+ * @remark      The specific error code can be obtained by using the
+ *              get_last_result() method. Error codes are described in
+ *              exception section.
+ * @exception   #KRATE_ERROR_NONE No error
+ * @exception   #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception   #KRATE_ERROR_TIMED_OUT Time out
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_create()
+ * @see         krate_application_release()
+ * @see         application_manager_get_application_info()
+ * @see         get_last_result()
+ */
+KRATE_API int krate_app_proxy_get_app_info(krate_app_proxy_h handle, const char* appid, app_info_h* app_info);
+
+/**
+ * @brief       Retrieves all the handles of the application in the krate.
+ * @details     This API calls app_manager_app_info_cb() once for each application
+ *              ID with traversing the installed application list in the krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate application manager handle
+ * @param[in]   callback The iteration callback function
+ * @param[in]   user_data The user data passed to the callback function
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         The handle must be created by krate_app_proxy_create().
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_create()
+ * @see         application_manager_foreach_app_info()
+ */
+KRATE_API int krate_app_proxy_foreach_app_info(krate_app_proxy_h handle, app_manager_app_info_cb callback, void *user_data);
+
+/**
+ * @brief       Launch the application located at the given path into the krate.
+ * @details     Administrator can use this API to launch the application in the
+ *              krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate application manager handle
+ * @param[in]   app_control The app_control handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_NO_SUCH_FILE No such application file
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API or the caller is not the owner
+ *              of the krate
+ * @pre         The handle must be created by krate_app_proxy_create().
+ * @pre         The krate corresponding to the given name must be
+ *              created before use of this API.
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_destroy()
+ * @see         krate_app_proxy_resume()
+ * @see         krate_app_proxy_terminate()
+ * @see         krate_is_running_app()
+ * @see         app_control_send_launch_request()
+ */
+KRATE_API int krate_app_proxy_send_launch_request(krate_app_proxy_h handle, app_control_h app_control);
+
+/**
+ * @brief       Terminate the application located at the given path into the krate.
+ * @details     Administrator can use this API to terminate the application in
+ *              the krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate application manager handle
+ * @param[in]   appid The application ID to be terminated
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_NO_SUCH_FILE No such application file
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API or the caller is not the owner
+ *              of the krate
+ * @pre         The handle must be created by krate_app_proxy_create().
+ * @pre         The krate corresponding to the given name must be
+ *              created before use of this API.
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_destroy()
+ * @see         krate_app_proxy_resume()
+ * @see         krate_app_proxy_send_launch_request()
+ * @see         krate_is_running_app()
+ * @see         app_control_send_terminate_request()
+ * @see         app_manager_send_terminate_bt_app()
+ */
+KRATE_API int krate_app_proxy_terminate(krate_app_proxy_h handle, const char* appid);
+
+/**
+ * @brief       Resume the application located at the given path into the krate.
+ * @details     Administrator can use this API to resume the application in the
+ *              krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate application manager handle
+ * @param[in]   appid The application ID to be resumed
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_NO_SUCH_FILE No such application file
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API or the caller is not the owner
+ *              of the krate
+ * @pre         The handle must be created by krate_app_proxy_create().
+ * @pre         The krate corresponding to the given name must be
+ *              created before use of this API.
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_destroy()
+ * @see         krate_app_proxy_send_launch_request()
+ * @see         krate_app_proxy_terminate()
+ * @see         app_manager_resume_app()
+ */
+KRATE_API int krate_app_proxy_resume(krate_app_proxy_h handle, const char* appid);
+
+/**
+ * @brief       Checks whether the application in the krate is running.
+ * @details     This API can be used to check whether the application in the krate
+ *              is running.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate application manager handle
+ * @param[in]   appid The application ID
+ * @param[out]  result true if the application is running,
+ *              otherwise false if the application is not running
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_NO_DATA No such pacakge to check
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_app_proxy_create().
+ * @see         krate_app_proxy_create()
+ * @see         krate_app_proxy_destroy()
+ * @see         krate_app_proxy_send_launch_request()
+ * @see         krate_app_proxy_terminate()
+ * @see         app_manager_is_running_app()
+ */
+KRATE_API int krate_app_proxy_is_running(krate_app_proxy_h handle, const char* appid, int* result);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CAPI_KRATE_APP_PROXY_H__  */
diff --git a/lib/krate/debug.h b/lib/krate/debug.h
new file mode 100644 (file)
index 0000000..719e478
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __CAPI_KRATE_ASSERT_H__
+#define __CAPI_KRATE_ASSERT_H__
+
+#define RET_ON_FAILURE(cond, ret) \
+{                                 \
+       if (!(cond))                  \
+               return (ret);             \
+}
+
+#endif //! __CAPI_KRATE_ASSERT_H__
diff --git a/lib/krate/krate.cpp b/lib/krate/krate.cpp
new file mode 100644 (file)
index 0000000..6f428f3
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include "debug.h"
+#include "krate.h"
+
+#include "client.h"
+#include "rmi/manager.h"
+
+
+using namespace Krate;
+
+KrateContext& GetKrateContext(void* handle)
+{
+       return *reinterpret_cast<KrateContext*>(handle);
+}
+
+int krate_manager_create(krate_manager_h* handle)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext* client = new(std::nothrow) KrateContext();
+
+       RET_ON_FAILURE(handle, KRATE_ERROR_CONNECTION_REFUSED);
+
+       if (client->connect() < 0) {
+               delete client;
+               RET_ON_FAILURE(handle, KRATE_ERROR_CONNECTION_REFUSED);
+       }
+
+       *handle = reinterpret_cast<krate_manager_h>(client);
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_manager_destroy(krate_manager_h handle)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       delete &GetKrateContext(handle);
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_manager_add_event_cb(krate_manager_h handle, const char* event, krate_event_cb callback, void* user_data, int *id)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(event, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext &context = GetKrateContext(handle);
+       int ret = context.subscribeSignal(std::string("Manager::") + event,
+                                                                         callback, user_data);
+       if (ret < 0)
+               return KRATE_ERROR_INVALID_PARAMETER;
+
+       *id = ret;
+       return KRATE_ERROR_NONE;
+}
+
+int krate_manager_remove_event_cb(krate_manager_h handle, int callback_id)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(callback_id >= 0, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext &context = GetKrateContext(handle);
+       int ret =  context.unsubscribeSignal(callback_id);
+       if (ret)
+               return KRATE_ERROR_INVALID_PARAMETER;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_manager_create_krate(krate_manager_h handle, const char* name, const char* manifest)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(manifest, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext &client = GetKrateContext(handle);
+       Krate::Manager krate = client.createKrateInterface<Krate::Manager>();
+       return krate.createKrate(name, manifest);
+}
+
+int krate_manager_destroy_krate(krate_manager_h handle, const char* name)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext &client = GetKrateContext(handle);
+       Krate::Manager krate = client.createKrateInterface<Krate::Manager>();
+       return krate.removeKrate(name);
+}
+
+int krate_manager_get_krate_state(krate_manager_h handle, const char* name, krate_state_e *state)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext &client = GetKrateContext(handle);
+       Krate::Manager krate = client.createKrateInterface<Krate::Manager>();
+
+       int result = krate.getKrateState(name);
+       if (result == 0) {
+               return KRATE_ERROR_NO_DATA;
+       }
+
+       *state = (krate_state_e)result;
+       return KRATE_ERROR_NONE;
+}
+
+int krate_manager_foreach_name(krate_manager_h handle, krate_state_e state,
+                                                 krate_manager_foreach_cb callback, void* user_data)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER);
+
+       KrateContext &client = GetKrateContext(handle);
+       Krate::Manager krate = client.createKrateInterface<Krate::Manager>();
+       std::vector<std::string> list = krate.getKrateList(state);
+       for (std::vector<std::string>::iterator it = list.begin();
+                it != list.end(); it++) {
+               if (!callback((*it).c_str(), user_data))
+                       break;
+       }
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_manager_reset_krate_password(krate_manager_h handle, const char* name, const char* new_password)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER);
+
+       if (new_password == NULL) {
+               new_password = "";
+       }
+
+       KrateContext &client = GetKrateContext(handle);
+       Krate::Manager krate = client.createKrateInterface<Krate::Manager>();
+
+       return krate.resetKratePassword(name, new_password);
+}
diff --git a/lib/krate/krate.h b/lib/krate/krate.h
new file mode 100644 (file)
index 0000000..15aa135
--- /dev/null
@@ -0,0 +1,309 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __KRATE_KRATE_MANAGER_H__
+#define __KRATE_KRATE_MANAGER_H__
+
+#include <tizen.h>
+
+/**
+ * @file krate.h
+ * @brief This file defines common data types required to krate APIs.
+ */
+
+#ifndef KRATE_API
+#define KRATE_API __attribute__((visibility("default")))
+#endif // API
+
+#ifndef TRUE
+#define TRUE    1
+#endif
+
+#ifndef FALSE
+#define FALSE   0
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  CAPI_KRATE_KRATE_MANAGER_MODULE
+ * @{
+ */
+
+/**
+ * @brief       Enumeration of device policy API errors
+ * @since_tizen 3.0
+ */
+typedef enum {
+       KRATE_ERROR_NONE                 = TIZEN_ERROR_NONE,                 /**< The operation was successful */
+       KRATE_ERROR_INVALID_PARAMETER    = TIZEN_ERROR_INVALID_PARAMETER,    /**< Invalid parameter */
+       KRATE_ERROR_CONNECTION_REFUSED   = TIZEN_ERROR_CONNECTION_REFUSED,   /**< Connection refused */
+       KRATE_ERROR_TIMED_OUT            = TIZEN_ERROR_TIMED_OUT,            /**< Time out */
+       KRATE_ERROR_PERMISSION_DENIED    = TIZEN_ERROR_PERMISSION_DENIED,    /**< Access privilege is not sufficient */
+       KRATE_ERROR_NOT_SUPPORTED        = TIZEN_ERROR_NOT_SUPPORTED,        /**< Operation is not supported */
+       KRATE_ERROR_NO_SUCH_FILE         = TIZEN_ERROR_NO_SUCH_FILE,         /**< No such file or directory */
+       KRATE_ERROR_FILE_EXISTS          = TIZEN_ERROR_FILE_EXISTS,          /**< File exists */
+       KRATE_ERROR_OUT_OF_MEMORY        = TIZEN_ERROR_OUT_OF_MEMORY,        /**< Out of memory */
+       KRATE_ERROR_NO_DATA              = TIZEN_ERROR_NO_DATA               /**< No Data */
+} krate_error_type_e;
+
+/**
+ * @brief       The krate manager handle
+ * @details     The krate manager  handle is an abstraction of the
+ *              logical connection between the krate manager and it's client.
+ *              The krate manager handle must be created by using
+ *              krate_manager_create() before attempting to use almost any of
+ *              the krate related APIs, and it should be freed when interaction
+ *              with the krate manager is no longer required.
+ *              To release the handle, use krate_manager_destroy().
+ * @since_tizen 3.0
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ */
+typedef void* krate_manager_h;
+
+/**
+ * @brief       Creates the krate manager handle.
+ * @details     This API creates krate manager handle required to
+ *              the krate related APIs.
+ *              This API is also used to verify whether caller is authorized
+ *              or not.
+ * @since_tizen 3.0
+ * @param[out]  handle The krate manager handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_CONNECTION_REFUSED Connection refused
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @see         krate_manager_destroy()
+ * @see         get_last_result()
+ */
+KRATE_API int krate_manager_create(krate_manager_h *handle);
+
+/**
+ * @brief       Releases the krate manager handle.
+ * @details     This API must be called if interaction with the krate manager is
+ *              no longer required.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate manager handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         The handle must be created by krate_manager_create()
+ * @see         krate_manager_create()
+ */
+KRATE_API int krate_manager_destroy(krate_manager_h handle);
+
+/**
+ * @brief       Called when a krate raises a event.
+ * @since_tizen 3.0
+ * @param[in]   name The krate name
+ * @param[in]   object The object name triggered the event
+ * @param[in]   user_data The user data passed from krate_manager_add_event_cb
+ * @see         krate_manager_add_event_cb()
+ * @see         krate_manager_remove_event_cb()
+ */
+typedef void(*krate_event_cb)(const char* name, const char* object, void* user_data);
+
+/**
+ * @brief       Adds krate event callback.
+ * @details     This API can be used to receive events sent by krate
+ *              The callback specified to this function is automatically called when
+ *              the krate is created or removed.
+ * @since_tizen 3.0
+ * @param[in]   context The krate_manager handle
+ * @param[in]   event The event name to receive
+ * @param[in]   callback The event callback
+ * @param[in]   user_data The user data passed to the callback function
+ * @param[out]  id Signal identifier
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_manager_create().
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ * @see         krate_manager_remove_event_cb()
+ */
+KRATE_API int krate_manager_add_event_cb(krate_manager_h handle,
+                                                                         const char* event,
+                                                                         krate_event_cb callback, void* user_data,
+                                                                         int* id);
+
+/**
+ * @brief       Removes krate event callback.
+ * @details     This API removes krate event callback
+ * @since_tizen 3.0
+ * @param[in]   context The krate manager handle
+ * @param[in]   id Signal identifier
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The context must be created by krate_manager_create().
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ * @see         krate_manager_add_event_cb()
+ */
+KRATE_API int krate_manager_remove_event_cb(krate_manager_h handle, int id);
+
+/**
+ * @brief       Creates a new krate.
+ * @details     This API creates a container. All file system objects neeeded
+ *              will be also created. manifest XML passed by parameter will be
+ *              used when the krate is running.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate manager handle
+ * @param[in]   name The krate name to be created
+ * @param[in]   manifest The manifest XML to be used when the krate is runned.
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API
+ * @pre         The handle must be created by krate_manager_create().
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ * @see         krate_manager_destroy_krate()
+ * @see         krate_manager_create_krate_iterator()
+ */
+KRATE_API int krate_manager_create_krate(krate_manager_h handle,
+                                                                                       const char* name,
+                                                                                       const char* manifest);
+
+/**
+ * @brief       Removes existing krate.
+ * @details     This removes krate. All file system objects created for the krate
+ *              will be also erased.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate manager handle
+ * @param[in]   name The krate name to be removed
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API or the caller is not the owner
+ *              of the krate
+ * @pre         The handle must be created by krate_manager_create().
+ * @pre         The krate corresponding to the given name must be
+ *              created before use of this API.
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ * @see         krate_manager_create_krate()
+ * @see         krate_manager_create_krate_iterator()
+ */
+KRATE_API int krate_manager_destroy_krate(krate_manager_h handle,
+                                                                                       const char* name);
+
+/*
+ * @brief       Enumeration for krate state
+ * @since_tizen 3.0
+ */
+typedef enum {
+       KRATE_STATE_LOCKED       = 0x01,  /**< Krate has been defined, but it can not start. */
+       KRATE_STATE_RUNNING      = 0x02, /**< Krate has been started. */
+       KRATE_STATE_ALL          = 0xff  /**< This presents all of the state  */
+} krate_state_e;
+
+/**
+ * @brief       Gets the krate state.
+ * @details     This API can be used to get the state of the krate. The krate can
+ *              have one of the three states(running, locked).
+ * @since_tizen 3.0
+ * @param[in]   handle The krate policy handle
+ * @param[in]   name The krate name
+ * @param[out]  state The krate state
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_NO_DATA No such krate to get state
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_manager_create().
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ * @see         krate_manager_create_krate()
+ * @see         krate_manager_destroy_krate()
+ */
+KRATE_API int krate_manager_get_krate_state(krate_manager_h handle,
+                                                                                       const char* name,
+                                                                                       krate_state_e* state);
+
+/**
+ * @brief       Called to get all the name of created krates.
+ * @since_tizen 3.0
+ * @param[in]   name The krate name
+ * @param[in]   user_data The user data passed from krate_manager_foreach_name
+ * @return      true to continue with the next iteration of the loop, otherwise false to break out out the loop
+ * @see         krate_manager_foreach_name()
+ */
+typedef bool(*krate_manager_foreach_cb)(const char* name, void* user_data);
+
+/**
+ * @brief       Retrieves all the name of created krates
+ * @details     This API calls krate_manager_foreach_cb() once for each krate name
+ *              with traversing the created krates list.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate policy handle
+ * @param[in]   state a combination of the krate state to look
+ * @param[in]   callback The iteration callback function
+ * @param[in]   user_data The user data passed to the callback function
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         The handle must be created by krate_manager_create().
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ * @see         krate_manager_create_krate()
+ * @see         krate_manager_destroy_krate()
+ */
+KRATE_API int krate_manager_foreach_name(krate_manager_h handle,
+                                                                                  krate_state_e state,
+                                                                                  krate_manager_foreach_cb callback,
+                                                                                  void* user_data);
+
+/**
+ * @brief       Reset password for the krate.
+ * @details     This API can be used to set password for the krate. The password
+ *              of the krate can be used for authenticating user.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate policy handle
+ * @param[in]   name The krate name
+ * @param[out]  new_password new password if NULL, existing password will be removed
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_NO_DATA No such krate to get state
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_manager_create().
+ * @see         krate_manager_create()
+ * @see         krate_manager_destroy()
+ */
+KRATE_API int krate_manager_reset_krate_password(krate_manager_h handle,
+                                                                       const char* name, const char* new_password);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __KRATE_KRATE_MANAGER_H__ */
diff --git a/lib/krate/package-info-internal.h b/lib/krate/package-info-internal.h
new file mode 100644 (file)
index 0000000..d84fa79
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __KRATE_PACKAGE_INFO_INTERNAL_H__
+#define __KRATE_PACKAGE_INFO_INTERNAL_H__
+
+#include <glib.h>
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct icon_x {
+               char *text;
+               char *lang;
+               char *section;
+               char *size;
+               char *resolution;
+               char *dpi;
+} icon_x;
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct description_x {
+               char *name;
+               char *text;
+               char *lang;
+} description_x;
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct label_x {
+               char *name;
+               char *text;
+               char *lang;
+} label_x;
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct author_x {
+               char *email;
+               char *href;
+               char *text;
+               char *lang;
+} author_x;
+
+// pkgmgr-info : include/pkgmgrinfo_basic.h
+typedef struct package_x {
+       char *for_all_users;        /**< Flag that indicates if the package is available for everyone or for current user only, no xml part*/
+       char *package;              /**< package name, attr*/
+       char *version;              /**< package version, attr*/
+       char *installlocation;      /**< package install location, attr, default: "internal-only"*/
+       char *ns;                   /**<name space, attr*/
+       char *removable;            /**< package removable flag, no xml part*/
+       char *preload;              /**< package preload flag, no xml part*/
+       char *readonly;             /**< package readonly flag, no xml part*/
+       char *update;               /**< package update flag, no xml part*/
+       char *appsetting;           /**< package app setting flag, attr, default: "false"*/
+       char *system;               /**< package system flag, no xml part*/
+       char *type;                 /**< package type, attr*/
+       char *package_size;         /**< package size for external installation, attr*/
+       char *installed_time;       /**< installed time after finishing of installation, no xml part*/
+       char *installed_storage;    /**< package currently installed storage, no xml part*/
+       char *storeclient_id;       /**< id of store client for installed package, attr*/
+       char *mainapp_id;           /**< app id of main application, no xml part*/
+       char *package_url;          /**< app id of main application, attr*/
+       char *root_path;            /**< package root path, attr*/
+       char *csc_path;             /**< package csc path, attr*/
+       char *nodisplay_setting;    /**< package no display setting menu, attr, default: "false"*/
+       char *support_disable;      /**< package support disable flag, attr, default: "false"*/
+       char *api_version;          /**< minimum version of API package using, attr, default: patch_version trimmed version from tizen_full_version*/
+       char *tep_name;             /*no xml part*/
+       char *zip_mount_file;       /*no xml part*/
+       char *backend_installer;    /**< package backend installer, attr*/
+       GList *icon;                /**< package icon, element*/
+       GList *label;               /**< package label, element*/
+       GList *author;              /**< package author, element*/
+       GList *description;         /**< package description, element*/
+       GList *license;             /**< package license, no xml part*/
+       GList *privileges;          /**< package privileges, element*/
+       GList *application;         /**< package's application, element*/
+       GList *compatibility;       /**< package compatibility, element*/
+       GList *deviceprofile;       /**< package device profile, element*/
+} package_x;
+
+// pkgmgr-info : include/pkgmgrinfo_private.h
+typedef struct _pkgmgr_pkginfo_x {
+       uid_t uid;
+       package_x *pkg_info;
+       char *locale;
+} pkgmgr_pkginfo_x;
+
+// package-manager : src/package_info.c
+typedef struct package_info_s {
+       char *package;
+       pkgmgr_pkginfo_x *pkgmgr_pkginfo;
+} package_info_s;
+
+#endif //__KRATE_PACKAGE_INFO_INTERNAL_H__
diff --git a/lib/krate/package-proxy.cpp b/lib/krate/package-proxy.cpp
new file mode 100644 (file)
index 0000000..690397e
--- /dev/null
@@ -0,0 +1,316 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include <cstdlib>
+#include <cstring>
+#include <algorithm>
+
+#include <pkgmgr-info.h>
+#include <package-manager.h>
+#include <tzplatform_config.h>
+#include <klay/auth/user.h>
+
+#include "debug.h"
+#include "krate.h"
+#include "package-proxy.h"
+#include "package-info-internal.h"
+
+#include "client.h"
+#include "rmi/package-proxy.h"
+
+using namespace Krate;
+
+struct krate_package_proxy_s {
+       PackageProxy proxy;
+       std::string krateName;
+       pkgmgr_client* pNativeHandle;
+       package_manager_event_cb pCallback;
+       void *pCallbackUserData;
+};
+
+static inline krate_package_proxy_s* getInstance(krate_package_proxy_h handle)
+{
+       return reinterpret_cast<krate_package_proxy_s *>(handle);
+}
+
+static int packageEventHandler(uid_t target_uid, int req_id,
+                                                          const char *pkg_type, const char *pkg_name,
+                                                          const char *key, const char *val,
+                                                          const void *pmsg, void *data)
+{
+       static auto event_type = (package_manager_event_type_e)-1;
+       auto event_state = PACKAGE_MANAGER_EVENT_STATE_FAILED;
+       auto instance = getInstance(data);
+       std::string keystr = key;
+       int progress = 0;
+
+       if (target_uid != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
+               try {
+                       runtime::User pkgOwner(target_uid);
+                       if (pkgOwner.getName() != instance->krateName) {
+                               return PACKAGE_MANAGER_ERROR_NONE;
+                       }
+               } catch (runtime::Exception &e) {
+                       return PACKAGE_MANAGER_ERROR_NONE;
+               }
+       }
+
+       std::transform(keystr.begin(), keystr.end(), keystr.begin(), ::tolower);
+
+       if (keystr == "start") {
+               if (val == NULL) {
+                       return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
+               }
+
+               std::string valstr = val;
+               std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower);
+               if (valstr == "install") {
+                       event_type = PACKAGE_MANAGER_EVENT_TYPE_INSTALL;
+               } else if (valstr == "uninstall") {
+                       event_type = PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL;
+               } else if (valstr == "update") {
+                       event_type = PACKAGE_MANAGER_EVENT_TYPE_UPDATE;
+               } else {
+                       return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER;
+               }
+
+               event_state = PACKAGE_MANAGER_EVENT_STATE_STARTED;
+       } else if (keystr == "install_percent" ||
+                          keystr == "progress_percent") {
+               event_state = PACKAGE_MANAGER_EVENT_STATE_PROCESSING;
+               progress = std::stoi(val);
+       } else if (keystr == "error") {
+               event_state = PACKAGE_MANAGER_EVENT_STATE_FAILED;
+       } else if (keystr == "end" ||
+                          keystr == "ok") {
+               event_state = PACKAGE_MANAGER_EVENT_STATE_COMPLETED;
+               progress = 100;
+       }
+
+       instance->pCallback(pkg_type, pkg_name,
+                                               event_type, event_state, progress,
+                                               PACKAGE_MANAGER_ERROR_NONE,
+                                               instance->pCallbackUserData);
+
+
+       return PACKAGE_MANAGER_ERROR_NONE;
+}
+
+static package_info_h make_package_info_handle(const PackageProxy::PackageInfo& info)
+{
+       uid_t krate_uid;
+
+       if (info.id.empty()) {
+               return NULL;
+       }
+
+       try {
+               runtime::User pkgOwner(info.krate);
+               krate_uid = pkgOwner.getUid();
+       } catch (runtime::Exception &e) {
+               return NULL;
+       }
+
+       package_x* package = (package_x*)::calloc(1, sizeof(package_x));
+       pkgmgr_pkginfo_x* pkginfo = (pkgmgr_pkginfo_x*)::calloc(1, sizeof(pkgmgr_pkginfo_x));
+       package_info_s* packageinfo = (package_info_s*)::calloc(1, sizeof(package_info_s));
+
+       packageinfo->package = ::strdup(info.id.c_str());
+       packageinfo->pkgmgr_pkginfo = pkginfo;
+
+       pkginfo->uid = krate_uid;
+       pkginfo->locale = ::strdup(info.locale.c_str());
+       pkginfo->pkg_info = package;
+
+       package->for_all_users = ::strdup("false");
+       package->package = ::strdup(info.id.c_str());
+       package->version = ::strdup(info.version.c_str());
+       package->removable = ::strdup(info.isRemovable? "true":"false");
+       package->preload = ::strdup(info.isPreload? "true":"false");
+       package->system = ::strdup(info.isSystem? "true":"false");
+       package->type = ::strdup(info.type.c_str());
+       package->mainapp_id = ::strdup(info.mainAppId.c_str());
+       package->api_version = ::strdup(info.apiVersion.c_str());
+
+       icon_x* icon = (icon_x*)::calloc(1, sizeof(icon_x));
+       icon->text = ::strdup(info.icon.c_str());
+       icon->lang = ::strdup(info.locale.c_str());
+       package->icon = ::g_list_append(NULL, icon);
+
+       label_x* label = (label_x*)::calloc(1, sizeof(label_x));
+       label->text = ::strdup(info.label.c_str());
+       label->lang = ::strdup(info.locale.c_str());
+       package->label = ::g_list_append(NULL, label);
+
+       description_x* desc = (description_x*)::calloc(1, sizeof(description_x));
+       desc->text = ::strdup(info.description.c_str());
+       desc->lang = ::strdup(info.locale.c_str());
+       package->description = ::g_list_append(NULL, desc);
+
+       author_x* author = (author_x*)::calloc(1, sizeof(author_x));
+       author->text = ::strdup(info.author.name.c_str());
+       author->email = ::strdup(info.author.email.c_str());
+       author->href = ::strdup(info.author.href.c_str());
+       author->lang = ::strdup(info.locale.c_str());
+       package->author = ::g_list_append(NULL, author);
+
+       return reinterpret_cast<package_info_h>(packageinfo);
+}
+
+int krate_package_proxy_create(krate_manager_h manager, const char* name, krate_package_proxy_h *handle)
+{
+       RET_ON_FAILURE(manager, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       krate_package_proxy_s* instance = new krate_package_proxy_s {
+               GetKrateContext(manager).
+                                                               createKrateInterface<PackageProxy>(),
+               name, ::pkgmgr_client_new(PC_LISTENING), NULL, NULL
+       };
+
+       *handle = reinterpret_cast<krate_package_proxy_h>(instance);
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_destroy(krate_package_proxy_h handle)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       krate_package_proxy_s* instance = getInstance(handle);
+
+       ::pkgmgr_client_free(instance->pNativeHandle);
+
+       delete instance;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_get_package_info(krate_package_proxy_h handle, const char* package_id, package_info_h* package_info)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(package_id, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(package_info, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       const auto& info = proxy.getPackageInfo(name, package_id);
+       package_info_h ret = make_package_info_handle(info);
+
+       if (ret == NULL) {
+               return KRATE_ERROR_INVALID_PARAMETER;
+       }
+
+       *package_info = ret;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_foreach_package_info(krate_package_proxy_h handle, package_manager_package_info_cb callback, void *user_data)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       for (const auto& pkgid : proxy.getPackageList(name)) {
+               package_info_h info_h = make_package_info_handle(proxy.getPackageInfo(name, pkgid));
+               int ret = callback(info_h, user_data);
+               package_info_destroy(info_h);
+               if (!ret) {
+                       break;
+               }
+       }
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_set_event_status(krate_package_proxy_h handle, int status_type)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+
+       int ret;
+       ret = pkgmgrinfo_client_set_status_type(instance->pNativeHandle, status_type);
+
+       if (ret != PACKAGE_MANAGER_ERROR_NONE)
+               return KRATE_ERROR_INVALID_PARAMETER;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_set_event_cb(krate_package_proxy_h handle, package_manager_event_cb callback, void *user_data)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+
+       instance->pCallback = callback;
+       instance->pCallbackUserData = user_data;
+
+       int ret;
+       ret = pkgmgr_client_listen_status(instance->pNativeHandle, packageEventHandler, handle);
+
+       if (ret < 0)
+               return KRATE_ERROR_INVALID_PARAMETER;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_unset_event_cb(krate_package_proxy_h handle)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+
+       int ret;
+       ret = pkgmgr_client_remove_listen_status(instance->pNativeHandle);
+
+       if (ret < 0)
+               return KRATE_ERROR_INVALID_PARAMETER;
+
+       return KRATE_ERROR_NONE;
+}
+
+int krate_package_proxy_install(krate_package_proxy_h handle, const char* package_path)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(package_path, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       return proxy.install(name, package_path);
+}
+
+int krate_package_proxy_uninstall(krate_package_proxy_h handle, const char* package_id)
+{
+       RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(package_id, KRATE_ERROR_INVALID_PARAMETER);
+
+       auto instance = getInstance(handle);
+       auto& proxy = instance->proxy;
+       const std::string& name = instance->krateName;
+
+       return proxy.uninstall(name, package_id);
+}
diff --git a/lib/krate/package-proxy.h b/lib/krate/package-proxy.h
new file mode 100644 (file)
index 0000000..5dda76a
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __CAPI_KRATE_PACKAGE_INFO_H__
+#define __CAPI_KRATE_PACKAGE_INFO_H__
+
+#include <package_info.h>
+#include <package_manager.h>
+
+#include <krate/krate.h>
+
+/**
+ * @file package-info.h
+ * @brief This file provides APIs to get the information of packages in the krate
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup  CAPI_KRATE_KRATE_PACKAGE_INFO_MODULE
+ * @{
+ */
+
+/**
+ * @brief       The krate package proxy handle
+ * @since_tizen 3.0
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ */
+typedef void* krate_package_proxy_h;
+
+/**
+ * @brief       Acquires the krate package proxy handle.
+ * @details     This API acquires krate package proxy handle required to call
+ *              the krate package_manager APIs.
+ * @since_tizen 3.0
+ * @param[in]   manager The krate manager handle
+ * @param[in]   name The krate name
+ * @param[out]  handle The krate package proxy handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_CONNECTION_REFUSED Connection refused
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @see         krate_manager_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         get_last_result()
+ */
+KRATE_API int krate_package_proxy_create(krate_manager_h manager, const char* name, krate_package_proxy_h *handle);
+
+/**
+ * @brief       Releases the krate package proxy handle.
+ * @details     This API must be called if interaction with the krate package
+ *              manager handle is no longer required.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate package proxy handle
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_package_proxy_create()
+ * @see         krate_package_proxy_create()
+ */
+KRATE_API int krate_package_proxy_destroy(krate_package_proxy_h handle);
+
+/**
+ * @brief       Gets the package information for the given package in the krate.
+ * @details     This API gets package information handle required to get
+ *              information of the pacakge in the krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate package proxy handle
+ * @param[in]   pakcage_id The package ID
+ * @return      Krate package information handle on success, otherwise NULL
+ * @remark      The specific error code can be obtained by using the
+ *              get_last_result() method. Error codes are described in
+ *              exception section.
+ * @remark      The handle should be destroyed using package_info_destroy().
+ * @exception   #KRATE_ERROR_NONE No error
+ * @exception   #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception   #KRATE_ERROR_TIMED_OUT Time out
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         package_manager_get_package_info()
+ * @see         package_manager_destroy()
+ * @see         get_last_result()
+ */
+KRATE_API int krate_package_proxy_get_package_info(krate_package_proxy_h handle, const char* pakcage_id, package_info_h* package_info);
+
+/**
+ * @brief       Retrieves all the IDs of the installed package in the krate.
+ * @details     This API calls package_manager_package_info_cb() once for
+ *              each package information handle with traversing the installed
+ *              package list in the krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate package proxy handle
+ * @param[in]   callback The iteration callback function
+ * @param[in]   user_data The user data passed to the callback function
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre         The handle must be created by krate_package_proxy_create().
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         package_manager_foreach_package_info()
+ */
+KRATE_API int krate_package_proxy_foreach_package_info(krate_package_proxy_h handle, package_manager_package_info_cb callback, void *user_data);
+
+/**
+ * @brief       Installs the package located at the given path into the krate.
+ * @details     Administrator can use this API to install the package into the
+ *              krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate package proxy handle
+ * @param[in]   name The krate name
+ * @param[in]   package_path The absolute path to the package to be installed
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_NO_SUCH_FILE No such package file
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API or the caller is not the owner
+ *              of the krate
+ * @pre         The handle must be created by krate_package_proxy_create().
+ * @pre         The krate corresponding to the given name must be
+ *              created before use of this API.
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         krate_package_proxy_uninstall()
+ * @see         package_manager_request_install()
+ */
+KRATE_API int krate_package_proxy_install(krate_package_proxy_h handle, const char* package_path);
+
+/**
+ * @brief       Uinstalls the package with the given ID from the krate.
+ * @details     Administrator can use this API to uninstall the package from the
+ *              krate.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate package proxy handle
+ * @param[in]   name The krate name
+ * @param[in]   pakcage_id The pakcage ID
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @retval      #KRATE_ERROR_NO_DATA No such pacakge to unintall
+ * @retval      #KRATE_ERROR_PERMISSION_DENIED The application does not have
+ *              the privilege to call this API or the caller is not the owner
+ *              of the krate
+ * @pre         The handle must be created by krate_package_proxy_create().
+ * @pre         The krate corresponding to the given name must be
+ *              created before use of this API.
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         krate_package_proxy_install()
+ * @see         package_manager_request_uninstall()
+ */
+KRATE_API int krate_package_proxy_uninstall(krate_package_proxy_h handle, const char* pakcage_id);
+
+/**
+ * @brief       Sets the event status that presents the package has been
+ *              installed, uninstalled or updated in the krate.
+ * @details     This API sets the event status of the package for monitoring
+ *              whether the package has been installed, uninstalled or updated.
+ *               event status can be combined multiple status using OR operation.
+ * @since_tizen 3.0
+ * @param[in]   handle The krate package proxy handle
+ * @param[in]   status_type The status of the package
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         The handle must be created by krate_package_proxy_create().
+ * @pre         the krate corresponding to the given name must be
+ *              created before use of this api.
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         krate_package_proxy_uninstall()
+ * @see         krate_package_proxy_set_event_cb()
+ * @see         krate_package_proxy_unset_event_cb()
+ * @see         package_manager_set_event_status()
+ */
+KRATE_API int krate_package_proxy_set_event_status(krate_package_proxy_h handle, int status_type);
+
+/**
+ * @brief       Registers a callback function for package event.
+ * @details     This API sets a callback function to be invoked when the package
+ *              has been installed, uninstalled or updated.
+ * @since_tizen 3.0
+ * @param[in]   handle the krate package proxy handle
+ * @param[in]   callback The callback function to be registered
+ * @param[in]   user_data The user data to be passed to the callback function
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         the handle must be created by krate_package_proxy_create().
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         krate_package_proxy_uninstall()
+ * @see         krate_package_proxy_set_event_status()
+ * @see         krate_package_proxy_unset_event_cb()
+ * @see         package_manager_event_cb()
+ * @see         package_manager_set_event_cb()
+ */
+KRATE_API int krate_package_proxy_set_event_cb(krate_package_proxy_h handle, package_manager_event_cb callback, void *user_data);
+
+/**
+ * @brief       Unregisters the callback function.
+ * @details     This API unsets the callback funtion not to be invoked by
+ *              package event status
+ * @since_tizen 3.0
+ * @param[in]   handle the krate package proxy handle
+ * @param[in]   name the krate name
+ * @return      #KRATE_ERROR_NONE on success, otherwise a negative value
+ * @retval      #KRATE_ERROR_NONE Successful
+ * @retval      #KRATE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval      #KRATE_ERROR_TIMED_OUT Time out
+ * @pre         the handle must be created by krate_package_proxy_create().
+ *              created before use of this api.
+ * @see         krate_package_proxy_create()
+ * @see         krate_package_proxy_destroy()
+ * @see         krate_package_proxy_uninstall()
+ * @see         krate_package_proxy_set_event_status()
+ * @see         krate_package_proxy_set_event_cb()
+ * @see         package_manager_unset_event_cb()
+ */
+KRATE_API int krate_package_proxy_unset_event_cb(krate_package_proxy_h handle);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CAPI_KRATE_PACKAGE_INFO_H__ */
diff --git a/lib/manager.cpp b/lib/manager.cpp
new file mode 100644 (file)
index 0000000..57a5264
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include "rmi/manager.h"
+
+namespace Krate {
+
+Manager::Manager(KrateControlContext& ctx) :
+       context(ctx)
+{
+}
+
+Manager::~Manager()
+{
+}
+
+int Manager::createKrate(const std::string& name, const std::string& setupWizAppid)
+{
+       try {
+               return context->methodCall<int>("Manager::createKrate", name, setupWizAppid);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Manager::removeKrate(const std::string& name)
+{
+       try {
+               return context->methodCall<int>("Manager::removeKrate", name);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Manager::lockKrate(const std::string& name)
+{
+       try {
+               return context->methodCall<int>("Manager::lockKrate", name);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Manager::unlockKrate(const std::string& name)
+{
+       try {
+               return context->methodCall<int>("Manager::unlockKrate", name);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int Manager::getKrateState(const std::string& name)
+{
+       try {
+               return context->methodCall<int>("Manager::getKrateState", name);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+std::vector<std::string> Manager::getKrateList(int state)
+{
+       std::vector<std::string> empty;
+       try {
+               return context->methodCall<std::vector<std::string>>("Manager::getKrateList", state);
+       } catch (runtime::Exception& e) {
+               return empty;
+       }
+}
+
+int Manager::resetKratePassword(const std::string& name, const std::string& newPassword)
+{
+       try {
+               return context->methodCall<int>("Manager::resetKratePassword", name, newPassword);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+} // namespace Krate
diff --git a/lib/package-proxy.cpp b/lib/package-proxy.cpp
new file mode 100644 (file)
index 0000000..0a58e34
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include "rmi/package-proxy.h"
+
+namespace Krate {
+
+PackageProxy::PackageProxy(KrateControlContext& ctx) :
+       context(ctx)
+{
+}
+
+PackageProxy::~PackageProxy()
+{
+}
+
+PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, const std::string& pkgid)
+{
+       try {
+               return context->methodCall<PackageProxy::PackageInfo>("PackageProxy::getPackageInfo", name, pkgid);
+       } catch (runtime::Exception& e) {}
+       return PackageProxy::PackageInfo();
+}
+
+std::vector<std::string> PackageProxy::getPackageList(const std::string& krate)
+{
+       try {
+               return context->methodCall<std::vector<std::string>>("PackageProxy::getPackageList", krate);
+       } catch (runtime::Exception& e) {}
+       return std::vector<std::string>();;
+}
+
+int PackageProxy::install(const std::string& name, const std::string& pkgid)
+{
+       try {
+               return context->methodCall<int>("PackageProxy::install", name, pkgid);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int PackageProxy::uninstall(const std::string& name, const std::string& pkgid)
+{
+       try {
+               return context->methodCall<int>("PackageProxy::uninstall", name, pkgid);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+} // namespace Krate
index be7a884..ab4f5e3 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
+# 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
 #
@@ -18,10 +18,12 @@ FILE(GLOB PAM_SRCS  krate.cpp
                                        krate-builder.cpp
 )
 
-SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
 
-ADD_LIBRARY(pam_${PROJECT_NAME} MODULE ${PAM_SRCS})
-SET_TARGET_PROPERTIES(pam_${PROJECT_NAME} PROPERTIES  PREFIX ""
+SET(PAM_NAME pam_${PROJECT_NAME})
+
+ADD_LIBRARY(${PAM_NAME} MODULE ${PAM_SRCS})
+SET_TARGET_PROPERTIES(${PAM_NAME} PROPERTIES  PREFIX ""
        COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/krate"
        COMPILE_FLAGS "-fvisibility=hidden"
 )
@@ -36,16 +38,17 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(PAM DEFAULT_MSG PAM_LIBRARY PAM_INCLUDE_DIR)
 
 PKG_CHECK_MODULES(PAM_DEPS     REQUIRED
                                                        klay
+                                                       libxml-2.0
 )
 
 INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR} ${PAM_DEPS_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(pam_${PROJECT_NAME} ${PAM_LIBRARY} ${PAM_DEPS_LIBRARIES} pthread)
+TARGET_LINK_LIBRARIES(${PAM_NAME} ${PAM_LIBRARY} ${PAM_DEPS_LIBRARIES} pthread)
 
-TARGET_COMPILE_DEFINITIONS(pam_${PROJECT_NAME} PRIVATE
-       CONF_PATH="${CONF_INSTALL_DIR}"
+TARGET_COMPILE_DEFINITIONS(${PAM_NAME} PRIVATE
+       CONF_PATH="${CONF_DIR}"
 )
 
 CONFIGURE_FILE(pam.d/systemd-user.in pam.d/systemd-user-${PROJECT_NAME})
 
-INSTALL(TARGETS pam_${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/security)
+INSTALL(TARGETS ${PAM_NAME} DESTINATION ${LIB_INSTALL_DIR}/security)
 INSTALL(FILES pam.d/systemd-user-${PROJECT_NAME} DESTINATION ${PAMD_DIR})
index 06fea56..84496cf 100644 (file)
 #include <klay/xml/parser.h>
 #include <klay/xml/document.h>
 
-#define KRATE_MANIFEST_DIR CONF_PATH "/krate/"
-
 std::string buildKrateManifestPath(const std::string& name)
 {
-       return KRATE_MANIFEST_DIR + name + ".xml";
+       return CONF_PATH "/" + name + ".xml";
 }
 
 std::string getKrateName(pam_handle_t* handle)
index a6e952e..e132b27 100644 (file)
@@ -5,6 +5,8 @@ License: Apache-2.0
 Source0: file://%{name}-%{version}.tar.gz
 Summary: Tizen Krate Manager
 Group:   Security/Other
+Requires: systemd
+BuildRequires: pam-devel
 BuildRequires: gcc
 BuildRequires: cmake
 BuildRequires: gettext-tools
@@ -17,13 +19,13 @@ BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(appsvc)
 BuildRequires: pkgconfig(libtzplatform-config)
-BuildRequires: pkgconfig(security-privilege-manager)
-BuildRequires: pkgconfig(capi-base-common)
-BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(notification)
 BuildRequires: pkgconfig(key-manager)
 BuildRequires: pkgconfig(auth-fw-admin)
+BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(cynara-session)
+BuildRequires: pkgconfig(libgum)
 
 %description
 The krate package provides a daemon which is responsible for managing each of
@@ -32,16 +34,19 @@ krates.
 %files
 %manifest krate.manifest
 %defattr(644,root,root,755)
-#%attr(755,root,root) %{_bindir}/krate
+%attr(755,root,root) %{_bindir}/krated
 %attr(700,root,root) %{_sbindir}/krate-volume-manager
 %{_unitdir}/krate.service
-#%{_unitdir}/multi-user.target.wants/krate.service
+%{_unitdir}/multi-user.target.wants/krate.service
 %attr(700,root,root) /etc/gumd/useradd.d/20_krate-add.post
 %attr(700,root,root) /etc/gumd/userdel.d/20_krate-remove.post
 %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/indicator_icon.png
 %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/notification_sub_icon.png
 %attr(700,root,root) %dir %{TZ_SYS_ETC}/krate
 %attr(600,root,root) %config %{TZ_SYS_ETC}/krate/owner.xml
+%attr(700,root,root) %{_libdir}/security/pam_*.so
+%attr(700,root,root) %{_sbindir}/krate-admin-cli
+%config /etc/pam.d/*
 
 %prep
 %setup -q
@@ -65,16 +70,20 @@ krates.
          -DSYSTEMD_UNIT_DIR=%{_unitdir} \
          -DPAMD_DIR=/etc/pam.d \
          -DCONF_DIR=%{TZ_SYS_ETC}/krate \
+         -DICON_DIR="%{TZ_SYS_RO_ICONS}/krate" \
          -DAPP_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \
-         -DAPP_ICON_DIR_PREFIX="%{TZ_SYS_RO_ICONS}" \
          -DAPP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}"
 
 make %{?jobs:-j%jobs}
 
 %install
 %make_install
-#mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants
-#ln -s ../krate.service %{buildroot}/%{_unitdir}/multi-user.target.wants/krate.service
+mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants
+ln -s ../krate.service %{buildroot}/%{_unitdir}/multi-user.target.wants/krate.service
+
+%post
+mv /etc/pam.d/systemd-user /etc/pam.d/systemd-user.keep
+cp /etc/pam.d/systemd-user-krate /etc/pam.d/systemd-user
 
 %clean
 rm -rf %{buildroot}
@@ -82,8 +91,8 @@ rm -rf %{buildroot}
 %preun
 
 %postun
+mv /etc/pam.d/systemd-user.keep /etc/pam.d/systemd-user
 
-%if 0
 ## Krate Client Package ########################################################
 %package -n libkrate
 Summary: Tizen Krate Client library
@@ -91,7 +100,7 @@ Group: Development/Libraries
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(capi-appfw-package-manager)
 BuildRequires: pkgconfig(libtzplatform-config)
-Requires: %{name} = %{version}-%{release}
+#Requires: %{name} = %{version}-%{release}
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
@@ -125,48 +134,19 @@ developing the krate client program.
 %{_includedir}/krate
 %{_libdir}/pkgconfig/krate.pc
 
-%endif
-
-## PAM Plugin Package ########################################################
-%package -n dpm-pam-krate
-Summary: PAM Plugin for zone policy in device policy manager
-Group: Development/Libraries
-Requires: systemd
-BuildRequires: pam-devel
-
-%description -n dpm-pam-krate
-PAM Plugin for zone policy in device policy manager and CLI tool
-
-%post -n dpm-pam-krate
-mv /etc/pam.d/systemd-user /etc/pam.d/systemd-user.keep
-cp /etc/pam.d/systemd-user-zone /etc/pam.d/systemd-user
-
-%postun -n dpm-pam-krate
-mv /etc/pam.d/systemd-user.keep /etc/pam.d/systemd-user
-
-%files -n dpm-pam-krate
-%manifest krate.manifest
-%defattr(600,root,root,700)
-%attr(700,root,root) %{_libdir}/security/pam_*.so
-#%attr(700,root,root) %{_sbindir}/zone-admin-cli
-%config /etc/pam.d/*
-
-## Begin of mobile feature ###################################################
-%if "%{profile}" == "mobile"
-
 ## Krate Setup Wizard Package #################################################
 %package -n org.tizen.krate-setup-wizard
 Summary: Tizen Krate setup wizard Interface
 Group: Security/Other
+Requires: libkrate = %{version}-%{release}
 BuildRequires: pkgconfig(efl-extension)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(evas)
 BuildRequires: pkgconfig(notification)
-BuildRequires: pkgconfig(zone)
 
 %description -n org.tizen.krate-setup-wizard
-Tizen Krate setup wizard interface for zone
+Tizen Krate setup wizard interface
 
 %define setup_home %{TZ_SYS_RO_APP}/org.tizen.krate-setup-wizard
 
@@ -205,6 +185,7 @@ Tizen Krate launcher interface
 %package -n org.tizen.keyguard
 Summary: Tizen Krate keyguard Interface
 Group: Security/Other
+Requires: libkrate = %{version}-%{release}
 BuildRequires: pkgconfig(efl-extension)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(capi-appfw-application)
@@ -224,5 +205,3 @@ Tizen Krate keyguard interface
 %{keyguard_home}/bin/*
 %{keyguard_home}/res/*
 %{TZ_SYS_RO_PACKAGES}/org.tizen.keyguard.xml
-
-%endif
diff --git a/rmi/app-proxy.h b/rmi/app-proxy.h
new file mode 100644 (file)
index 0000000..927a8dc
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __APP_PROXY_H__
+#define __APP_PROXY_H__
+
+#include "context.h"
+
+namespace Krate {
+
+/**
+ * This class provides APIs to create/remove and manage names.
+ */
+
+class AppProxy {
+public:
+       AppProxy(KrateControlContext& ctxt);
+       ~AppProxy();
+
+       //application information
+       struct AppInfo {
+               std::string krate;
+               std::string id;
+               std::string locale;
+               std::string package;
+               std::string type;
+               std::string icon;
+               std::string label;
+               int componentType;
+               bool isNoDisplayed;
+               bool isTaskManaged;
+
+               REFLECTABLE
+               (
+                       krate, id, locale, package, type, icon, label,
+                       componentType, isNoDisplayed, isTaskManaged
+               );
+       };
+
+       AppInfo getAppInfo(const std::string& name, const std::string& appid);
+
+       int createIterator(const std::string& name);
+       AppInfo getIteratorValue(int iterator);
+       bool nextIterator(int iterator);
+       int destroyIterator(int iterator);
+
+       //application bundle
+       struct Bundle {
+               std::string operation;
+               std::string uri;
+               std::string mime;
+               std::string category;
+               std::string appId;
+               struct Extra {
+                       std::string key;
+                       std::vector<std::string> value;
+                       REFLECTABLE(key, value);
+               };
+               std::vector<Extra> extraData;
+
+               REFLECTABLE
+               (
+                       operation, uri, mime, category, appId, extraData
+               );
+       };
+
+       int launch(const std::string& name, const Bundle& bundle);
+       int resume(const std::string& name, const std::string& appid);
+       int terminate(const std::string& name, const std::string& appid);
+       bool isRunning(const std::string& name, const std::string& appid);
+
+private:
+       KrateControlContext& context;
+};
+
+} // namespace Krate
+#endif // __APP_PROXY_H__
diff --git a/rmi/manager.h b/rmi/manager.h
new file mode 100644 (file)
index 0000000..53005f7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __MANAGER_H__
+#define __MANAGER_H__
+
+#include "context.h"
+
+namespace Krate {
+
+class Manager {
+public:
+       enum State {
+               Locked      = 0x01,
+               Running     = 0x02,
+       };
+
+       Manager(KrateControlContext& ctxt);
+       ~Manager();
+
+       int createKrate(const std::string& name, const std::string& manifest);
+       int removeKrate(const std::string& name);
+       int lockKrate(const std::string& name);
+       int unlockKrate(const std::string& name);
+
+       int getKrateState(const std::string& name);
+
+       std::vector<std::string> getKrateList(int state);
+
+       int resetKratePassword(const std::string& name, const std::string& newPassword);
+
+private:
+       KrateControlContext& context;
+};
+
+} // namespace Krate
+#endif // __MANAGER_H__
diff --git a/rmi/package-proxy.h b/rmi/package-proxy.h
new file mode 100644 (file)
index 0000000..300d609
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __PACKAGE_PROXY_H__
+#define __PACKAGE_PROXY_H__
+
+#include "context.h"
+
+namespace Krate {
+
+/**
+ * This class provides APIs to control packages in the krates.
+ */
+
+class PackageProxy {
+public:
+       PackageProxy(KrateControlContext& ctxt);
+       ~PackageProxy();
+
+       //package information
+       struct PackageInfo {
+               std::string krate;
+               std::string id;
+               std::string locale;
+               std::string type;
+               std::string icon;
+               std::string label;
+               std::string description;
+               struct {
+                       std::string name;
+                       std::string email;
+                       std::string href;
+                       REFLECTABLE(name, email, href);
+               } author;
+               std::string version;
+               std::string apiVersion;
+               std::string mainAppId;
+               bool isSystem;
+               bool isRemovable;
+               bool isPreload;
+
+               REFLECTABLE
+               (
+                       krate, id, locale, type, icon, label, description, author,
+                       version, apiVersion, mainAppId, isSystem, isRemovable, isPreload
+               );
+       };
+
+       PackageInfo getPackageInfo(const std::string& name, const std::string& pkgid);
+       std::vector<std::string> getPackageList(const std::string& name);
+
+       //package manager request
+       int install(const std::string& name, const std::string& pkgpath);
+       int uninstall(const std::string& name, const std::string& pkgid);
+
+private:
+       KrateControlContext& context;
+};
+
+} // namespace Krate
+#endif // __PACKAGE_PROXY_H__
index 48b71a3..942f7e0 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+SET(SERVER_SRCS        main.cpp
+                               server.cpp
+                               packman.cpp
+                               launchpad.cpp
+                               app-bundle.cpp
+                               manager.cpp
+                               app-proxy.cpp
+                               package-proxy.cpp
+)
 
-SET(TARGET ${PROJECT_NAME})
+SET(DEPENDENCY klay
+                               glib-2.0
+                               gio-2.0
+                               libxml-2.0
+                               bundle
+                               aul
+                               appsvc
+                               pkgmgr
+                               pkgmgr-info
+                               libtzplatform-config
+                               capi-system-system-settings
+                               notification
+                               libgum
+                               cynara-client
+                               cynara-session
+                               auth-fw-admin
+)
+
+SET(SERVER_NAME ${PROJECT_NAME}d)
+
+ADD_EXECUTABLE(${SERVER_NAME} ${SERVER_SRCS})
+
+PKG_CHECK_MODULES(SERVER_DEPS REQUIRED ${DEPENDENCY})
+
+INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${KRATE_SERVER} ${PROJECT_SOURCE_DIR})
+
+TARGET_LINK_LIBRARIES(${SERVER_NAME} ${SERVER_DEPS_LIBRARIES} pthread)
+
+SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES LINK_FLAGS "-pie")
+
+TARGET_COMPILE_DEFINITIONS(${SERVER_NAME} PRIVATE
+       CONF_PATH="${CONF_DIR}"
+       RUN_PATH="${RUN_DIR}"
+       ICON_PATH="${ICON_DIR}"
+)
 
 CONFIGURE_FILE(systemd/krate.service.in systemd/krate.service)
 
+INSTALL(TARGETS ${SERVER_NAME} DESTINATION ${BIN_DIR})
 INSTALL(FILES systemd/krate.service DESTINATION ${SYSTEMD_UNIT_DIR})
 
 INSTALL(FILES ${KRATE_TOOLS}/gumd-scripts/20_krate-add.post DESTINATION /etc/gumd/useradd.d)
 INSTALL(FILES ${KRATE_TOOLS}/gumd-scripts/20_krate-remove.post DESTINATION /etc/gumd/userdel.d)
 
 INSTALL(FILES ${KRATE_DATA}/DefaultManifest.xml DESTINATION ${CONF_DIR} RENAME owner.xml)
-INSTALL(FILES ${KRATE_DATA}/indicator_icon.png DESTINATION ${APP_ICON_DIR_PREFIX}/krate)
-INSTALL(FILES ${KRATE_DATA}/notification_sub_icon.png DESTINATION ${APP_ICON_DIR_PREFIX}/krate)
+INSTALL(FILES ${KRATE_DATA}/indicator_icon.png DESTINATION ${ICON_DIR})
+INSTALL(FILES ${KRATE_DATA}/notification_sub_icon.png DESTINATION ${ICON_DIR})
diff --git a/server/app-bundle.cpp b/server/app-bundle.cpp
new file mode 100644 (file)
index 0000000..518e36f
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include <memory>
+
+#include <klay/exception.h>
+
+#include "app-bundle.h"
+
+Bundle::Bundle() :
+       handle(nullptr)
+{
+       handle = ::bundle_create();
+       if (handle == nullptr) {
+               throw runtime::Exception("Failed to create bundle");
+       }
+}
+
+Bundle::~Bundle()
+{
+       ::bundle_free(handle);
+}
+
+void Bundle::addInternal(const std::string& key, const std::string& value)
+{
+       ::bundle_add_str(handle, key.c_str(), value.c_str());
+}
+
+void Bundle::addArrayInternal(const std::string& key, const std::vector<std::string>& array)
+{
+       std::unique_ptr<const char*[]> arrayptr(new const char*[array.size()]);
+
+       int index = 0;
+       for (const std::string& data : array) {
+               arrayptr.get()[index++] = data.c_str();
+       }
+
+       ::bundle_add_str_array(handle, key.c_str(), arrayptr.get(), array.size());
+}
diff --git a/server/app-bundle.h b/server/app-bundle.h
new file mode 100644 (file)
index 0000000..9ce75ee
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __APP_BUNDLE_H__
+#define __APP_BUNDLE_H__
+
+#include <string>
+#include <vector>
+
+#include <bundle.h>
+
+class Bundle {
+public:
+       Bundle();
+       ~Bundle();
+
+       template<typename T>
+       void add(const std::string& key, const std::vector<T>& value)
+       {
+               addArrayInternal(key, value);
+       }
+
+       template<typename T>
+       void add(const std::string& key, const T& value)
+       {
+               addInternal(key, value);
+       }
+
+       bundle* get() const
+       {
+               return handle;
+       }
+
+private:
+       void addInternal(const std::string& key, const std::string& value);
+       void addArrayInternal(const std::string& key, const std::vector<std::string>& array);
+
+private:
+       bundle* handle;
+};
+
+#endif //__APP_BUNDLE_H__
diff --git a/server/app-proxy.cpp b/server/app-proxy.cpp
new file mode 100644 (file)
index 0000000..38b6e16
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <unordered_map>
+
+#include <system_settings.h>
+#include <klay/auth/user.h>
+#include <klay/audit/logger.h>
+
+#include "packman.h"
+#include "launchpad.h"
+
+#include "rmi/app-proxy.h"
+
+namespace Krate {
+
+namespace {
+
+struct IteratorData {
+       std::string krate;
+       std::vector<ApplicationInfo> list;
+       unsigned int current;
+};
+
+std::unordered_map<int, IteratorData> iteratorMap;
+int newIteratorId = 0;
+
+} // namespace
+
+AppProxy::AppProxy(KrateControlContext& ctx) :
+       context(ctx)
+{
+       context.registerParametricMethod(this, "", (AppProxy::AppInfo)(AppProxy::getAppInfo)(std::string, std::string));
+
+       context.registerParametricMethod(this, "", (int)(AppProxy::createIterator)(std::string));
+       context.registerParametricMethod(this, "", (AppProxy::AppInfo)(AppProxy::getIteratorValue)(int));
+       context.registerParametricMethod(this, "", (bool)(AppProxy::nextIterator)(int));
+       context.registerParametricMethod(this, "", (int)(AppProxy::destroyIterator)(int));
+
+       context.registerParametricMethod(this, "", (int)(AppProxy::launch)(std::string, AppProxy::Bundle));
+       context.registerParametricMethod(this, "", (int)(AppProxy::resume)(std::string, std::string));
+       context.registerParametricMethod(this, "", (int)(AppProxy::terminate)(std::string, std::string));
+       context.registerParametricMethod(this, "", (int)(AppProxy::isRunning)(std::string, std::string));
+}
+
+AppProxy::~AppProxy()
+{
+}
+
+AppProxy::AppInfo AppProxy::getAppInfo(const std::string& name, const std::string& appid)
+{
+       AppInfo appInfo;
+
+       try {
+               runtime::User user(name);
+               ApplicationInfo appinfo(appid, user.getUid());
+               char* locale;
+
+               system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
+               if (locale == NULL) {
+                       appInfo.locale = "No locale";
+               } else {
+                       appInfo.locale = locale;
+                       free(locale);
+               }
+
+               appInfo.krate = name;
+               appInfo.id = appid;
+               appInfo.package = appinfo.getPackage();
+               appInfo.type = appinfo.getType();
+               appInfo.icon = appinfo.getIcon();
+               appInfo.label = appinfo.getLabel();
+               appInfo.componentType = appinfo.getComponentType();
+               appInfo.isNoDisplayed = appinfo.isNoDisplayed();
+               appInfo.isTaskManaged = appinfo.isTaskManaged();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to retrieve application info installed in the krate: " + appid);
+       }
+
+       return appInfo;
+}
+
+int AppProxy::createIterator(const std::string& name)
+{
+       int iteratorId = -1;
+       try {
+               PackageManager& packman = PackageManager::instance();
+               runtime::User user(name);
+               IteratorData data;
+
+               iteratorId = newIteratorId;
+
+               data.krate = name;
+               data.list = packman.getAppList(user.getUid());
+               data.current = 0;
+
+               iteratorMap.insert(std::make_pair(iteratorId, data));
+
+               if (++newIteratorId < 0) {
+                       newIteratorId = 0;
+               }
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to retrieve package info installed in the krate");
+       }
+       return iteratorId;
+}
+
+AppProxy::AppInfo AppProxy::getIteratorValue(int iterator)
+{
+       AppInfo appInfo;
+
+       auto it = iteratorMap.find(iterator);
+       if (it == iteratorMap.end()) {
+               return appInfo;
+       }
+       if (it->second.current >= it->second.list.size()) {
+               return appInfo;
+       }
+
+       const ApplicationInfo& appinfo = it->second.list.at(it->second.current);
+       char* locale;
+
+       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
+       if (locale == NULL) {
+               appInfo.locale = "No locale";
+       } else {
+               appInfo.locale = locale;
+               free(locale);
+       }
+
+       appInfo.krate = it->second.krate;
+       appInfo.id = appinfo.getId();
+       appInfo.package = appinfo.getPackage();
+       appInfo.type = appinfo.getType();
+       appInfo.icon = appinfo.getIcon();
+       appInfo.label = appinfo.getLabel();
+       appInfo.componentType = appinfo.getComponentType();
+       appInfo.isNoDisplayed = appinfo.isNoDisplayed();
+       appInfo.isTaskManaged = appinfo.isTaskManaged();
+
+       return appInfo;
+}
+
+bool AppProxy::nextIterator(int iterator)
+{
+       auto it = iteratorMap.find(iterator);
+       if (it != iteratorMap.end()) {
+               if (++it->second.current < it->second.list.size()) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+int AppProxy::destroyIterator(int iterator)
+{
+       auto it = iteratorMap.find(iterator);
+       if (it != iteratorMap.end()) {
+               iteratorMap.erase(it);
+               return 0;
+       }
+       return -1;
+}
+
+int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle)
+{
+       try {
+               runtime::User user(name);
+               ::Bundle b;
+
+               if (!bundle.operation.empty()) {
+                       b.add("__APP_SVC_OP_TYPE__", bundle.operation);
+               }
+               if (!bundle.uri.empty()) {
+                       b.add("__APP_SVC_URI__", bundle.uri);
+               }
+               if (!bundle.mime.empty()) {
+                       b.add("__APP_SVC_MIME__", bundle.mime);
+               }
+               if (!bundle.category.empty()) {
+                       b.add("__APP_SVC_CATEGORY__", bundle.category);
+               }
+
+               for (Bundle::Extra extra : bundle.extraData) {
+                       if (extra.value.size() > 1) {
+                               b.add(extra.key, extra.value);
+                       } else if (extra.value.size() == 1) {
+                               b.add(extra.key, extra.value.at(0));
+                       }
+               }
+
+               Launchpad launchpad(user.getUid());
+               launchpad.launch(bundle.appId, b);
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to launch app in the krate");
+               return -1;
+       }
+       return 0;
+}
+
+int AppProxy::resume(const std::string& name, const std::string& appid)
+{
+       try {
+               runtime::User user(name);
+               Launchpad launchpad(user.getUid());
+               launchpad.resume(appid);
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to terminate app in the krate");
+               return -1;
+       }
+       return 0;
+}
+
+int AppProxy::terminate(const std::string& name, const std::string& appid)
+{
+       try {
+               runtime::User user(name);
+               Launchpad launchpad(user.getUid());
+               launchpad.terminate(appid);
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to terminate app in the krate");
+               return -1;
+       }
+       return 0;
+}
+
+bool AppProxy::isRunning(const std::string& name, const std::string& appid)
+{
+       try {
+               runtime::User user(name);
+               Launchpad launchpad(user.getUid());
+               return launchpad.isRunning(appid);
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to get app running state in the krate");
+       }
+       return false;
+}
+
+} // namespace Krate
diff --git a/server/context.h b/server/context.h
new file mode 100644 (file)
index 0000000..ab771d9
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __KRATE_CONTEXT_H__
+#define __KRATE_CONTEXT_H__
+
+#include "server.h"
+
+using KrateControlContext = Server;
+
+#endif //__KRATE_CONTEXT_H__
diff --git a/server/launchpad.cpp b/server/launchpad.cpp
new file mode 100644 (file)
index 0000000..d0a1dbf
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+
+#include <aul.h>
+#include <klay/exception.h>
+#include <klay/audit/logger.h>
+
+#include "launchpad.h"
+
+Launchpad::Launchpad(const uid_t uid) :
+       user(uid)
+{
+       if (user == 0) {
+               throw runtime::Exception("No logined user for launching app");
+       }
+}
+
+bool Launchpad::isRunning(const std::string& appid)
+{
+       return ::aul_app_is_running_for_uid(appid.c_str(), user);
+}
+
+void Launchpad::launch(const std::string& appid)
+{
+       launch(appid, Bundle());
+}
+
+void Launchpad::launch(const std::string& appid, const Bundle& bundle)
+{
+       if (::aul_launch_app_for_uid(appid.c_str(), bundle.get(), user) < 0) {
+               throw runtime::Exception("Failed to launch app " + appid);
+       }
+}
+
+void Launchpad::resume(const std::string& appid)
+{
+       if (::aul_resume_app_for_uid(appid.c_str(), user) < 0) {
+               throw runtime::Exception("Failed to resume app " + appid);
+       }
+}
+
+void Launchpad::terminate(const std::string& appid)
+{
+       int pid = ::aul_app_get_pid_for_uid(appid.c_str(), user);
+       if (pid > 0) {
+               if (::aul_terminate_pid_for_uid(pid, user) < 0) {
+                       WARN("Failed to terminate app PID=" + std::to_string(pid));
+                       ::kill(pid, SIGKILL);
+               }
+       }
+}
diff --git a/server/launchpad.h b/server/launchpad.h
new file mode 100644 (file)
index 0000000..c3120ed
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __LAUNCHPAD_H__
+#define __LAUNCHPAD_H__
+
+#include <string>
+
+#include "app-bundle.h"
+
+class Launchpad {
+public:
+       Launchpad(const uid_t uid = 0);
+       Launchpad(const Launchpad&) = delete;
+       Launchpad(Launchpad&&) = delete;
+
+       void launch(const std::string& appid);
+       void launch(const std::string& appid, const Bundle& bundle);
+       void resume(const std::string& appid);
+       bool isRunning(const std::string& appid);
+       void terminate(const std::string& appid);
+
+private:
+       uid_t user;
+};
+
+#endif //__LAUNCHPAD_H__
diff --git a/server/main.cpp b/server/main.cpp
new file mode 100644 (file)
index 0000000..448df58
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include <iostream>
+#include <stdexcept>
+
+#include "server.h"
+
+void signalHandler(int signum)
+{
+       exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+       ::signal(SIGINT, signalHandler);
+
+       ::umask(0);
+
+       try {
+               Server server;
+               server.run();
+       } catch (std::exception &e) {
+               std::cerr << e.what() << std::endl;
+               return 1;
+       }
+
+       return 0;
+}
diff --git a/server/manager.cpp b/server/manager.cpp
new file mode 100644 (file)
index 0000000..5d6bc03
--- /dev/null
@@ -0,0 +1,701 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <algorithm>
+
+#include <notification.h>
+#include <notification_internal.h>
+#include <tzplatform_config.h>
+#include <auth-passwd-admin.h>
+#include <gum/gum-user.h>
+#include <gum/common/gum-user-types.h>
+#include <klay/error.h>
+#include <klay/process.h>
+#include <klay/filesystem.h>
+#include <klay/auth/user.h>
+#include <klay/xml/parser.h>
+#include <klay/xml/document.h>
+#include <klay/dbus/connection.h>
+#include <klay/audit/logger.h>
+
+#include "packman.h"
+#include "launchpad.h"
+
+#include "rmi/manager.h"
+
+#define KRATE_DELEGATOR_APP  "org.tizen.keyguard"
+#define NOTIFICATION_SUB_ICON_PATH  ICON_PATH "/notification_sub_icon.png"
+
+namespace Krate {
+
+namespace {
+
+const std::vector<std::string> defaultGroups = {
+       "audio",
+       "video",
+       "display",
+       "log"
+};
+
+const std::vector<std::string> unitsToMask = {
+       "starter.service",
+       "scim.service"
+};
+
+const std::string KRATE_SKEL_PATH = "/etc/skel";
+const std::string KRATE_CREATE_HOOK_PATH = "/etc/gumd/useradd.d";
+const std::string KRATE_REMOVE_HOOK_PATH = "/etc/gumd/userdel.d";
+
+const std::string KRATE_DEFAULT_OWNER = "owner";
+
+const std::string KRATE_GROUP = "users";
+
+std::list<std::string> createdKrateList;
+static std::atomic<bool> isKrateForeground(false);
+
+std::unordered_map<int, notification_h> notiHandleMap;
+
+inline void maskUserServices(const runtime::User& user)
+{
+       ::tzplatform_set_user(user.getUid());
+       std::string pivot(::tzplatform_getenv(TZ_USER_HOME));
+       ::tzplatform_reset_user();
+
+       runtime::File unitbase(pivot + "/.config/systemd/user");
+       unitbase.makeDirectory(true);
+       unitbase.chmod(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+
+       for (const std::string& unit : unitsToMask) {
+               std::string target = unitbase.getPath() + "/" + unit;
+               if (::symlink("/dev/null", target.c_str()) == -1) {
+                       throw runtime::Exception(runtime::GetSystemErrorMessage());
+               }
+       }
+}
+
+inline void setKrateState(uid_t id, int state)
+{
+       dbus::Connection& systemDBus = dbus::Connection::getSystem();
+       systemDBus.methodcall("org.freedesktop.login1",
+                                                 "/org/freedesktop/login1",
+                                                 "org.freedesktop.login1.Manager",
+                                                 "SetUserLinger",
+                                                 -1, "", "(ubb)", id, state, 1);
+}
+
+inline const std::string convertPathForOwner(const std::string& path, const runtime::User& user, const runtime::User& owner)
+{
+       ::tzplatform_set_user(owner.getUid());
+       std::string ownerHome(::tzplatform_getenv(TZ_USER_HOME));
+       ::tzplatform_reset_user();
+       ownerHome += "/.krate";
+
+       ::tzplatform_set_user(user.getUid());
+       std::string userHome(::tzplatform_getenv(TZ_USER_HOME));
+       ::tzplatform_reset_user();
+
+       std::string userHomeForOwner(ownerHome + "/" + user.getName());
+
+       std::string convertedPath(path);
+
+       if (convertedPath.compare(0, userHome.size(), userHome) == 0) {
+               convertedPath.replace(0, userHome.size(), userHomeForOwner);
+       }
+
+       return convertedPath;
+}
+
+inline void prepareFileForOwner(const std::string path, const runtime::User& pkgUser, const runtime::User& owner)
+{
+       std::string pathLink = convertPathForOwner(path, pkgUser, owner);
+
+       if (path != pathLink) {
+               runtime::File linkFile(pathLink);
+               linkFile.makeBaseDirectory(pkgUser.getUid(), pkgUser.getGid());
+               if (linkFile.exists()) {
+                       linkFile.remove();
+               }
+
+               int ret = ::link(path.c_str(), pathLink.c_str());
+               if (ret != 0) {
+                       //TODO: copy the icon instead of linking
+                       throw runtime::Exception("Failed to link from " + path +
+                                                                        " to " + pathLink);
+               }
+       }
+}
+
+int packageEventHandler(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)
+{
+       static std::string type;
+       std::string keystr = key;
+
+       if (target_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
+               return 0;
+       }
+
+       std::transform(keystr.begin(), keystr.end(), keystr.begin(), ::tolower);
+       if (keystr == "start") {
+               type = val;
+               std::transform(type.begin(), type.end(), type.begin(), ::tolower);
+               return 0;
+       } else if (keystr != "end" && keystr != "ok") {
+               return 0;
+       }
+
+       try {
+               runtime::User owner(KRATE_DEFAULT_OWNER), pkgUser(target_uid);
+
+               if (type == "install" || type == "update") {
+                       PackageInfo pkg(pkgid, pkgUser.getUid());
+                       std::string icon = pkg.getIcon();
+                       prepareFileForOwner(icon, pkgUser, owner);
+
+                       for (const ApplicationInfo& app : pkg.getAppList()) {
+                               std::string icon = app.getIcon();
+                               prepareFileForOwner(icon, pkgUser, owner);
+                       }
+               } else {
+                       ::tzplatform_set_user(pkgUser.getUid());
+                       std::string pkgPath(::tzplatform_getenv(TZ_USER_APP));
+                       pkgPath = pkgPath + "/" + pkgid;
+                       ::tzplatform_reset_user();
+
+                       runtime::File pkgDirForOwner(convertPathForOwner(pkgPath, pkgUser, owner));
+                       pkgDirForOwner.remove(true);
+               }
+       } catch (runtime::Exception &e) {
+               ERROR(e.what());
+       }
+
+       return 0;
+}
+
+void initializeCreatedKrateList() {
+       try {
+               runtime::DirectoryIterator iter(CONF_PATH "/"), end;
+
+               while (iter != end) {
+                       const std::string& file = iter->getName();
+                       const std::string& name(file.substr(0, file.rfind(".xml")));
+                       createdKrateList.push_back(name);
+                       ++iter;
+               }
+       } catch (runtime::Exception& e) {}
+}
+
+#define NT_TITLE     NOTIFICATION_TEXT_TYPE_TITLE
+#define NT_CONTENT   NOTIFICATION_TEXT_TYPE_CONTENT
+#define NT_ICON      NOTIFICATION_IMAGE_TYPE_ICON
+#define NT_INDICATOR NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR
+#define NT_NONE      NOTIFICATION_VARIABLE_TYPE_NONE
+#define NT_EVENT     NOTIFICATION_LY_ONGOING_PROGRESS
+#define NT_APP       NOTIFICATION_DISPLAY_APP_INDICATOR
+
+#define NT_ICON_PATH ICON_PATH "/indicator_icon.png"
+#define NT_TEXT      "Container Mode"
+#define NT_APPINFO   "Krate Application"
+
+#define NT_ERROR_NONE   NOTIFICATION_ERROR_NONE
+
+void krateProcessCallback(GDBusConnection *connection,
+                                                const gchar *sender, const gchar *objectPath,
+                                                const gchar *interface, const gchar *signalName,
+                                                GVariant *params, gpointer userData)
+{
+       static runtime::User owner(KRATE_DEFAULT_OWNER);
+       int pid, status;
+
+//     notification_h noti = reinterpret_cast<notification_h>(userData);
+
+       g_variant_get(params, "(ii)", &status, &pid);
+
+       if (status != 5) {
+               return;
+       }
+
+       struct stat st;
+       std::string proc("/proc/" + std::to_string(pid));
+       if (::stat(proc.c_str(), &st) != 0) {
+               return;
+       }
+
+       // this will have been commented until notification_delete_for_uid can work
+       /*
+       if (owner.getUid() != st.st_uid) {
+               if (!isKrateForeground) {
+                       notification_set_text(noti, NT_CONTENT, NT_APPINFO, NULL, NT_NONE);
+                       notification_post_for_uid(noti, owner.getUid());
+                       isKrateForeground = true;
+               }
+       } else {
+               if (isKrateForeground) {
+                       notification_delete_for_uid(noti, owner.getUid());
+                       isKrateForeground = false;
+               }
+       }*/
+}
+
+notification_h createNotification()
+{
+       notification_h noti = notification_create(NOTIFICATION_TYPE_ONGOING);
+       if (noti == NULL) {
+               return NULL;
+       }
+
+       if (notification_set_text(noti, NT_TITLE, NT_TEXT, NULL, NT_NONE) != NT_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+       if (notification_set_image(noti, NT_ICON, NT_ICON_PATH) != NT_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       if (notification_set_image(noti, NT_INDICATOR, NT_ICON_PATH) != NT_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       if (notification_set_layout(noti, NT_EVENT) != NT_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       if (notification_set_display_applist(noti, NT_APP) != NT_ERROR_NONE) {
+               notification_free(noti);
+               return NULL;
+       }
+
+       return noti;
+}
+
+void krateProcessMonitor()
+{
+       GError *error = NULL;
+       GDBusConnection* connection;
+       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (connection == NULL) {
+               ERROR("GBus Connection failed");
+               g_error_free(error);
+               return;
+       }
+
+       notification_h noti = createNotification();
+       if (noti == NULL) {
+               ERROR("Failed to created notification");
+               return;
+       }
+
+       g_dbus_connection_signal_subscribe(connection,
+                                                                               NULL,
+                                                                               "org.tizen.resourced.process",
+                                                                               "ProcStatus",
+                                                                               "/Org/Tizen/ResourceD/Process",
+                                                                               NULL,
+                                                                               G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                               krateProcessCallback,
+                                                                               reinterpret_cast<gpointer>(noti),
+                                                                               NULL);
+}
+
+void notiProxyInsert(const runtime::User& owner, const runtime::User& user, int privId, notification_h noti)
+{
+       std::string krateLauncherUri;
+       notification_h newNoti;
+       app_control_h appControl;
+       char* pkgId;
+
+       notification_clone(noti, &newNoti);
+
+       notification_get_pkgname(noti, &pkgId);
+       PackageInfo pkg(pkgId, user.getUid());
+       notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON, pkg.getIcon().c_str());
+       notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, NOTIFICATION_SUB_ICON_PATH);
+
+       notification_get_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, (void *)&appControl);
+       if (appControl != NULL) {
+               char* appId = NULL, *uri = NULL;
+
+               app_control_get_app_id(appControl, &appId);
+               if (appId == NULL) {
+                       appId = strdup("");
+               }
+
+               krateLauncherUri = "krate://enter/" + user.getName() + "/" + appId;
+
+               app_control_get_uri(appControl, &uri);
+               if (uri != NULL) {
+                       krateLauncherUri += "?uri=";
+                       krateLauncherUri +=  uri;
+                       free(uri);
+               }
+
+               free(appId);
+               app_control_set_app_id(appControl, KRATE_DELEGATOR_APP);
+               app_control_set_uri(appControl, krateLauncherUri.c_str());
+               notification_set_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, appControl);
+       }
+
+       notification_post_for_uid(newNoti, owner.getUid());
+       notiHandleMap.insert(std::make_pair(privId, newNoti));
+}
+
+void notiProxyDelete(const runtime::User& owner, int privId)
+{
+       std::unordered_map<int, notification_h>::iterator it;
+
+       it = notiHandleMap.find(privId);
+       if (it == notiHandleMap.end()) {
+               return;
+       }
+       notification_delete_for_uid(it->second, owner.getUid());
+       notification_free(it->second);
+       notiHandleMap.erase(it);
+}
+
+void notiProxyUpdate(const runtime::User& owner, const runtime::User& user, int privId, notification_h noti) {
+       std::unordered_map<int, notification_h>::iterator it;
+       double progress;
+       char *str;
+
+       it = notiHandleMap.find(privId);
+       if (it == notiHandleMap.end()) {
+               return;
+       }
+
+       notification_image_type_e imageTypes[] = {
+               NOTIFICATION_IMAGE_TYPE_ICON,
+               NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
+               NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK,
+               NOTIFICATION_IMAGE_TYPE_THUMBNAIL,
+               NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK,
+               NOTIFICATION_IMAGE_TYPE_ICON_SUB,
+               NOTIFICATION_IMAGE_TYPE_BACKGROUND,
+               NOTIFICATION_IMAGE_TYPE_LIST_1,
+               NOTIFICATION_IMAGE_TYPE_LIST_2,
+               NOTIFICATION_IMAGE_TYPE_LIST_3,
+               NOTIFICATION_IMAGE_TYPE_LIST_4,
+               NOTIFICATION_IMAGE_TYPE_LIST_5,
+               NOTIFICATION_IMAGE_TYPE_BUTTON_1,
+               NOTIFICATION_IMAGE_TYPE_BUTTON_2,
+               NOTIFICATION_IMAGE_TYPE_BUTTON_3,
+               NOTIFICATION_IMAGE_TYPE_BUTTON_4,
+               NOTIFICATION_IMAGE_TYPE_BUTTON_5,
+               NOTIFICATION_IMAGE_TYPE_BUTTON_6
+       };
+
+       for (notification_image_type_e type : imageTypes) {
+               notification_get_image(noti, type, &str);
+               notification_set_image(it->second, type, str);
+       }
+
+       notification_text_type_e textTypes[] = {
+               NOTIFICATION_TEXT_TYPE_TITLE,
+               NOTIFICATION_TEXT_TYPE_CONTENT,
+               NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
+               NOTIFICATION_TEXT_TYPE_EVENT_COUNT,
+               NOTIFICATION_TEXT_TYPE_INFO_1,
+               NOTIFICATION_TEXT_TYPE_INFO_SUB_1,
+               NOTIFICATION_TEXT_TYPE_INFO_2,
+               NOTIFICATION_TEXT_TYPE_INFO_SUB_2,
+               NOTIFICATION_TEXT_TYPE_INFO_3,
+               NOTIFICATION_TEXT_TYPE_INFO_SUB_3,
+               NOTIFICATION_TEXT_TYPE_GROUP_TITLE,
+               NOTIFICATION_TEXT_TYPE_GROUP_CONTENT,
+               NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
+               NOTIFICATION_TEXT_TYPE_BUTTON_1,
+               NOTIFICATION_TEXT_TYPE_BUTTON_2,
+               NOTIFICATION_TEXT_TYPE_BUTTON_3,
+               NOTIFICATION_TEXT_TYPE_BUTTON_4,
+               NOTIFICATION_TEXT_TYPE_BUTTON_5,
+               NOTIFICATION_TEXT_TYPE_BUTTON_6,
+       };
+
+       for (notification_text_type_e type : textTypes) {
+               notification_get_text(noti, type, &str);
+               notification_set_text(it->second, type, str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       }
+
+       notification_get_size(noti, &progress);
+       notification_set_size(it->second, progress);
+
+       notification_get_progress(noti, &progress);
+       notification_set_progress(it->second, progress);
+
+       notification_update_for_uid(it->second, owner.getUid());
+}
+
+void notiProxyCallback(void *data, notification_type_e type, notification_op *op_list, int num_op)
+{
+       static runtime::User owner(KRATE_DEFAULT_OWNER);
+       runtime::User user(*reinterpret_cast<std::string*>(data));
+
+       if (user.getName() == owner.getName()) {
+               // TODO : should remove noti in the krate when related-krate is removed
+               //        This will be imlemented when notification bug is fixed
+               return;
+    }
+
+       for (int i = 0; i < num_op; i++) {
+               notification_h noti = NULL;
+               int opType, privId;
+
+               notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_TYPE, &opType);
+               notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_PRIV_ID, &privId);
+
+               switch (opType) {
+               case NOTIFICATION_OP_INSERT:
+                       notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_NOTI, &noti);
+                       notiProxyInsert(owner, user, privId, noti);
+                       break;
+               case NOTIFICATION_OP_DELETE:
+                       notiProxyDelete(owner, privId);
+                       break;
+               case NOTIFICATION_OP_UPDATE:
+                       notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_NOTI, &noti);
+                       notiProxyUpdate(owner, user, privId, noti);
+                       break;
+               }
+       }
+}
+
+} // namespace
+
+Manager::Manager(KrateControlContext& ctx) :
+       context(ctx)
+{
+       context.registerParametricMethod(this, "", (int)(Manager::createKrate)(std::string, std::string));
+       context.registerParametricMethod(this, "", (int)(Manager::removeKrate)(std::string));
+       context.registerParametricMethod(this, "", (int)(Manager::lockKrate)(std::string));
+       context.registerParametricMethod(this, "", (int)(Manager::unlockKrate)(std::string));
+       context.registerParametricMethod(this, "", (int)(Manager::getKrateState)(std::string));
+       context.registerParametricMethod(this, "", (std::vector<std::string>)(Manager::getKrateList)(int));
+       context.registerParametricMethod(this, "", (int)(Manager::resetKratePassword)(std::string, std::string));
+
+       context.createNotification("Manager::created");
+       context.createNotification("Manager::removed");
+
+       PackageManager& packageManager = PackageManager::instance();
+       packageManager.setEventCallback(packageEventHandler, this);
+
+       krateProcessMonitor();
+
+       initializeCreatedKrateList();
+       for (std::string& name : createdKrateList) {
+               runtime::User krate(name);
+               notification_register_detailed_changed_cb_for_uid(notiProxyCallback, &name, krate.getUid());
+       }
+}
+
+Manager::~Manager()
+{
+}
+
+int Manager::createKrate(const std::string& name, const std::string& manifest)
+{
+       auto provisioningWorker = [name, manifest, this]() {
+               std::unique_ptr<xml::Document> manifestFile;
+
+               try {
+                       //create krate user by gumd
+                       GumUser* guser = NULL;
+                       while (guser == NULL) {
+                               guser = gum_user_create_sync(FALSE);
+                       }
+                       g_object_set(G_OBJECT(guser), "username", name.c_str(),
+                                                       "usertype", GUM_USERTYPE_SECURITY, NULL);
+                       gboolean ret = gum_user_add_sync(guser);
+                       g_object_unref(guser);
+
+                       if (!ret) {
+                               throw runtime::Exception("Failed to remove user (" + name + ") by gumd");
+                       }
+
+                       runtime::User user(name);
+
+                       maskUserServices(user);
+
+                       manifestFile.reset(xml::Parser::parseString(manifest));
+                       manifestFile->write(CONF_PATH "/" + name + ".xml", "UTF-8", true);
+
+                       //TODO: write container owner info
+
+                       //unlock the user
+                       setKrateState(user.getUid(), 1);
+
+                       //wait for launchpad in the krate
+                       sleep(1);
+
+                       auto it = createdKrateList.insert(createdKrateList.end(), name);
+                       notification_register_detailed_changed_cb_for_uid(notiProxyCallback, &(*it), user.getUid());
+                       context.notify("Manager::created", name, "");
+               } catch (runtime::Exception& e) {
+                       ERROR(e.what());
+                       context.notify("Manager::created", name, "Error");
+               }
+       };
+
+       std::thread asyncWork(provisioningWorker);
+       asyncWork.detach();
+
+       return 0;
+}
+
+int Manager::removeKrate(const std::string& name)
+{
+       if (lockKrate(name) != 0) {
+               return -1;
+       }
+
+       auto remove = [name, this] {
+               //wait for krate session close
+               sleep(1);
+
+               try {
+                       runtime::User user(name);
+
+               //umount TZ_USER_CONTENT
+                       ::tzplatform_set_user(user.getUid());
+                       ::umount2(::tzplatform_getenv(TZ_USER_CONTENT), MNT_FORCE);
+                       ::tzplatform_reset_user();
+
+                       //remove krate user
+                       GumUser* guser = NULL;
+                       while (guser == NULL) {
+                               guser = gum_user_get_sync(user.getUid(), FALSE);
+                       }
+                       gboolean ret = gum_user_delete_sync(guser, TRUE);
+                       g_object_unref(guser);
+
+                       if (!ret) {
+                               throw runtime::Exception("Failed to remove user " + name + "(" + std::to_string(user.getUid()) + ") by gumd");
+                       }
+
+                       auto it = createdKrateList.begin();
+                       for (; it != createdKrateList.end(); it++) {
+                               if (*it == name) {
+                                       break;
+                               }
+                       }
+                       createdKrateList.erase(it);
+
+                       notification_unregister_detailed_changed_cb_for_uid(notiProxyCallback, NULL, user.getUid());
+                       context.notify("Manager::removed", name, "");
+               } catch (runtime::Exception& e) {
+                       ERROR(e.what());
+                       context.notify("Manager::removed", name, "Error");
+                       return;
+               }
+       };
+
+       std::thread asyncWork(remove);
+       asyncWork.detach();
+
+       return 0;
+}
+
+int Manager::lockKrate(const std::string& name)
+{
+       try {
+               runtime::User user(name);
+               setKrateState(user.getUid(), 0);
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
+               return -1;
+       }
+
+       return 0;
+}
+
+int Manager::unlockKrate(const std::string& name)
+{
+       try {
+               runtime::User user(name);
+               setKrateState(user.getUid(), 1);
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
+               return -1;
+       }
+
+       return 0;
+}
+
+int Manager::getKrateState(const std::string& name)
+{
+       auto it = std::find(createdKrateList.begin(), createdKrateList.end(), name);
+       if (it == createdKrateList.end()) {
+               return 0;
+       }
+
+       try {
+               runtime::User user(name);
+               try {
+                       dbus::Connection& systemDBus = dbus::Connection::getSystem();
+                       const dbus::Variant& var = systemDBus.methodcall
+                                                                                  ("org.freedesktop.login1",
+                                                                                       "/org/freedesktop/login1",
+                                                                                       "org.freedesktop.login1.Manager",
+                                                                                       "GetUser",
+                                                                                       -1, "(o)", "(u)", user.getUid());
+                       return Manager::State::Running;
+               } catch (runtime::Exception& e) {
+                       return Manager::State::Locked;
+               }
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
+               return 0;
+       }
+
+       return 0;
+}
+
+std::vector<std::string> Manager::getKrateList(int state)
+{
+       std::vector<std::string> list;
+
+       for (const std::string& name : createdKrateList) {
+               if (getKrateState(name) & state) {
+                       list.push_back(name);
+               }
+       }
+       return list;
+}
+
+int Manager::resetKratePassword(const std::string& name, const std::string& newPassword)
+{
+       try {
+               runtime::User user(name);
+               int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, user.getUid(), newPassword.c_str());
+               if (ret != AUTH_PASSWD_API_SUCCESS) {
+                       throw runtime::Exception("Failed to reset password for " + name);
+               }
+       } catch (runtime::Exception& e) {
+               ERROR(e.what());
+               return -1;
+       }
+
+       return 0;
+}
+
+} // namespace Krate
diff --git a/server/package-proxy.cpp b/server/package-proxy.cpp
new file mode 100644 (file)
index 0000000..44513d4
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <system_settings.h>
+#include <klay/auth/user.h>
+#include <klay/audit/logger.h>
+
+#include "packman.h"
+
+#include "rmi/package-proxy.h"
+
+namespace Krate {
+
+PackageProxy::PackageProxy(KrateControlContext& ctx) :
+       context(ctx)
+{
+       context.registerParametricMethod(this, "", (PackageProxy::PackageInfo)(PackageProxy::getPackageInfo)(std::string, std::string));
+       context.registerParametricMethod(this, "", (std::vector<std::string>)(PackageProxy::getPackageList)(std::string));
+
+       context.registerParametricMethod(this, "", (int)(PackageProxy::install)(std::string, std::string));
+       context.registerParametricMethod(this, "", (int)(PackageProxy::uninstall)(std::string, std::string));
+}
+
+PackageProxy::~PackageProxy()
+{
+}
+
+PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, const std::string& pkgid)
+{
+       PackageProxy::PackageInfo package;
+       char* locale = NULL;
+
+       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
+       if (locale == NULL) {
+               locale = strdup("No locale");
+       }
+
+       package.krate = name;
+       package.id = pkgid;
+       package.locale = locale;
+
+       free(locale);
+
+       try {
+               runtime::User user(name);
+               ::PackageInfo pkginfo(pkgid, user.getUid());
+
+               package.type = pkginfo.getType();
+               package.icon = pkginfo.getIcon();
+               package.label = pkginfo.getLabel();
+               package.description = pkginfo.getDescription();
+
+               package.author.name = pkginfo.getAuthorName();
+               package.author.email = pkginfo.getAuthorEmail();
+               package.author.href = pkginfo.getAuthorHref();
+
+               package.version = pkginfo.getVersion();
+               package.apiVersion = pkginfo.getApiVersion();
+               package.mainAppId = pkginfo.getMainAppId();
+
+               package.isSystem = pkginfo.isSystem();
+               package.isRemovable = pkginfo.isRemovable();
+               package.isPreload = pkginfo.isPreload();
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to retrieve package info installed in the krate");
+       }
+
+       return package;
+}
+
+std::vector<std::string> PackageProxy::getPackageList(const std::string& name)
+{
+       try {
+               runtime::User user(name);
+               PackageManager& packman = PackageManager::instance();
+               return packman.getPackageList(user.getUid());
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to retrieve package info installed in the krate");
+       }
+       return std::vector<std::string>();
+}
+
+
+int PackageProxy::install(const std::string& name, const std::string& pkgpath)
+{
+       try {
+               runtime::User user(name);
+               PackageManager& packman = PackageManager::instance();
+               packman.installPackage(pkgpath, user.getUid());
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to install package in the krate");
+               return -1;
+       }
+
+       return 0;
+}
+
+int PackageProxy::uninstall(const std::string& name, const std::string& pkgid)
+{
+       try {
+               runtime::User user(name);
+               PackageManager& packman = PackageManager::instance();
+               packman.uninstallPackage(pkgid, user.getUid());
+       } catch (runtime::Exception& e) {
+               ERROR("Failed to uninstall package of pkgid in the krate");
+               return -1;
+       }
+       return 0;
+}
+
+} // namespace Krate
diff --git a/server/packman.cpp b/server/packman.cpp
new file mode 100644 (file)
index 0000000..8739dce
--- /dev/null
@@ -0,0 +1,427 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include <klay/exception.h>
+#include <klay/audit/logger.h>
+
+#include "packman.h"
+
+namespace {
+
+int PackageEventCallback(uid_t uid, int id, const char* type, const char* name,
+                                                const char* key, const char* val, const void* msg, void* data)
+{
+       return 0;
+}
+
+int AppListCallback(pkgmgrinfo_appinfo_h handle, void *data)
+{
+       std::vector<ApplicationInfo>* appList = static_cast<std::vector<ApplicationInfo>*>(data);
+       appList->push_back(ApplicationInfo(handle));
+
+       return 0;
+}
+
+int PackageListCallback(pkgmgrinfo_pkginfo_h handle, void *data)
+{
+       char* pkgid = nullptr;
+       ::pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+
+       std::vector<std::string>* packageList = static_cast<std::vector<std::string>*>(data);
+       packageList->push_back(pkgid);
+
+       return 0;
+}
+
+} // namespace
+
+PackageInfo::PackageInfo(const std::string& pkgid, uid_t uid) :
+       user(uid), handle(nullptr)
+{
+       if (uid == 0) {
+               uid = getuid();
+       }
+
+       if (::pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), user, &handle) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid Package Id");
+       }
+}
+
+PackageInfo::~PackageInfo()
+{
+       ::pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+}
+
+std::vector<ApplicationInfo> PackageInfo::getAppList() const
+{
+       std::vector<ApplicationInfo> appList;
+
+       if (::pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, AppListCallback, &appList, user) != PMINFO_R_OK) {
+               ERROR("Error in pkgmgrinfo_appinfo_get_usr_list");
+       }
+
+       return appList;
+}
+
+std::string PackageInfo::getType() const
+{
+       char *pkgtype;
+       if (::pkgmgrinfo_pkginfo_get_type(handle, &pkgtype) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return pkgtype;
+}
+
+std::string PackageInfo::getLabel() const
+{
+       char *label;
+       if (::pkgmgrinfo_pkginfo_get_label(handle, &label) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return label;
+}
+
+std::string PackageInfo::getIcon() const
+{
+       char *icon;
+       if (::pkgmgrinfo_pkginfo_get_icon(handle, &icon) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return icon;
+}
+
+std::string PackageInfo::getDescription() const
+{
+       char *desc;
+       if (::pkgmgrinfo_pkginfo_get_description(handle, &desc) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return desc;
+}
+
+std::string PackageInfo::getAuthorName() const
+{
+       char *name;
+       if (::pkgmgrinfo_pkginfo_get_author_name(handle, &name) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return name;
+}
+
+std::string PackageInfo::getAuthorEmail() const
+{
+       char *email;
+       if (::pkgmgrinfo_pkginfo_get_author_email(handle, &email) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return email;
+}
+
+std::string PackageInfo::getAuthorHref() const
+{
+       char *href;
+       if (::pkgmgrinfo_pkginfo_get_author_name(handle, &href) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return href;
+}
+
+std::string PackageInfo::getVersion() const
+{
+       char *version;
+       if (::pkgmgrinfo_pkginfo_get_version(handle, &version) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return version;
+}
+
+std::string PackageInfo::getApiVersion() const
+{
+       char *api;
+       if (::pkgmgrinfo_pkginfo_get_api_version(handle, &api) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return api;
+}
+
+std::string PackageInfo::getMainAppId() const
+{
+       char *mainappid;
+       if (::pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return mainappid;
+}
+
+bool PackageInfo::isSystem() const
+{
+       bool ret;
+       if (::pkgmgrinfo_pkginfo_is_system(handle, &ret) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return ret;
+}
+
+bool PackageInfo::isRemovable() const
+{
+       bool ret;
+       if (::pkgmgrinfo_pkginfo_is_removable(handle, &ret) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return ret;
+}
+
+bool PackageInfo::isPreload() const
+{
+       bool ret;
+       if (::pkgmgrinfo_pkginfo_is_preload(handle, &ret) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid operation");
+       }
+
+       return ret;
+}
+
+ApplicationInfo::ApplicationInfo(const std::string& aid, uid_t uid)
+{
+       pkgmgrinfo_appinfo_h handle;
+
+       if (::pkgmgrinfo_appinfo_get_usr_appinfo(aid.c_str(), uid, &handle) != PMINFO_R_OK) {
+               throw runtime::Exception("Invalid App Id");
+       }
+
+       load(handle);
+
+       ::pkgmgrinfo_appinfo_destroy_appinfo(handle);
+}
+
+ApplicationInfo::ApplicationInfo(pkgmgrinfo_appinfo_h handle)
+{
+       load(handle);
+}
+
+
+ApplicationInfo::~ApplicationInfo()
+{
+}
+
+void ApplicationInfo::load(pkgmgrinfo_appinfo_h handle) {
+       pkgmgrinfo_app_component comp;
+       char* str;
+       int ret;
+
+       ret = ::pkgmgrinfo_appinfo_get_appid(handle, &str);
+       if (ret == PMINFO_R_OK) {
+               id = str;
+       }
+
+       ret = ::pkgmgrinfo_appinfo_get_pkgid(handle, &str);
+       if (ret == PMINFO_R_OK) {
+               package = str;
+       }
+
+       ret = ::pkgmgrinfo_appinfo_get_apptype(handle, &str);
+       if (ret == PMINFO_R_OK) {
+               type = str;
+       }
+
+       ret = ::pkgmgrinfo_appinfo_get_icon(handle, &str);
+       if (ret == PMINFO_R_OK) {
+               icon = str;
+       }
+
+       ret = ::pkgmgrinfo_appinfo_get_label(handle, &str);
+       if (ret == PMINFO_R_OK) {
+               label = str;
+       }
+
+       ret = ::pkgmgrinfo_appinfo_get_component(handle, &comp);
+       if (ret == PMINFO_R_OK) {
+               componentType = static_cast<int>(comp);
+       }
+
+       ::pkgmgrinfo_appinfo_is_nodisplay(handle, &noDisplayed);
+       ::pkgmgrinfo_appinfo_is_taskmanage(handle, &taskManaged);
+}
+
+const std::string& ApplicationInfo::getId() const
+{
+       return id;
+}
+
+const std::string& ApplicationInfo::getPackage() const
+{
+       return package;
+}
+
+const std::string& ApplicationInfo::getType() const
+{
+       return type;
+}
+
+const std::string& ApplicationInfo::getIcon() const
+{
+       return icon;
+}
+
+const std::string& ApplicationInfo::getLabel() const
+{
+       return label;
+}
+
+int ApplicationInfo::getComponentType() const
+{
+       return componentType;
+}
+
+bool ApplicationInfo::isNoDisplayed() const
+{
+       return noDisplayed;
+}
+
+bool ApplicationInfo::isTaskManaged() const
+{
+       return taskManaged;
+}
+
+PackageManager::PackageManager() :
+       nativeRequestHandle(nullptr), nativeListenHandle(nullptr)
+{
+       nativeRequestHandle = ::pkgmgr_client_new(PC_REQUEST);
+       if (nativeRequestHandle == nullptr) {
+               throw runtime::Exception("No package manager request instance");
+       }
+
+       nativeListenHandle = ::pkgmgr_client_new(PC_LISTENING);
+       if (nativeListenHandle == nullptr) {
+               ::pkgmgr_client_free(nativeRequestHandle);
+               throw runtime::Exception("No package manager listening instance");
+       }
+}
+
+PackageManager::~PackageManager()
+{
+       ::pkgmgr_client_free(nativeRequestHandle);
+       ::pkgmgr_client_free(nativeListenHandle);
+}
+
+PackageManager& PackageManager::instance()
+{
+       static PackageManager __instance__;
+       return __instance__;
+}
+
+void PackageManager::setEventCallback(pkgmgrinfo_handler callback, void* user_data)
+{
+       int ret;
+       ret = ::pkgmgr_client_listen_status(nativeListenHandle, callback, user_data);
+       if (ret < 0) {
+               throw runtime::Exception("Failed to set package event callback");
+       }
+}
+
+void PackageManager::unsetEventCallback()
+{
+       int ret;
+       ret = ::pkgmgr_client_remove_listen_status(nativeListenHandle);
+       if (ret < 0) {
+               throw runtime::Exception("Failed to unset package event callback");
+       }
+}
+
+void PackageManager::installPackage(const std::string& pkgpath, const uid_t user)
+{
+       int ret = ::pkgmgr_client_usr_install(nativeRequestHandle, NULL, NULL, pkgpath.c_str(), NULL, PM_QUIET, PackageEventCallback, nullptr, user);
+       if (ret < PKGMGR_R_OK) {
+               throw runtime::Exception("Package installation failed");
+       }
+}
+
+void PackageManager::uninstallPackage(const std::string& pkgid, const uid_t user)
+{
+       std::string pkgtype;
+
+       PackageInfo pkgInfo(pkgid, user);
+       pkgtype = pkgInfo.getType();
+
+       int ret = ::pkgmgr_client_usr_uninstall(nativeRequestHandle, pkgtype.c_str(), pkgid.c_str(), PM_QUIET, PackageEventCallback, nullptr, user);
+       if (ret < PKGMGR_R_OK) {
+               ERROR("Error in pkgmgr_client_uninstall");
+               throw runtime::Exception("Package manager exception");
+       }
+}
+
+std::vector<std::string> PackageManager::getPackageList(const uid_t user)
+{
+       std::vector<std::string> packageList;
+
+       if (::pkgmgrinfo_pkginfo_get_usr_list(PackageListCallback, &packageList, user) != PMINFO_R_OK) {
+               ERROR("Error in pkgmgrinfo_pkginfo_get_list");
+       }
+
+       return packageList;
+}
+
+std::vector<ApplicationInfo> PackageManager::getAppList(const uid_t user)
+{
+       std::vector<ApplicationInfo> appList;
+
+       if (::pkgmgrinfo_appinfo_get_usr_installed_list(AppListCallback, user, &appList) != PMINFO_R_OK) {
+               ERROR("Error in pkgmgrinfo_appinfo_get_installed_list");
+       }
+
+       return appList;
+}
+
+void PackageManager::setModeRestriction(int mode, uid_t user)
+{
+       if (::pkgmgr_client_usr_set_restriction_mode(nativeRequestHandle,
+                                                                                                mode,
+                                                                                                user) != PKGMGR_R_OK) {
+               throw runtime::Exception("Failed to set package restriction mode");
+       }
+}
+
+void PackageManager::unsetModeRestriction(int mode, uid_t user)
+{
+       if (::pkgmgr_client_usr_unset_restriction_mode(nativeRequestHandle,
+                                                                                                  mode,
+                                                                                                  user) != PKGMGR_R_OK) {
+               throw runtime::Exception("Failed to unset package mode restriction");
+       }
+}
+
+int PackageManager::getModeRestriction(uid_t user)
+{
+       int mode;
+       if (::pkgmgr_client_usr_get_restriction_mode(nativeRequestHandle,
+                                                                                                &mode,
+                                                                                                user) != PKGMGR_R_OK) {
+               throw runtime::Exception("Failed to get package restriction mode");
+       }
+
+       return mode;
+}
diff --git a/server/packman.h b/server/packman.h
new file mode 100644 (file)
index 0000000..0609538
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __PACKMAN_H__
+#define __PACKMAN_H__
+
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <string>
+#include <vector>
+
+#include <package-manager.h>
+#include <pkgmgr-info.h>
+
+class ApplicationInfo {
+public:
+       ApplicationInfo(const std::string& aid, uid_t uid = 0);
+       ApplicationInfo(pkgmgrinfo_appinfo_h handle);
+       ~ApplicationInfo();
+
+       const std::string& getId() const;
+       const std::string& getPackage() const;
+       const std::string& getType() const;
+       const std::string& getIcon() const;
+       const std::string& getLabel() const;
+       int getComponentType() const;
+       bool isNoDisplayed() const;
+       bool isTaskManaged() const;
+
+private:
+       void load(pkgmgrinfo_appinfo_h handle);
+
+       std::string id;
+       std::string package;
+       std::string type;
+       std::string icon;
+       std::string label;
+       int componentType;
+       bool noDisplayed;
+       bool taskManaged;
+};
+
+class PackageInfo {
+public:
+       PackageInfo(const std::string& pkgid, uid_t uid = 0);
+       ~PackageInfo();
+
+       std::vector<ApplicationInfo> getAppList() const;
+
+       std::string getType() const;
+       std::string getIcon() const;
+       std::string getLabel() const;
+       std::string getDescription() const;
+
+       std::string getAuthorName() const;
+       std::string getAuthorEmail() const;
+       std::string getAuthorHref() const;
+
+       std::string getVersion() const;
+       std::string getApiVersion() const;
+       std::string getMainAppId() const;
+
+       bool isSystem() const;
+       bool isRemovable() const;
+       bool isPreload() const;
+
+private:
+       uid_t user;
+       pkgmgrinfo_pkginfo_h handle;
+};
+
+class PackageManager {
+public:
+       void installPackage(const std::string& pkgpath, const uid_t user);
+       void uninstallPackage(const std::string& pkgid, const uid_t user);
+
+       std::vector<std::string> getPackageList(const uid_t user);
+       std::vector<ApplicationInfo> getAppList(const uid_t user);
+
+       void setEventCallback(pkgmgrinfo_handler callback, void* user_data);
+       void unsetEventCallback();
+
+       void setModeRestriction(int mode, uid_t user);
+       void unsetModeRestriction(int mode, uid_t user);
+       int getModeRestriction(uid_t user);
+
+       void setPackageRestriction(const std::string& pkgid, int mode, uid_t user);
+       void unsetPackageRestriction(const std::string& pkgid, int mode, uid_t user);
+       int getPackageRestriction(const std::string& pkgid, uid_t user);
+
+       static PackageManager& instance();
+
+private:
+       PackageManager();
+       ~PackageManager();
+
+private:
+       pkgmgr_client *nativeRequestHandle, *nativeListenHandle;
+};
+
+#endif // __PACKMAN_H__
diff --git a/server/server.cpp b/server/server.cpp
new file mode 100644 (file)
index 0000000..4db963d
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+#include <functional>
+
+#include <cynara-client.h>
+#include <cynara-session.h>
+
+#include "server.h"
+
+#include "rmi/manager.h"
+#include "rmi/app-proxy.h"
+#include "rmi/package-proxy.h"
+
+using namespace std::placeholders;
+
+namespace {
+
+const std::string KRATE_MANAGER_ADDRESS = "/tmp/.krate.sock";
+
+std::unique_ptr<Krate::Manager> manager;
+std::unique_ptr<Krate::AppProxy> appProxy;
+std::unique_ptr<Krate::PackageProxy> packageProxy;
+
+} // namespace
+
+Server::Server()
+{
+       service.reset(new rmi::Service(KRATE_MANAGER_ADDRESS));
+
+       service->setPrivilegeChecker(std::bind(&Server::checkPeerPrivilege, this, _1, _2));
+
+       service->registerParametricMethod(this, "", (runtime::FileDescriptor)(Server::registerNotificationSubscriber)(std::string));
+       service->registerParametricMethod(this, "", (int)(Server::unregisterNotificationSubscriber)(std::string, int));
+
+       manager.reset(new Krate::Manager(*this));
+       appProxy.reset(new Krate::AppProxy(*this));
+       packageProxy.reset(new Krate::PackageProxy(*this));
+}
+
+Server::~Server()
+{
+}
+
+void Server::run()
+{
+       // Prepare execution environment
+       service->start(true);
+}
+
+void Server::terminate()
+{
+       service->stop();
+}
+
+runtime::FileDescriptor Server::registerNotificationSubscriber(const std::string& name)
+{
+       return runtime::FileDescriptor(service->subscribeNotification(name), true);
+}
+
+int Server::unregisterNotificationSubscriber(const std::string& name, int id)
+{
+       return service->unsubscribeNotification(name, id);
+}
+
+bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege)
+{
+       cynara *p_cynara;
+
+       if (privilege.empty()) {
+               return true;
+       }
+
+       if (::cynara_initialize(&p_cynara, NULL) != CYNARA_API_SUCCESS) {
+               ERROR("Failure in cynara API");
+               return false;
+       }
+
+       if (::cynara_check(p_cynara, cred.security.c_str(), "",
+                                          std::to_string(cred.uid).c_str(),
+                                          privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) {
+               ::cynara_finish(p_cynara);
+               ERROR("Access denied: " + cred.security + " : " + privilege);
+               return false;
+       }
+
+       ::cynara_finish(p_cynara);
+
+       return true;
+}
diff --git a/server/server.h b/server/server.h
new file mode 100644 (file)
index 0000000..95bc9fc
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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
+ */
+
+#ifndef __KRATE_SERVER_H__
+#define __KRATE_SERVER_H__
+
+#include <string>
+#include <memory>
+
+#include <klay/filesystem.h>
+#include <klay/file-descriptor.h>
+#include <klay/rmi/service.h>
+
+class Server {
+public:
+       Server();
+       ~Server();
+
+       void run();
+       void terminate();
+
+       template<typename Type, typename... Args>
+       void setMethodHandler(const std::string& privilege, const std::string& method,
+                                                 const typename rmi::MethodHandler<Type, Args...>::type& handler)
+       {
+               service->setMethodHandler<Type, Args...>(privilege, method, handler);
+       }
+
+       template <typename... Args>
+       void notify(const std::string& name, Args&&... args)
+       {
+               service->notify<Args...>(name, std::forward<Args>(args)...);
+       }
+
+       uid_t getPeerUid() const
+       {
+               return service->getPeerUid();
+       }
+
+       gid_t getPeerGid() const
+       {
+               return service->getPeerGid();
+       }
+
+       pid_t getPeerPid() const
+       {
+               return service->getPeerPid();
+       }
+
+       void createNotification(const std::string& name)
+       {
+               service->createNotification(name);
+       }
+
+       runtime::FileDescriptor registerNotificationSubscriber(const std::string& name);
+       int unregisterNotificationSubscriber(const std::string& name, int id);
+
+       bool checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege);
+
+private:
+       std::string securityLabel;
+       std::unique_ptr<rmi::Service> service;
+};
+
+#endif //__KRATE_SERVER_H__
index 1e9d228..1680489 100644 (file)
@@ -1,11 +1,14 @@
 [Unit]
-Description=Krate
+Description=@PROJECT_NAME@ management daemon
 
 [Service]
 Type=simple
-ExecStart=${TZ_SYS_BIN}/krate
+SmackProcessLabel=System
+ExecStart=@BIN_DIR@/@PROJECT_NAME@d
 Restart=on-failure
 ExecReload=/bin/kill -HUP $MAINPID
+CapabilityBoundingSet=~CAP_MAC_ADMIN
+CapabilityBoundingSet=~CAP_MAC_OVERRIDE
 
 [Install]
 WantedBy=multi-user.target
index 2ce3d84..813d2e7 100755 (executable)
@@ -15,7 +15,7 @@
 #
 
 SET(KRATE_APPS  ${KRATE_TOOLS}/apps)
-#SET(KRATE_CLI  ${KRATE_TOOLS}/cli)
+SET(KRATE_CLI  ${KRATE_TOOLS}/cli)
 
 ADD_SUBDIRECTORY(${KRATE_APPS})
-#ADD_SUBDIRECTORY(${KRATE_CLI})
+ADD_SUBDIRECTORY(${KRATE_CLI})
index 8b1018c..42ca637 100644 (file)
@@ -150,7 +150,7 @@ static void __badge_changed_cb(unsigned int action, const char *app_id, unsigned
 }
 
 
-static char* __get_current_zone_name() {
+static char* __get_current_krate_name() {
        struct passwd pwd, *result;
        int bufsize;
 
@@ -192,9 +192,9 @@ void _icon_uninstalled_cb(const char *pkg_id)
 
 static void __show_launcher()
 {
-       char *zone_name = __get_current_zone_name();
+       char *krate_name = __get_current_krate_name();
 
-       _set_kaskit_window_title(zone_name);
+       _set_kaskit_window_title(krate_name);
 
        package_manager_set_event_status(__pkg_mgr,
                PACKAGE_MANAGER_STATUS_TYPE_INSTALL |
@@ -205,7 +205,7 @@ static void __show_launcher()
 
        ecore_thread_run(__create_icon_thread, NULL, NULL, NULL);
 
-       free(zone_name);
+       free(krate_name);
 }
 
 static bool __app_create(void *data)
index b6bf05a..5df7275 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index f60c758..b119716 100644 (file)
@@ -7,10 +7,9 @@ FIND_PACKAGE(PkgConfig REQUIRED)
 PKG_CHECK_MODULES(KEYGUARD REQUIRED
        auth-fw
        shortcut
-       zone
 )
 
-INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${KEYGUARD_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${KEYGUARD_INCLUDE_DIRS} ${KRATE_LIB})
 LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${KEYGUARD_LIBRARY_DIRS})
 
 SET(PROJECT_SRC src/main.c
@@ -23,7 +22,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
 ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_SRC})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin)
 
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${KEYGUARD_LIBRARIES})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${KEYGUARD_LIBRARIES} krate)
 
 ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj
         COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images
index 2ff94be..6ae44a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Keyguard application
+ * Tizen Krate Keyguard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -16,8 +16,8 @@
  * limitations under the License.
  *
  */
-#ifndef __ZONE_KEYGUARD_H__
-#define __ZONE_KEYGUARD_H__
+#ifndef __KRATE_KEYGUARD_H__
+#define __KRATE_KEYGUARD_H__
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,8 +31,8 @@
 #include <efl_extension.h>
 #include <shortcut_manager.h>
 #include <auth-passwd.h>
-#include <zone/zone.h>
-#include <zone/app-proxy.h>
+#include <krate/krate.h>
+#include <krate/app-proxy.h>
 
 #ifdef  LOG_TAG
 #undef  LOG_TAG
@@ -53,4 +53,4 @@ bool _has_password(void);
 bool _check_password(const char* password);
 unsigned int _get_left_attempts(void);
 
-#endif /* __ZONE_KEYGUARD_H__ */
+#endif /* __KRATE_KEYGUARD_H__ */
index 85496d9..4d6237b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Keyguard application
+ * Tizen Krate Keyguard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index dd82199..4fd6bf4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Keyguard Layout
+ * Tizen Krate Keyguard Layout
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index 48f4a5b..25b272c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Keyguard application
+ * Tizen Krate Keyguard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -60,24 +60,24 @@ unsigned int _get_left_attempts()
        return max_attempt - attempt;
 }
 
-static void __launch_zone_app(const char* zone_name, app_control_h app_control)
+static void __launch_krate_app(const char* krate_name, app_control_h app_control)
 {
-       zone_manager_h zone_mgr;
-       zone_app_proxy_h zone_app;
-
-       zone_manager_create(&zone_mgr);
-       zone_app_proxy_create(zone_mgr, zone_name, &zone_app);
-       zone_app_proxy_send_launch_request(zone_app, app_control);
-       zone_app_proxy_destroy(zone_app);
-       zone_manager_destroy(zone_mgr);
+       krate_manager_h krate_mgr;
+       krate_app_proxy_h krate_app;
+
+       krate_manager_create(&krate_mgr);
+       krate_app_proxy_create(krate_mgr, krate_name, &krate_app);
+       krate_app_proxy_send_launch_request(krate_app, app_control);
+       krate_app_proxy_destroy(krate_app);
+       krate_manager_destroy(krate_mgr);
 }
 
-static void __add_shortcut(const char* zone_name)
+static void __add_shortcut(const char* krate_name)
 {
        char uri[PATH_MAX];
 
-       snprintf(uri, sizeof(uri), "zone://enter/%s", zone_name);
-       shortcut_add_to_home(zone_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL);
+       snprintf(uri, sizeof(uri), "krate://enter/%s", krate_name);
+       shortcut_add_to_home(krate_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL);
 }
 
 static bool __app_create(void *data)
@@ -112,28 +112,28 @@ static void __app_control(app_control_h app_control, void *data)
                return;
        }
 
-       if (strncmp(uri, "zone://", sizeof("zone://") - 1) != 0) {
+       if (strncmp(uri, "krate://", sizeof("krate://") - 1) != 0) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Mismatched URI");
                free(uri);
                ui_app_exit();
                return;
        }
 
-       tmp = uri + sizeof("zone://") - 1;
+       tmp = uri + sizeof("krate://") - 1;
 
        if (strncmp(tmp, "setup/", sizeof("setup/") - 1) == 0) {
-               char *zone_name;
+               char *krate_name;
 
-               zone_name = tmp + sizeof("setup/") - 1;
-               __add_shortcut(zone_name);
+               krate_name = tmp + sizeof("setup/") - 1;
+               __add_shortcut(krate_name);
                ui_app_exit();
                return;
        } else if (strncmp(tmp, "enter/", sizeof("enter/") - 1) == 0) {
-               char* zone_name, *launch_parameter;
+               char* krate_name, *launch_parameter;
                char new_uri[PATH_MAX];
 
-               zone_name = tmp + sizeof("enter/") - 1;
-               launch_parameter = strchr(zone_name, '/');
+               krate_name = tmp + sizeof("enter/") - 1;
+               launch_parameter = strchr(krate_name, '/');
                if (launch_parameter != NULL) {
                        *(launch_parameter++) = '\0';
                        if (launch_parameter[0] == '\0') {
@@ -142,16 +142,15 @@ static void __app_control(app_control_h app_control, void *data)
                } else {
                        launch_parameter = KASKIT_PACKAGE;
                }
-               snprintf(new_uri, PATH_MAX, "zone://launch/%s", launch_parameter);
+               snprintf(new_uri, PATH_MAX, "krate://launch/%s", launch_parameter);
                app_control_set_uri(app_control, new_uri);
                app_control_set_app_id(app_control, PACKAGE);
 
-               dlog_print(DLOG_ERROR, LOG_TAG, "Wow");
                dlog_print(DLOG_ERROR, LOG_TAG, PACKAGE);
                dlog_print(DLOG_ERROR, LOG_TAG, new_uri);
-               dlog_print(DLOG_ERROR, LOG_TAG, zone_name);
+               dlog_print(DLOG_ERROR, LOG_TAG, krate_name);
 
-               __launch_zone_app(zone_name, app_control);
+               __launch_krate_app(krate_name, app_control);
                ui_app_exit();
                return;
        }else if (strncmp(tmp, "launch/", sizeof("launch/") - 1) == 0) {
index 27c812f..45a649c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Keyguard application
+ * Tizen Krate Keyguard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index 8d6c682..c92b902 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Keyguard application
+ * Tizen Krate Keyguard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index eea89ca..e495026 100644 (file)
@@ -6,10 +6,9 @@ INCLUDE_DIRECTORIES(./include)
 FIND_PACKAGE(PkgConfig REQUIRED)
 PKG_CHECK_MODULES(SETUP_WIZARD REQUIRED
        notification
-       zone
 )
 
-INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${SETUP_WIZARD_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${SETUP_WIZARD_INCLUDE_DIRS} ${KRATE_LIB})
 LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${SETUP_WIZARD_LIBRARY_DIRS})
 
 SET(PACKAGE_SRC src/main.c
@@ -24,7 +23,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
 ADD_EXECUTABLE(${PROJECT_NAME} ${PACKAGE_SRC})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin)
 
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${SETUP_WIZARD_LIBRARIES})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${SETUP_WIZARD_LIBRARIES} krate)
 
 ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj
         COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images
index a003d41..2828c3b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -16,8 +16,8 @@
  * limitations under the License.
  *
  */
-#ifndef __ZONE_SETUP_H__
-#define __ZONE_SETUP_H__
+#ifndef __KRATE_SETUP_H__
+#define __KRATE_SETUP_H__
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,8 +29,8 @@
 #include <dlog.h>
 #include <Elementary.h>
 #include <efl_extension.h>
-#include <zone/zone.h>
-#include <zone/app-proxy.h>
+#include <krate/krate.h>
+#include <krate/app-proxy.h>
 
 #include "setup-text.h"
 
 
 typedef struct {
        char *mode;
-       char *zone_name;
-        char *zone_password;
+       char *krate_name;
+        char *krate_password;
 
-       zone_manager_h zone_manager;
-       int zone_event_cb_id;
+       krate_manager_h krate_manager;
+       int krate_event_cb_id;
        bool request_done;
 
        app_control_h app_control;
@@ -72,9 +72,9 @@ void _create_security_view(appdata_s *data);
 void _create_setup_view(appdata_s *data);
 void _create_two_button_layout(Evas_Object *parent, Evas_Object *left_button, Evas_Object *right_button);
 
-int _send_zone_create_request(appdata_s *ad);
-int _send_zone_remove_request(appdata_s *ad);
+int _send_krate_create_request(appdata_s *ad);
+int _send_krate_remove_request(appdata_s *ad);
 void _create_notification(app_control_h app_control);
-void *zone_request_fail(void *ad);
+void *krate_request_fail(void *ad);
 
-#endif /* __ZONE_SETUP_H__ */
+#endif /* __KRATE_SETUP_H__ */
index 7d96ad8..ca4a792 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
 #define DELETE_ONGOING_TITLE "Deleting a folder..."
 #define DELETE_ONGOING_CONTENT "The folder will be removed from<br> your personal home screen."
 
-#define NOTI_CREATE_ZONE "Separated zone creation"
-#define NOTI_BODY_CREATE_ZONE "Tap heare to create Separated Zone."
+#define NOTI_CREATE_KRATE "Separated krate creation"
+#define NOTI_BODY_CREATE_KRATE "Tap heare to create Separated Krate."
 
-#define NOTI_REMOVE_ZONE "Separated Zone deletion"
-#define NOTI_BODY_REMOVE_ZONE "Tap here to delete Separated Zone."
+#define NOTI_REMOVE_KRATE "Separated Krate deletion"
+#define NOTI_BODY_REMOVE_KRATE "Tap here to delete Separated Krate."
 
 #define CANCEL_BUTTON "Cancel"
 #define NEXT_BUTTON "Next"
@@ -52,7 +52,7 @@
 
 #define OK_BUTTON "OK"
 #define SETUP_POPUP_HEADER "Setup Wizard"
-#define BODY_ZONE_CREATE_ERROR "Failed to create the Separated Zone."
-#define BODY_ZONE_REMOVE_ERROR "Failed to remove the Separated Zone."
+#define BODY_KRATE_CREATE_ERROR "Failed to create the Separated Krate."
+#define BODY_KRATE_REMOVE_ERROR "Failed to remove the Separated Krate."
 
 #endif /*__SETUP_TEXT_H__*/
index de65535..febca3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index ca1448d..8b521cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard Layout
+ * Tizen Krate Setup-Wizard Layout
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index 8c6ecbd..6262019 100644 (file)
@@ -19,7 +19,7 @@ group { name: "setup_layout";
                                color: 0 0 0 255;
                                rel1 { relative: 0.0 0.0; to: "bg"; offset: 22 150;}
                                rel2 { relative: 1.0 0.0; to: "bg"; offset: -22 300;}
-                               text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Zone";}
+                               text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Krate";}
                        }
                }
                part { name: "icon_base";
index 632f95c..382e402 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard Layout
+ * Tizen Krate Setup-Wizard Layout
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -40,7 +40,7 @@ group { name: "welcome_layout";
                                color3: 85 88 88 255;
                                rel1 { relative: 0.0 0.0; to: "bg"; offset: 22 150;}
                                rel2 { relative: 1.0 0.0; to: "bg"; offset: -22 300;}
-                               text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Zone";}
+                               text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Krate";}
                        }
                }
                part { name: "icon_base";
index 658ed80..20c0bb2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
 #include "krate-setup.h"
 #include "widget.h"
 
-static void __launch_zone_app(zone_manager_h zone_mgr, const char *zone_name, app_control_h app_control)
+static void __launch_krate_app(krate_manager_h krate_mgr, const char *krate_name, app_control_h app_control)
 {
-       zone_app_proxy_h zone_app;
+       krate_app_proxy_h krate_app;
 
-       zone_app_proxy_create(zone_mgr, zone_name, &zone_app);
-       zone_app_proxy_send_launch_request(zone_app, app_control);
-       zone_app_proxy_destroy(zone_app);
+       krate_app_proxy_create(krate_mgr, krate_name, &krate_app);
+       krate_app_proxy_send_launch_request(krate_app, app_control);
+       krate_app_proxy_destroy(krate_app);
 }
 
-static void __zone_request_done(const char *from, const char *info, void *user_data)
+static void __krate_request_done(const char *from, const char *info, void *user_data)
 {
        app_control_h app_control;
        char uri[PATH_MAX];
 
        appdata_s *ad = (appdata_s *) user_data;
        if (!strcmp(info, "Error")) {
-               ecore_main_loop_thread_safe_call_sync(zone_request_fail, ad);
+               ecore_main_loop_thread_safe_call_sync(krate_request_fail, ad);
                return;
        }
 
        if (!strcmp(ad->mode, "create")) {
-               zone_manager_reset_zone_password(ad->zone_manager, ad->zone_name, ad->zone_password);
+               krate_manager_reset_krate_password(ad->krate_manager, ad->krate_name, ad->krate_password);
 
                app_control_create(&app_control);
                app_control_set_app_id(app_control, KEYGUARD_PACKAGE);
-               snprintf(uri, sizeof(uri), "zone://setup/%s", ad->zone_name);
+               snprintf(uri, sizeof(uri), "krate://setup/%s", ad->krate_name);
                app_control_set_uri(app_control, uri);
                app_control_send_launch_request(app_control, NULL, NULL);
                app_control_destroy(app_control);
 
                app_control_create(&app_control);
                app_control_set_app_id(app_control, KASKIT_PACKAGE);
-               __launch_zone_app(ad->zone_manager, ad->zone_name, app_control);
+               __launch_krate_app(ad->krate_manager, ad->krate_name, app_control);
                app_control_destroy(app_control);
        }
 
@@ -62,8 +62,8 @@ static bool __app_create(void *data)
 {
        appdata_s *ad = (appdata_s *) data;
 
-       if (zone_manager_create(&ad->zone_manager) != ZONE_ERROR_NONE) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "failed to get zone manager handle");
+       if (krate_manager_create(&ad->krate_manager) != KRATE_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "failed to get krate manager handle");
                ui_app_exit();
                return false;
        }
@@ -81,7 +81,7 @@ static void __app_resume(void *data)
 
 static void __free_data(appdata_s *ad)
 {
-       free(ad->zone_name);
+       free(ad->krate_name);
        free(ad->mode);
 }
 
@@ -89,15 +89,15 @@ static void __app_terminate(void *data)
 {
        appdata_s *ad = (appdata_s *) data;
 
-       zone_manager_remove_event_cb(ad->zone_manager, ad->zone_event_cb_id);
-       zone_manager_destroy(ad->zone_manager);
+       krate_manager_remove_event_cb(ad->krate_manager, ad->krate_event_cb_id);
+       krate_manager_destroy(ad->krate_manager);
 
        __free_data(ad);
 
        return ;
 }
 
-static void __set_zone_callback(appdata_s *ad)
+static void __set_krate_callback(appdata_s *ad)
 {
        char *cb_event_list[2] = {"created", "removed"};
        char *cb_event = NULL;
@@ -107,8 +107,8 @@ static void __set_zone_callback(appdata_s *ad)
        else
                cb_event = cb_event_list[1];
 
-       if (zone_manager_add_event_cb(ad->zone_manager, cb_event, __zone_request_done, ad, &ad->zone_event_cb_id) != ZONE_ERROR_NONE) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add zone signal callback");
+       if (krate_manager_add_event_cb(ad->krate_manager, cb_event, __krate_request_done, ad, &ad->krate_event_cb_id) != KRATE_ERROR_NONE) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add krate signal callback");
                ui_app_exit();
        }
 
@@ -133,14 +133,14 @@ static void __app_control(app_control_h app_control, void *data)
                return;
        }
 
-       ret = app_control_get_extra_data(app_control, "zone", &ad->zone_name);
+       ret = app_control_get_extra_data(app_control, "krate", &ad->krate_name);
        if (ret != APP_CONTROL_ERROR_NONE) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "failed to get zone name");
+               dlog_print(DLOG_ERROR, LOG_TAG, "failed to get krate name");
                ui_app_exit();
                return;
        }
 
-       __set_zone_callback(ad);
+       __set_krate_callback(ad);
 
        if (app_control_clone(&ad->app_control, app_control) != APP_CONTROL_ERROR_NONE) {
                dlog_print(DLOG_ERROR, LOG_TAG, "Failed to clone app control handler");
index 80fe455..c80dc54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -189,9 +189,9 @@ static void security_password_setup_cb(void *data, Evas_Object *obj, void *event
        }
                delete_object_data();
 
-        ad->zone_password = security_password_setup_data;
+        ad->krate_password = security_password_setup_data;
 
-       if (_send_zone_create_request(ad) != 0) {
+       if (_send_krate_create_request(ad) != 0) {
                ui_app_exit();
        }
 
index c8a4937..30be539 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -50,8 +50,8 @@ static void setup_wizard_next_cb(void *data, Evas_Object *obj, void *event_info)
        if (!strcmp(ad->mode, "create")) {
                _create_security_view(ad);
        } else {
-               if (_send_zone_remove_request(ad) != 0) {
-                       ecore_main_loop_thread_safe_call_sync(zone_request_fail, ad);
+               if (_send_krate_remove_request(ad) != 0) {
+                       ecore_main_loop_thread_safe_call_sync(krate_request_fail, ad);
                        return;
                }
                _create_setup_view(ad);
@@ -96,15 +96,15 @@ static Eina_Bool __progressbar_timer_cb(void *data)
        return ECORE_CALLBACK_RENEW;
 }
 
-void *zone_request_fail(void *user_data)
+void *krate_request_fail(void *user_data)
 {
        Evas_Object *popup = NULL;
        appdata_s *ad = (appdata_s *)user_data;
 
        if (!strcmp(ad->mode, "create"))
-               popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_ZONE_CREATE_ERROR);
+               popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_KRATE_CREATE_ERROR);
        else
-               popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_ZONE_REMOVE_ERROR);
+               popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_KRATE_REMOVE_ERROR);
 
        Evas_Object *btn = elm_button_add(popup);
        elm_object_style_set(btn, "popup");
index 7ad63ee..8112db2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
@@ -19,9 +19,9 @@
 #include <notification.h>
 #include "krate-setup.h"
 
-#define ZONE_METADATA_PATH "data/KrateManifest.xml"
+#define KRATE_METADATA_PATH "data/KrateManifest.xml"
 
-static char *__get_zone_metadata(void)
+static char *__get_krate_metadata(void)
 {
        FILE *fp = NULL;
        char *res_path = NULL;
@@ -35,7 +35,7 @@ static char *__get_zone_metadata(void)
                dlog_print(DLOG_ERROR, LOG_TAG, "failed to get resource path");
                return NULL;
        }
-       snprintf(metadata_path, PATH_MAX, "%s%s", res_path, ZONE_METADATA_PATH);
+       snprintf(metadata_path, PATH_MAX, "%s%s", res_path, KRATE_METADATA_PATH);
        free(res_path);
 
        fp = fopen(metadata_path, "r");
@@ -81,31 +81,31 @@ static char *__get_zone_metadata(void)
        return metadata;
 }
 
-int _send_zone_create_request(appdata_s *ad)
+int _send_krate_create_request(appdata_s *ad)
 {
        int ret;
        char *metadata = NULL;
 
-       metadata = __get_zone_metadata();
+       metadata = __get_krate_metadata();
        if (metadata == NULL) {
-               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get zone metadata");
+               dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get krate metadata");
                return -1;
        }
 
-       ret = zone_manager_create_zone(ad->zone_manager, ad->zone_name, metadata);
-       if (ret != ZONE_ERROR_NONE) {
+       ret = krate_manager_create_krate(ad->krate_manager, ad->krate_name, metadata);
+       if (ret != KRATE_ERROR_NONE) {
                return -1;
        }
 
        return 0;
 }
 
-int _send_zone_remove_request(appdata_s *ad)
+int _send_krate_remove_request(appdata_s *ad)
 {
        int ret;
 
-       ret = zone_manager_destroy_zone(ad->zone_manager, ad->zone_name);
-       if (ret != ZONE_ERROR_NONE) {
+       ret = krate_manager_destroy_krate(ad->krate_manager, ad->krate_name);
+       if (ret != KRATE_ERROR_NONE) {
                return -1;
        }
 
@@ -117,8 +117,8 @@ static int __set_notification(notification_h noti_handle, app_control_h app_cont
        int ret = 0;
         char *mode = NULL;
         char *noti_text[2][2] = {
-                {NOTI_CREATE_ZONE, NOTI_BODY_CREATE_ZONE},
-                {NOTI_REMOVE_ZONE, NOTI_BODY_REMOVE_ZONE}
+                {NOTI_CREATE_KRATE, NOTI_BODY_CREATE_KRATE},
+                {NOTI_REMOVE_KRATE, NOTI_BODY_REMOVE_KRATE}
         };
         char **text = NULL;
 
index 426a404..6a94dc4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Tizen Zone Setup-Wizard application
+ * Tizen Krate Setup-Wizard application
  *
  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
  *
index 67a843a..75023dd 100644 (file)
@@ -19,7 +19,7 @@ FILE(GLOB CLI_SRCS    krate-admin-cli.cpp
                                        ${KRATE_MODULE}/krate-builder.cpp
 )
 
-SET(CLI_NAME "zone-admin-cli")
+SET(CLI_NAME ${PROJECT_NAME}-admin-cli)
 
 ADD_EXECUTABLE(${CLI_NAME} ${CLI_SRCS})
 SET_TARGET_PROPERTIES(${CLI_NAME} PROPERTIES PREFIX ""
@@ -34,10 +34,9 @@ PKG_CHECK_MODULES(CLI_DEPS   REQUIRED
                                                        libxml-2.0
                                                        capi-appfw-package-manager
                                                        capi-appfw-app-manager
-                                                       zone
 )
 
-INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${KRATE_MODULE})
-TARGET_LINK_LIBRARIES(${CLI_NAME} ${CLI_DEPS_LIBRARIES})
+INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${KRATE_MODULE} ${KRATE_LIB})
+TARGET_LINK_LIBRARIES(${CLI_NAME} ${CLI_DEPS_LIBRARIES} krate)
 
 INSTALL(TARGETS ${CLI_NAME} DESTINATION sbin)
index e46e45b..45b7ea2 100644 (file)
@@ -44,8 +44,8 @@
 #include <klay/filesystem.h>
 #include <klay/auth/user.h>
 
-#include <zone/app-proxy.h>
-#include <zone/package-proxy.h>
+#include <krate/app-proxy.h>
+#include <krate/package-proxy.h>
 
 #include "session.h"
 
@@ -237,15 +237,15 @@ int showPkgInfo(const std::string& name)
 {
        int num = 0;
 
-       zone_manager_h krateMgr;
-       zone_package_proxy_h pkgProxy;
+       krate_manager_h krateMgr;
+       krate_package_proxy_h pkgProxy;
 
-       zone_manager_create(&krateMgr);
-       zone_package_proxy_create(krateMgr, name.c_str(), &pkgProxy);
-       zone_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num);
+       krate_manager_create(&krateMgr);
+       krate_package_proxy_create(krateMgr, name.c_str(), &pkgProxy);
+       krate_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num);
        std::cout << num << " packages are found" << std::endl;
-       zone_package_proxy_destroy(pkgProxy);
-       zone_manager_destroy(krateMgr);
+       krate_package_proxy_destroy(pkgProxy);
+       krate_manager_destroy(krateMgr);
 
        return 0;
 }
@@ -295,15 +295,15 @@ int showAppInfo(const std::string& name)
 {
        int num = 0;
 
-       zone_manager_h krateMgr;
-       zone_app_proxy_h appMgr;
+       krate_manager_h krateMgr;
+       krate_app_proxy_h appMgr;
 
-       zone_manager_create(&krateMgr);
-       zone_app_proxy_create(krateMgr, name.c_str(), &appMgr);
-       zone_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num);
+       krate_manager_create(&krateMgr);
+       krate_app_proxy_create(krateMgr, name.c_str(), &appMgr);
+       krate_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num);
        std::cout << num << " applications are found" << std::endl;
-       zone_app_proxy_destroy(appMgr);
-       zone_manager_destroy(krateMgr);
+       krate_app_proxy_destroy(appMgr);
+       krate_manager_destroy(krateMgr);
 
        return 0;
 }
@@ -326,12 +326,12 @@ void krateCallback(const char* name, const char* object, void *user_data)
 int monitorEvent()
 {
        int krateCallbackId[2];
-       zone_manager_h krateMgr;
-       zone_manager_create(&krateMgr);
+       krate_manager_h krateMgr;
+       krate_manager_create(&krateMgr);
 
-       zone_manager_add_event_cb(krateMgr, "created", krateCallback,
+       krate_manager_add_event_cb(krateMgr, "created", krateCallback,
                                                                (void*)"created", &krateCallbackId[0]);
-       zone_manager_add_event_cb(krateMgr, "removed", krateCallback,
+       krate_manager_add_event_cb(krateMgr, "removed", krateCallback,
                                                                (void*)"removed", &krateCallbackId[1]);
 
        std::cout << "=== Monitoring start ===" << std::endl << std::endl;
@@ -342,12 +342,12 @@ int monitorEvent()
        g_main_loop_run(gmainloop);
        g_main_loop_unref(gmainloop);
 
-       zone_manager_remove_event_cb(krateMgr, krateCallbackId[0]);
-       zone_manager_remove_event_cb(krateMgr, krateCallbackId[1]);
+       krate_manager_remove_event_cb(krateMgr, krateCallbackId[0]);
+       krate_manager_remove_event_cb(krateMgr, krateCallbackId[1]);
 
        std::cout << "===  Monitoring end  ===" << std::endl;
 
-       zone_manager_destroy(krateMgr);
+       krate_manager_destroy(krateMgr);
 
        return 0;
 }
@@ -398,13 +398,13 @@ void packageEventCallback(const char *type,
 
 int monitorPkgEvent(const std::string& name)
 {
-       zone_manager_h krateMgr;
-       zone_package_proxy_h pkgProxy;
+       krate_manager_h krateMgr;
+       krate_package_proxy_h pkgProxy;
 
-       zone_manager_create(&krateMgr);
-       zone_package_proxy_create(krateMgr, name.c_str(), &pkgProxy);
+       krate_manager_create(&krateMgr);
+       krate_package_proxy_create(krateMgr, name.c_str(), &pkgProxy);
 
-       zone_package_proxy_set_event_cb(pkgProxy, packageEventCallback, NULL);
+       krate_package_proxy_set_event_cb(pkgProxy, packageEventCallback, NULL);
 
        std::cout << "=== Monitoring start ===" << std::endl << std::endl;
 
@@ -414,12 +414,12 @@ int monitorPkgEvent(const std::string& name)
        g_main_loop_run(gmainloop);
        g_main_loop_unref(gmainloop);
 
-       zone_package_proxy_unset_event_cb(pkgProxy);
+       krate_package_proxy_unset_event_cb(pkgProxy);
 
        std::cout << "===  Monitoring end  ===" << std::endl;
 
-       zone_package_proxy_destroy(pkgProxy);
-       zone_manager_destroy(krateMgr);
+       krate_package_proxy_destroy(pkgProxy);
+       krate_manager_destroy(krateMgr);
 
        return 0;
 }
index 1d30527..fcaf715 100644 (file)
@@ -1,4 +1,4 @@
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 
 export `tzplatform-get TZ_SYS_ETC`
-cp ${TZ_SYS_ETC}/dpm/zone/owner.xml ${TZ_SYS_ETC}/dpm/zone/${1}.xml
+cp ${TZ_SYS_ETC}/krate/owner.xml ${TZ_SYS_ETC}/krate/${1}.xml
index 48bfabe..73112eb 100644 (file)
@@ -1,4 +1,4 @@
 PATH=/bin:/usr/bin:/sbin:/usr/sbin
 
 export `tzplatform-get TZ_SYS_ETC`
-rm ${TZ_SYS_ETC}/dpm/zone/${1}.xml
+rm ${TZ_SYS_ETC}/krate/${1}.xml