Merge changes from Tizen 2.4 69/44769/1
authorMu-Woong <muwoong.lee@samsung.com>
Mon, 27 Jul 2015 12:41:52 +0000 (21:41 +0900)
committerMu-Woong <muwoong.lee@samsung.com>
Mon, 27 Jul 2015 12:41:52 +0000 (21:41 +0900)
- Restructure provider interface to support on-demand provider object creation

Change-Id: I1c1ce93fc9b0a087c970e7b1aa63754ed3059b29
Signed-off-by: Mu-Woong <muwoong.lee@samsung.com>
include/context_mgr.h
include/context_mgr_iface.h
include/provider_iface.h
src/context_mgr.cpp
src/provider_iface.cpp [new file with mode: 0644]

index 27f5e0e..c85c548 100644 (file)
@@ -21,19 +21,20 @@ namespace ctx {
        /* Forward Declaration */
        class json;
        class context_provider_iface;
+       class context_provider_info;
 
        namespace context_manager {
                /*
                 */
-               bool register_provider(const char* subject, ctx::context_provider_iface* cp);
+               bool register_provider(const char *subject, context_provider_info &provider_info);
 
                /*
                 */
-               bool publish(const charsubject, ctx::json option, int error, ctx::json data_updated);
+               bool publish(const char *subject, ctx::json option, int error, ctx::json data_updated);
 
                /*
                 */
-               bool reply_to_read(const charsubject, ctx::json option, int error, ctx::json data_read);
+               bool reply_to_read(const char *subject, ctx::json option, int error, ctx::json data_read);
 
        }       /* namespace ctx::context_manager */
 }      /* namespace ctx */
index 1cd15de..41f832b 100644 (file)
@@ -21,13 +21,14 @@ namespace ctx {
        /* Forward Declaration */
        class json;
        class context_provider_iface;
+       class context_provider_info;
 
        class context_manager_iface {
-               public:
-                       virtual ~context_manager_iface() {}
-                       virtual bool register_provider(const char* subject, ctx::context_provider_iface* cp) = 0;
-                       virtual bool publish(const char* subject, ctx::json& option, int error, ctx::json& data_updated) = 0;
-                       virtual bool reply_to_read(const char* subject, ctx::json& option, int error, ctx::json& data_read) = 0;
+       public:
+               virtual ~context_manager_iface() {}
+               virtual bool register_provider(const char *subject, context_provider_info &provider_info) = 0;
+               virtual bool publish(const char *subject, ctx::json &option, int error, ctx::json &data_updated) = 0;
+               virtual bool reply_to_read(const char *subject, ctx::json &option, int error, ctx::json &data_read) = 0;
        };      /* class context_manager_iface */
 
        namespace context_manager {
index 766ee68..f5268b6 100644 (file)
@@ -23,22 +23,31 @@ namespace ctx {
        class json;
 
        class context_provider_iface {
-               public:
-                       virtual ~context_provider_iface() {}
+       public:
+               virtual ~context_provider_iface() {}
+               virtual int subscribe(const char *subject, ctx::json option, ctx::json *request_result);
+               virtual int unsubscribe(const char *subject, ctx::json option);
+               virtual int read(const char *subject, ctx::json option, ctx::json *request_result);
+               virtual int write(const char *subject, ctx::json data, ctx::json *request_result);
 
-                       virtual bool init() = 0;
+       protected:
+               context_provider_iface() {}
 
-                       virtual bool is_supported(const char* subject) = 0;
-
-                       virtual int subscribe(const char* subject, ctx::json option, ctx::json* request_result) = 0;
-
-                       virtual int unsubscribe(const char* subject, ctx::json option) = 0;
+       };      /* class context_provider_iface */
 
-                       virtual int read(const char* subject, ctx::json option, ctx::json* request_result) = 0;
+       class context_provider_info {
+               typedef context_provider_iface *(*creator_t)(void *data);
+               typedef void (*destroyer_t)(void *data);
 
-                       virtual int write(const char* subject, ctx::json data, ctx::json* request_result) = 0;
+       public:
+               creator_t create;
+               destroyer_t destroy;
+               void *data;
+               const char *privilege;
 
-       };      /* class context_provider_iface */
+               context_provider_info();
+               context_provider_info(creator_t cr, destroyer_t des, void *dat = NULL, const char *priv = NULL);
+       };
 
 }      /* namespace ctx */
 
index b2acdc9..914bf3f 100644 (file)
@@ -27,10 +27,10 @@ void ctx::context_manager::set_instance(context_manager_iface* mgr)
        _instance = mgr;
 }
 
-bool ctx::context_manager::register_provider(const char* subject, ctx::context_provider_iface* cp)
+bool ctx::context_manager::register_provider(const char* subject, ctx::context_provider_info &provider_info)
 {
        IF_FAIL_RETURN_TAG(_instance, false, _E, "Not initialized");
-       return _instance->register_provider(subject, cp);
+       return _instance->register_provider(subject, provider_info);
 }
 
 bool ctx::context_manager::publish(const char* subject, ctx::json option, int error, ctx::json data_updated)
diff --git a/src/provider_iface.cpp b/src/provider_iface.cpp
new file mode 100644 (file)
index 0000000..1e06ce2
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 <types_internal.h>
+#include <json.h>
+#include <provider_iface.h>
+
+int ctx::context_provider_iface::subscribe(const char *subject, ctx::json option, ctx::json *request_result)
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::context_provider_iface::unsubscribe(const char *subject, ctx::json option)
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::context_provider_iface::read(const char *subject, ctx::json option, ctx::json *request_result)
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::context_provider_iface::write(const char *subject, ctx::json data, ctx::json *request_result)
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+ctx::context_provider_info::context_provider_info()
+       : create(NULL)
+       , destroy(NULL)
+       , data(NULL)
+       , privilege(NULL)
+{
+}
+
+ctx::context_provider_info::context_provider_info(
+               ctx::context_provider_info::creator_t cr,
+               ctx::context_provider_info::destroyer_t des, void *dat, const char *priv)
+       : create(cr)
+       , destroy(des)
+       , data(dat)
+       , privilege(priv)
+{
+}