#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"
#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"
#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
} 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 {
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()
{
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();
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();
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();
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)
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();
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();
}
}
+ 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();
_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;
{
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 {
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;
((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;
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");
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 {
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;
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;
}
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__ */
_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;
{
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 {
_D("communcation/start requested");
int error;
+ json result;
int properties;
iotcon_resource_interfaces_h resource_ifaces = NULL;
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;
}
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;
}
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;
}
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)
{
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);
}
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;
}
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);
};