Implemented service_listener_cb specifications 88/81288/1
authorkmook <kmook.choi@samsung.com>
Mon, 25 Jul 2016 08:29:00 +0000 (17:29 +0900)
committerkmook <kmook.choi@samsung.com>
Mon, 25 Jul 2016 08:30:02 +0000 (17:30 +0900)
Change-Id: I011865c524ff27525f7185837f2a57c3d6dbc727
Signed-off-by: kmook <kmook.choi@samsung.com>
common/common.h
daemon/discovery_mgr_impl.cpp
daemon/service_provider/app_comm_service_info.h
daemon/service_provider/app_comm_service_provider.cpp
daemon/service_provider/app_comm_service_provider.h
daemon/service_provider/remote_app_control_service_provider.cpp
daemon/service_provider/remote_app_control_service_provider.h

index 7e77fd5..bdcb6ad 100644 (file)
@@ -21,6 +21,7 @@
 #include <tzplatform_config.h>
 #include "log.h"
 #include "d2d_conv_manager.h"
+#include "d2d_conv_internal.h"
 
 #define CONV_DATA "ConvHeader"
 #define CONV_OPTION "ConvOption"
@@ -137,9 +138,10 @@ enum request_type {
 #define CONV_JSON_CHANNEL_ID                   "channel_id"
 #define CONV_JSON_URI                                  "uri"
 #define CONV_JSON_RESULT_TYPE                  "result_type"
-#define CONV_JSON_MESSAGE                              "message"
+#define CONV_JSON_READ_TYPE                            "read_type"
+#define CONV_JSON_MESSAGE                              "message_smartview"
 #define CONV_JSON_CLIENT                               "client"
-#define CONV_JSON_PAYLOAD_SIZE                 "payload_size"
+#define CONV_JSON_PAYLOAD_SIZE                 "payload_size_smartview"
 #define CONV_JSON_EVENT                                        "event"
 #define CONV_JSON_FROM                                 "from"
 #define CONV_JSON_IS_HOST                              "isHost"
@@ -149,11 +151,23 @@ enum request_type {
 #define CONV_JSON_CLIENT_LIST                  "client_list"
 #define CONV_JSON_ERROR_MESSAGE                        "error_message"
 
+#define CONV_JSON_ON_START                             "onStart"
+#define CONV_JSON_ON_CONNECT                   "onConnect"
+#define CONV_JSON_ON_STOP                              "onStop"
+#define CONV_JSON_ON_DISCONNECT                        "onDisconnect"
+#define CONV_JSON_ON_MESSAGE                   "onMessage"
+#define CONV_JSON_ON_ERROR                             "onError"
+
+#define CONV_JSON_ON_CLIENT_CONNECT            "onClientConnect"
+#define CONV_JSON_ON_CLIENT_DISCONNECT "onClientDisconnect"
+
+#define CONV_JSON_ON_PUBLISH                   "onPublish"
+#define CONV_JSON_ON_READ                              "onRead"
+
+#define CONV_JSON_GET_CLIENTS                  "getClients"
+
 // remote app control service
 #define CONV_JSON_APP_CONTROL                  "app_control"
 #define CONV_JSON_REPLY                                        "reply"
 
-#define CONV_SETTING_VALUE_SERVICE_APP_TO_APP_COMMUNICATION 0x0001
-#define CONV_SETTING_VALUE_SERVICE_REMOTE_APP_CONTROL 0x0002
-
 #endif
index 5884ef4..9d5a88c 100755 (executable)
@@ -182,7 +182,7 @@ int conv::discovery_manager_impl::handle_request(request* request_obj)
                } else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_STOP) ){
                        const char* client = request_obj->get_sender();
 
-                       if (count_discovery_request<=0) {
+                       if (count_discovery_request <= 0) {
                                _D("discovery is already stopped");
                                request_obj->reply(CONV_ERROR_INVALID_OPERATION);
                        } else {
index 57a1b68..6d88847 100755 (executable)
@@ -29,7 +29,7 @@
 
 namespace conv {
        class application_instance : public OnConnectListener, public OnDisconnectListener, public OnClientConnectListener, public OnClientDisconnectListener,
-                                                                       public OnMessageListener, public OnErrorListener, public OnStartAppListener, public OnStopAppListener {
+                                                                       public OnMessageListener, public OnErrorListener, public OnStartAppListener, public OnStopAppListener, public OnPublishListener {
                public:
                        virtual ~application_instance()
                        {
@@ -54,7 +54,7 @@ namespace conv {
                                        json payload;
                                        json description;
 
-                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, "onStart");
+                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_START);
 
                                        description = (*request_obj)->get_description();
 
@@ -84,7 +84,7 @@ namespace conv {
                                        json payload;
                                        json description;
 
-                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, "onStop");
+                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_STOP);
 
                                        description = (*request_obj)->get_description();
 
@@ -103,7 +103,7 @@ namespace conv {
                        void onConnect(Client client)
                        {
                                _D("onConnect Called");
-                               publish_response(CONV_ERROR_NONE, "onConnect", &client);
+                               publish_response(CONV_ERROR_NONE, CONV_JSON_ON_CONNECT, &client);
 
                                if (!is_local && application != NULL) {
                                        ((Application*)application)->start();
@@ -114,19 +114,19 @@ namespace conv {
                        void onDisconnect(Client client)
                        {
                                _D("onDisconnect Called");
-                               publish_response(CONV_ERROR_NONE, "onDisconnect", &client);
+                               publish_response(CONV_ERROR_NONE, CONV_JSON_ON_DISCONNECT, &client);
                        }
 
                        void onClientConnect(Client client)
                        {
                                _D("onClientConnect Called");
-                               publish_response(CONV_ERROR_NONE, "onClientConnect", &client);
+                               publish_response(CONV_ERROR_NONE, CONV_JSON_ON_CLIENT_CONNECT, &client);
                        }
 
                        void onClientDisconnect(Client client)
                        {
                                _D("onClientDisconnect Called");
-                               publish_response(CONV_ERROR_NONE, "onClientDisconnect", &client);
+                               publish_response(CONV_ERROR_NONE, CONV_JSON_ON_CLIENT_DISCONNECT, &client);
                        }
 
                        void onMessage(Message message)
@@ -150,7 +150,7 @@ namespace conv {
                                        json payload = payload_str;
 
                                        payload.set(NULL, CONV_JSON_PAYLOAD_SIZE, message.m_payload_size);
-                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, "onMessage");
+                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_MESSAGE);
                                        payload.set(NULL, CONV_JSON_MESSAGE, message_json);
 
                                        description = (*request_obj)->get_description();
@@ -174,7 +174,7 @@ namespace conv {
                                        json payload;
                                        json description;
 
-                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, "onError");
+                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_ERROR);
                                        payload.set(NULL, CONV_JSON_ERROR_MESSAGE, error.get_error_message());
 
                                        description = (*request_obj)->get_description();
@@ -188,6 +188,32 @@ namespace conv {
                                }
                        }
 
+                       void onPublished(bool publish_result, void* user_data)
+                       {
+                               _D("onPublished Called");
+
+                               if ((*request_obj) != NULL) {
+                                       _D(RED("publishing_response"));
+                                       json result;
+                                       json payload;
+                                       json description;
+
+                                       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_PUBLISH);
+
+                                       description = (*request_obj)->get_description();
+
+                                       description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+                                       description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channel_id);
+
+                                       result.set(NULL, CONV_JSON_DESCRIPTION, description);
+                                       result.set(NULL, CONV_JSON_PAYLOAD, payload);
+                                       if (publish_result)
+                                               (*request_obj)->publish(CONV_ERROR_NONE, result);
+                                       else
+                                               (*request_obj)->publish(CONV_ERROR_INVALID_OPERATION, result);
+                               }
+                       }
+
                        void publish_response(int error, string result_type, Client *client)
                        {
                                bool isHost = client->isHost();
index 06b1e50..10dca38 100755 (executable)
@@ -34,7 +34,7 @@ conv::app_comm_service_provider::app_comm_service_provider()
        _type = CONV_SERVICE_TYPE_SMARTVIEW_APP_COMMUNICATION;
        _resource_type = CONV_RESOURCE_TYPE_SMARTVIEW_APP_COMMUNICATION;
        _uri = CONV_URI_SMARTVIEW_APP_COMMUNICATION;
-       if (conv::util::is_service_activated(CONV_SETTING_VALUE_SERVICE_APP_TO_APP_COMMUNICATION))
+       if (conv::util::is_service_activated(CONV_INTERNAL_SERVICE_APP_TO_APP_COMMUNICATION))
                _activation_state = 1;
        else
                _activation_state = 0;
@@ -46,7 +46,7 @@ int conv::app_comm_service_provider::handle_vconf_update(keynode_t *node)
 {
        int current_state = vconf_keynode_get_int(node);
 
-       if ((CONV_SETTING_VALUE_SERVICE_APP_TO_APP_COMMUNICATION & current_state) > 0) {
+       if ((CONV_INTERNAL_SERVICE_APP_TO_APP_COMMUNICATION & current_state) > 0) {
                _activation_state = 1;
                init();
        } else {
@@ -210,6 +210,7 @@ int conv::app_comm_service_provider::start_request(request* request_obj)
                application->setonErrorListener(app_info);
                application->setonDisconnectListener(app_info);
                application->addOnAllMessageListener(app_info);
+               application->setonPublishListener(app_info);
 
                app_info->is_local = true;
                app_info->application = application;
@@ -231,6 +232,7 @@ int conv::app_comm_service_provider::start_request(request* request_obj)
                ((Application*)application)->setonStartAppListener(app_info);
                ((Application*)application)->setonStopAppListener(app_info);
                application->addOnAllMessageListener(app_info);
+               application->setonPublishListener(app_info);
 
                app_info->is_local = false;
                app_info->application = application;
@@ -301,6 +303,7 @@ int conv::app_comm_service_provider::get_request(request* request_obj)
        channel.get(NULL, CONV_JSON_CHANNEL_ID, &channel_id);
 
        application_instance *app_info = NULL;
+       json result;
 
        for (application_instance_list_t::iterator iter = svc_info->application_instance_list.begin(); iter != svc_info->application_instance_list.end(); ++iter) {
                _D("iteration");
@@ -313,16 +316,14 @@ int conv::app_comm_service_provider::get_request(request* request_obj)
 
                                if ( svc_info->registered_request == NULL) {
                                        _D("No callback is registered");
-                                       request_obj->reply(CONV_ERROR_INVALID_OPERATION);
-                                       delete request_obj;
+                                       send_read_response(result, CONV_JSON_GET_CLIENTS, CONV_ERROR_INVALID_OPERATION, svc_info->registered_request);
 
                                        return CONV_ERROR_INVALID_OPERATION;
                                }
 
                                if (client_list == NULL) {
                                        _D("No clients");
-                                       request_obj->reply(CONV_ERROR_NO_DATA);
-                                       delete request_obj;
+                                       send_read_response(result, CONV_JSON_GET_CLIENTS, CONV_ERROR_NO_DATA, svc_info->registered_request);
 
                                        return CONV_ERROR_NO_DATA;
                                } else {
@@ -332,9 +333,6 @@ int conv::app_comm_service_provider::get_request(request* request_obj)
 
                                        Client client_obj;
                                        _D("clients size = %d", client_list->size());
-
-                                       json result;
-
                                        for (auto cs_itr = cl.begin(); cs_itr != cl.end(); cs_itr++) {
                                                cs_index++;
                                                json client;
@@ -350,31 +348,33 @@ int conv::app_comm_service_provider::get_request(request* request_obj)
 
                                                result.array_append(NULL, CONV_JSON_CLIENT_LIST, client);
                                        }
-                                       send_response(result, svc_info->registered_request);
+                                       send_read_response(result, CONV_JSON_GET_CLIENTS, CONV_ERROR_NONE, svc_info->registered_request);
 
                                        return CONV_ERROR_NONE;
                                }
                        }
                }
        }
-
        _D("service is not started");
+       send_read_response(result, CONV_JSON_GET_CLIENTS, CONV_ERROR_INVALID_OPERATION, svc_info->registered_request);
 
        return CONV_ERROR_INVALID_OPERATION;
 }
 
-int conv::app_comm_service_provider::send_response(json payload, request* request_obj)
+int conv::app_comm_service_provider::send_read_response(json payload, const char* read_type, conv_error_e error, request* request_obj)
 {
        _D(RED("publishing_response"));
-       json result;
+       IF_FAIL_RETURN_TAG(request_obj != NULL, CONV_ERROR_INVALID_OPERATION, _E, "listener_cb is not registered");
 
+       json result;
        json description = request_obj->get_description();
 
-       payload.set(NULL, CONV_JSON_RESULT_TYPE, "getClient");
+       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_READ);
+       payload.set(NULL, CONV_JSON_READ_TYPE, read_type);
 
        result.set(NULL, CONV_JSON_DESCRIPTION, description);
        result.set(NULL, CONV_JSON_PAYLOAD, payload);
-       request_obj->publish(CONV_ERROR_NONE, result);
+       request_obj->publish(error, result);
 
        return CONV_ERROR_NONE;
 }
index 02fb33b..c4a0c03 100644 (file)
@@ -44,7 +44,7 @@ namespace conv {
                        int handle_vconf_update(keynode_t *node);
 
                private:
-                       int send_response(json payload, request* request_obj);
+                       int send_read_response(json payload, const char* read_type, conv_error_e error, request* request_obj);
        };
 }
 #endif /* __APP_COMMUNICATION_SERVICE_PROVIDER_H__ */
index 689ea4e..f2172c9 100755 (executable)
@@ -61,7 +61,7 @@ conv::remote_app_control_service_provider::remote_app_control_service_provider()
        _resource_type = CONV_RESOURCE_TYPE_REMOTE_APP_CONTROL;
        _uri = CONV_URI_REMOTE_APP_CONTROL;
        iotcon_resource = NULL;
-       if (conv::util::is_service_activated(CONV_SETTING_VALUE_SERVICE_REMOTE_APP_CONTROL))
+       if (conv::util::is_service_activated(CONV_INTERNAL_SERVICE_REMOTE_APP_CONTROL))
                _activation_state = 1;
        else
                _activation_state = 0;
@@ -79,7 +79,7 @@ int conv::remote_app_control_service_provider::handle_vconf_update(keynode_t *no
 {
        int current_state = vconf_keynode_get_int(node);
 
-       if ((CONV_SETTING_VALUE_SERVICE_REMOTE_APP_CONTROL & current_state) > 0) {
+       if ((CONV_INTERNAL_SERVICE_REMOTE_APP_CONTROL & current_state) > 0) {
                _activation_state = 1;
                init();
        } else {
@@ -347,6 +347,7 @@ int conv::remote_app_control_service_provider::start_request(request* request_ob
 
        _D("communcation/start requested");
        int error;
+       json result;
 
        int properties;
        iotcon_resource_interfaces_h resource_ifaces = NULL;
@@ -356,6 +357,7 @@ int conv::remote_app_control_service_provider::start_request(request* request_ob
 
        if (svc_info->iotcon_info_obj.iotcon_resource_handle != NULL) {
                _D("already started");
+               send_response(result, CONV_JSON_ON_START, CONV_ERROR_INVALID_OPERATION, svc_info->registered_request);
                return CONV_ERROR_INVALID_OPERATION;
        }
 
@@ -382,6 +384,25 @@ int conv::remote_app_control_service_provider::start_request(request* request_ob
        iotcon_resource_types_destroy(resource_types);
        iotcon_resource_interfaces_destroy(resource_ifaces);
 
+       send_response(result, CONV_JSON_ON_START, CONV_ERROR_NONE, svc_info->registered_request);
+
+       return CONV_ERROR_NONE;
+}
+
+int conv::remote_app_control_service_provider::send_response(json payload, const char* request_type, conv_error_e error, request* request_obj)
+{
+       _D(RED("publishing_response"));
+       IF_FAIL_RETURN_TAG(request_obj != NULL, CONV_ERROR_INVALID_OPERATION, _E, "listener_cb is not registered");
+
+       json result;
+       json description = request_obj->get_description();
+
+       payload.set(NULL, CONV_JSON_RESULT_TYPE, request_type);
+
+       result.set(NULL, CONV_JSON_DESCRIPTION, description);
+       result.set(NULL, CONV_JSON_PAYLOAD, payload);
+       request_obj->publish(error, result);
+
        return CONV_ERROR_NONE;
 }
 
@@ -390,17 +411,19 @@ int conv::remote_app_control_service_provider::stop_request(request* request_obj
        IF_FAIL_RETURN_TAG(_activation_state == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
 
        _D("communcation/stop requested");
+       json result;
 
        remote_app_control_service_info *svc_info = reinterpret_cast<remote_app_control_service_info*>(request_obj->service_info);
 
        if (svc_info->iotcon_info_obj.iotcon_resource_handle == NULL) {
                _D("not even started");
+               send_response(result, CONV_JSON_ON_STOP, CONV_ERROR_INVALID_OPERATION, svc_info->registered_request);
                return CONV_ERROR_INVALID_OPERATION;
        }
 
        iotcon_remote_resource_destroy(svc_info->iotcon_info_obj.iotcon_resource_handle);
-
        svc_info->iotcon_info_obj.iotcon_resource_handle = NULL;
+       send_response(result, CONV_JSON_ON_STOP, CONV_ERROR_NONE, svc_info->registered_request);
 
        return CONV_ERROR_NONE;
 }
@@ -412,11 +435,6 @@ int conv::remote_app_control_service_provider::get_request(request* request_obj)
        return CONV_ERROR_NONE;
 }
 
-int conv::remote_app_control_service_provider::send_response(json payload, request* request_obj)
-{
-       return CONV_ERROR_NONE;
-}
-
 static void on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
                iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
 {
@@ -462,12 +480,17 @@ static void on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
                json payload;
                json description;
 
-               payload.set(NULL, CONV_JSON_APP_CONTROL, appctl_char);
-               result.set(NULL, CONV_JSON_DESCRIPTION, cb_info.request_obj->get_description());
-               result.set(NULL, CONV_JSON_PAYLOAD, payload);
+               if (cb_info.request_obj == NULL) {
+                       _E("listener_cb is not registered");
+               } else {
+                       payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_PUBLISH);
+                       payload.set(NULL, CONV_JSON_APP_CONTROL, appctl_char);
+                       result.set(NULL, CONV_JSON_DESCRIPTION, cb_info.request_obj->get_description());
+                       result.set(NULL, CONV_JSON_PAYLOAD, payload);
 
-               cb_info.request_obj->publish(CONV_ERROR_NONE, result);
-               _D("response published");
+                       cb_info.request_obj->publish(CONV_ERROR_NONE, result);
+                       _D("response published");
+               }
        }
        response_cb_map.erase(find_iter);
 }
@@ -518,6 +541,11 @@ int conv::remote_app_control_service_provider::set_request(request* request_obj)
 
        IF_FAIL_RETURN_TAG(error == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "iotcon_remote_resource_put failed");
 
+       if (reply != 1) {
+               json result;
+               send_response(result, CONV_JSON_ON_PUBLISH, CONV_ERROR_NONE, svc_info->registered_request);
+       }
+
        return CONV_ERROR_NONE;
 }
 
index e726942..8e0f869 100644 (file)
@@ -44,7 +44,7 @@ namespace conv {
 
                private:
                        iotcon_resource_h iotcon_resource;
-                       int send_response(json payload, request* request_obj);
+                       int send_response(json payload, const char* request_type, conv_error_e error, request* request_obj);
 
                        static void iotcon_request_cb(iotcon_resource_h resource, iotcon_request_h request, void *user_data);
        };