--- /dev/null
+/*
+ * Copyright (c) 2016 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 "AppCommServiceApplication.h"
+
+conv::AppCommServiceApplication::~AppCommServiceApplication()
+{
+ if (application != NULL)
+ delete application;
+}
+
+void conv::AppCommServiceApplication::onStart(bool start_result)
+{
+ _D("onStart Called");
+
+ if ((*requestObj) != NULL) {
+ _D(RED("publishing_response"));
+ Json result;
+ Json payload;
+ Json description;
+
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_START);
+
+ description = (*requestObj)->getDescription();
+
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
+
+ result.set(NULL, CONV_JSON_DESCRIPTION, description);
+ result.set(NULL, CONV_JSON_PAYLOAD, payload);
+ if (start_result)
+ (*requestObj)->publish(CONV_ERROR_NONE, result);
+ else
+ (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
+ }
+}
+
+void conv::AppCommServiceApplication::onStop(bool start_result)
+{
+ _D("onStop Called");
+
+ if (!isLocal && application != NULL) {
+ application->disconnect();
+ }
+
+ if ((*requestObj) != NULL) {
+ _D(RED("publishing_response"));
+ Json result;
+ Json payload;
+ Json description;
+
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_STOP);
+
+ description = (*requestObj)->getDescription();
+
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
+
+ result.set(NULL, CONV_JSON_DESCRIPTION, description);
+ result.set(NULL, CONV_JSON_PAYLOAD, payload);
+ if (start_result)
+ (*requestObj)->publish(CONV_ERROR_NONE, result);
+ else
+ (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
+ }
+}
+
+void conv::AppCommServiceApplication::onConnect(Client client)
+{
+ _D("onConnect Called");
+ publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_CONNECT, &client);
+
+ if (!isLocal && application != NULL) {
+ ((Application*)application)->start();
+ _D("Application start requested");
+ }
+}
+
+void conv::AppCommServiceApplication::onDisconnect(Client client)
+{
+ _D("onDisconnect Called");
+ publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_DISCONNECT, &client);
+}
+
+void conv::AppCommServiceApplication::onClientConnect(Client client)
+{
+ _D("onClientConnect Called");
+ publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_CLIENT_CONNECT, &client);
+}
+
+void conv::AppCommServiceApplication::onClientDisconnect(Client client)
+{
+ _D("onClientDisconnect Called");
+ publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_CLIENT_DISCONNECT, &client);
+}
+
+void conv::AppCommServiceApplication::onMessage(Message message)
+{
+ _D("onMessage Called");
+
+ if ((*requestObj) != NULL) {
+ _D(RED("publishing_response"));
+ Json result;
+ Json message_json;
+ Json description;
+
+ _D("size %d", message.m_payload_size);
+ _D("payload %s", message.m_payload);
+
+ message_json.set(NULL, CONV_JSON_EVENT, message.m_event);
+ message_json.set(NULL, CONV_JSON_MESSAGE, message.m_data);
+ message_json.set(NULL, CONV_JSON_FROM, message.m_from);
+ string payload_str(reinterpret_cast<const char*>(message.m_payload), message.m_payload_size);
+
+ Json payload = payload_str;
+
+ payload.set(NULL, CONV_JSON_PAYLOAD_SIZE, message.m_payload_size);
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_MESSAGE);
+// payload.set(NULL, CONV_JSON_MESSAGE, message_json);
+ payload.set(NULL, CONV_JSON_MESSAGE, message_json.dupCstr());
+ payload.set(NULL, CONV_JSON_FROM, message.m_from);
+
+ description = (*requestObj)->getDescription();
+
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
+
+ result.set(NULL, CONV_JSON_DESCRIPTION, description);
+ result.set(NULL, CONV_JSON_PAYLOAD, payload);
+ (*requestObj)->publish(CONV_ERROR_NONE, result);
+ }
+}
+
+void conv::AppCommServiceApplication::onError(Error error)
+{
+ _D("onError Called");
+
+ if ((*requestObj) != NULL) {
+ _D(RED("publishing_response"));
+ Json result;
+ Json payload;
+ Json description;
+
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_ERROR);
+ payload.set(NULL, CONV_JSON_ERROR_MESSAGE, error.get_error_message());
+
+ description = (*requestObj)->getDescription();
+
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
+
+ result.set(NULL, CONV_JSON_DESCRIPTION, description);
+ result.set(NULL, CONV_JSON_PAYLOAD, payload);
+ (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
+ }
+}
+
+void conv::AppCommServiceApplication::onPublished(bool publish_result, void* user_data)
+{
+ _D("onPublished Called");
+
+ if ((*requestObj) != NULL) {
+ _D(RED("publishing_response"));
+ Json result;
+ Json payload;
+ Json description;
+
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_PUBLISH);
+
+ description = (*requestObj)->getDescription();
+
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
+
+ result.set(NULL, CONV_JSON_DESCRIPTION, description);
+ result.set(NULL, CONV_JSON_PAYLOAD, payload);
+ if (publish_result)
+ (*requestObj)->publish(CONV_ERROR_NONE, result);
+ else
+ (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
+ }
+}
+
+void conv::AppCommServiceApplication::publishResponse(int error, string result_type, Client *client)
+{
+ if ((*requestObj) != NULL) {
+ _D(RED("publishing_response"));
+ Json result;
+ Json payload;
+ Json description;
+
+ string isHostStr = to_string(client->isHost());
+ string connectTimeStr = to_string(client->getConnectTime());
+
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, result_type);
+ payload.set(NULL, CONV_JSON_CLIENT_IS_HOST, isHostStr.c_str());
+ payload.set(NULL, CONV_JSON_CLIENT_CONNECT_TIME, connectTimeStr.c_str());
+ payload.set(NULL, CONV_JSON_CLIENT_CLIENT_ID, client->getId());
+
+ description = (*requestObj)->getDescription();
+
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
+ description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
+
+ result.set(NULL, CONV_JSON_DESCRIPTION, description);
+ result.set(NULL, CONV_JSON_PAYLOAD, payload);
+ (*requestObj)->publish(error, result);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.
+ */
+
+#ifndef __APP_COMMUNICATION_SERVICE_APPLICATION_H__
+#define __APP_COMMUNICATION_SERVICE_APPLICATION_H__
+
+#include <glib.h>
+#include <vector>
+#include <vconf.h>
+#include "../IServiceProvider.h"
+#include "Application.h"
+
+namespace conv {
+ class AppCommServiceApplication : public OnConnectListener, public OnDisconnectListener, public OnClientConnectListener, public OnClientDisconnectListener,
+ public OnMessageListener, public OnErrorListener, public OnStartAppListener, public OnStopAppListener, public OnPublishListener {
+ public:
+ virtual ~AppCommServiceApplication();
+
+ conv::Request** requestObj;
+ Channel* application;
+ string uri;
+ string channelId;
+ Service localService;
+ bool isLocal;
+
+ void onStart(bool start_result);
+ void onStop(bool start_result);
+ void onConnect(Client client);
+ void onDisconnect(Client client);
+ void onClientConnect(Client client);
+ void onClientDisconnect(Client client);
+ void onMessage(Message message);
+ void onError(Error error);
+ void onPublished(bool publish_result, void* user_data);
+ void publishResponse(int error, string result_type, Client *client);
+ };
+}
+#endif /* __APP_COMMUNICATION_SERVICE_APPLICATION_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 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 "AppCommServiceInfo.h"
+
+void conv::AppCommServiceInfo::onSuccess(Service service)
+{
+ _D("getByUri : service name : %s", service.getName().c_str() ? service.getName().c_str() : "name is NULL");
+ serviceObj = service;
+ readRequestResult = true;
+}
+
+void conv::AppCommServiceInfo::onError(Error)
+{
+ _D("getByUri Error");
+ readRequestResult = false;
+}
+
+conv::AppCommServiceInfo::~AppCommServiceInfo()
+{
+ if (registeredRequest != NULL) {
+ delete registeredRequest;
+ }
+
+ for (ApplicationInstanceList::iterator iter = applicationInstanceList.begin(); iter != applicationInstanceList.end(); ++iter) {
+ AppCommServiceApplication *appInfo = *iter;
+ delete appInfo;
+ applicationInstanceList.erase(iter);
+ }
+}
#ifndef __APP_COMMUNICATION_SERVICE_INFO_H__
#define __APP_COMMUNICATION_SERVICE_INFO_H__
-#include <iotcon.h>
#include <glib.h>
#include <vector>
+#include "AppCommServiceApplication.h"
#include "../IServiceInfo.h"
#include "../Request.h"
#include "Service.h"
#include "Result.h"
namespace conv {
- class ApplicationInstance : public OnConnectListener, public OnDisconnectListener, public OnClientConnectListener, public OnClientDisconnectListener,
- public OnMessageListener, public OnErrorListener, public OnStartAppListener, public OnStopAppListener, public OnPublishListener {
- public:
- virtual ~ApplicationInstance()
- {
- if (application != NULL)
- delete application;
- }
-
- conv::Request** requestObj;
- Channel* application;
- string uri;
- string channelId;
- Service localService;
- bool isLocal;
-
- void onStart(bool start_result)
- {
- _D("onStart Called");
-
- if ((*requestObj) != NULL) {
- _D(RED("publishing_response"));
- Json result;
- Json payload;
- Json description;
-
- payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_START);
-
- description = (*requestObj)->getDescription();
-
- description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
- description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
-
- result.set(NULL, CONV_JSON_DESCRIPTION, description);
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
- if (start_result)
- (*requestObj)->publish(CONV_ERROR_NONE, result);
- else
- (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
- }
- }
-
- void onStop(bool start_result)
- {
- _D("onStop Called");
-
- if (!isLocal && application != NULL) {
- application->disconnect();
- }
-
- if ((*requestObj) != NULL) {
- _D(RED("publishing_response"));
- Json result;
- Json payload;
- Json description;
-
- payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_STOP);
-
- description = (*requestObj)->getDescription();
-
- description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
- description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
-
- result.set(NULL, CONV_JSON_DESCRIPTION, description);
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
- if (start_result)
- (*requestObj)->publish(CONV_ERROR_NONE, result);
- else
- (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
- }
- }
-
- void onConnect(Client client)
- {
- _D("onConnect Called");
- publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_CONNECT, &client);
-
- if (!isLocal && application != NULL) {
- ((Application*)application)->start();
- _D("Application start requested");
- }
- }
-
- void onDisconnect(Client client)
- {
- _D("onDisconnect Called");
- publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_DISCONNECT, &client);
- }
-
- void onClientConnect(Client client)
- {
- _D("onClientConnect Called");
- publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_CLIENT_CONNECT, &client);
- }
-
- void onClientDisconnect(Client client)
- {
- _D("onClientDisconnect Called");
- publishResponse(CONV_ERROR_NONE, CONV_JSON_ON_CLIENT_DISCONNECT, &client);
- }
-
- void onMessage(Message message)
- {
- _D("onMessage Called");
-
- if ((*requestObj) != NULL) {
- _D(RED("publishing_response"));
- Json result;
- Json message_json;
- Json description;
-
- _D("size %d", message.m_payload_size);
- _D("payload %s", message.m_payload);
-
- message_json.set(NULL, CONV_JSON_EVENT, message.m_event);
- message_json.set(NULL, CONV_JSON_MESSAGE, message.m_data);
- message_json.set(NULL, CONV_JSON_FROM, message.m_from);
- string payload_str(reinterpret_cast<const char*>(message.m_payload), message.m_payload_size);
-
- Json payload = payload_str;
-
- payload.set(NULL, CONV_JSON_PAYLOAD_SIZE, message.m_payload_size);
- payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_MESSAGE);
-// payload.set(NULL, CONV_JSON_MESSAGE, message_json);
- payload.set(NULL, CONV_JSON_MESSAGE, message_json.dupCstr());
- payload.set(NULL, CONV_JSON_FROM, message.m_from);
-
- description = (*requestObj)->getDescription();
-
- description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
- description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
-
- result.set(NULL, CONV_JSON_DESCRIPTION, description);
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
- (*requestObj)->publish(CONV_ERROR_NONE, result);
- }
- }
-
- void onError(Error error)
- {
- _D("onError Called");
-
- if ((*requestObj) != NULL) {
- _D(RED("publishing_response"));
- Json result;
- Json payload;
- Json description;
-
- payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_ERROR);
- payload.set(NULL, CONV_JSON_ERROR_MESSAGE, error.get_error_message());
-
- description = (*requestObj)->getDescription();
-
- description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
- description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
-
- result.set(NULL, CONV_JSON_DESCRIPTION, description);
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
- (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
- }
- }
-
- void onPublished(bool publish_result, void* user_data)
- {
- _D("onPublished Called");
-
- if ((*requestObj) != NULL) {
- _D(RED("publishing_response"));
- Json result;
- Json payload;
- Json description;
-
- payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_PUBLISH);
-
- description = (*requestObj)->getDescription();
-
- description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
- description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
-
- result.set(NULL, CONV_JSON_DESCRIPTION, description);
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
- if (publish_result)
- (*requestObj)->publish(CONV_ERROR_NONE, result);
- else
- (*requestObj)->publish(CONV_ERROR_INVALID_OPERATION, result);
- }
- }
-
- void publishResponse(int error, string result_type, Client *client)
- {
- if ((*requestObj) != NULL) {
- _D(RED("publishing_response"));
- Json result;
- Json payload;
- Json description;
-
- string isHostStr = to_string(client->isHost());
- string connectTimeStr = to_string(client->getConnectTime());
-
- payload.set(NULL, CONV_JSON_RESULT_TYPE, result_type);
- payload.set(NULL, CONV_JSON_CLIENT_IS_HOST, isHostStr.c_str());
- payload.set(NULL, CONV_JSON_CLIENT_CONNECT_TIME, connectTimeStr.c_str());
- payload.set(NULL, CONV_JSON_CLIENT_CLIENT_ID, client->getId());
-
- description = (*requestObj)->getDescription();
-
- description.set(CONV_JSON_CHANNEL, CONV_JSON_URI, uri);
- description.set(CONV_JSON_CHANNEL, CONV_JSON_CHANNEL_ID, channelId);
-
- result.set(NULL, CONV_JSON_DESCRIPTION, description);
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
- (*requestObj)->publish(error, result);
- }
- }
- };
-
- typedef vector<ApplicationInstance*> ApplicationInstanceList;
-
+ typedef vector<AppCommServiceApplication*> ApplicationInstanceList;
// service information to handle app-to-app service with specific device 'id'
class AppCommServiceInfo : public IServiceInfo, public Result_Base {
public:
- void onSuccess(Service service)
- {
- _D("getByUri : service name : %s", service.getName().c_str() ? service.getName().c_str() : "name is NULL");
- serviceObj = service;
- readRequestResult = true;
- }
-
- void onError(Error)
- {
- _D("getByUri Error");
- readRequestResult = false;
- }
+ void onSuccess(Service service);
+ void onError(Error);
- ~AppCommServiceInfo()
- {
- if (registeredRequest != NULL) {
- delete registeredRequest;
- }
+ ~AppCommServiceInfo();
- for (ApplicationInstanceList::iterator iter = applicationInstanceList.begin(); iter != applicationInstanceList.end(); ++iter) {
- ApplicationInstance *appInfo = *iter;
- delete appInfo;
- applicationInstanceList.erase(iter);
- }
- }
std::string id;
Service serviceObj;
bool isLocal;
IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
- ApplicationInstance *appInfo = NULL;
+ AppCommServiceApplication *appInfo = NULL;
for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {
_D("iteration");
}
if ( appInfo == NULL ) {
- appInfo = new(std::nothrow) ApplicationInstance();
+ appInfo = new(std::nothrow) AppCommServiceApplication();
ASSERT_ALLOC(appInfo);
appInfo->uri = uri;
for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {
_D("%s, %s", (*iter)->uri.c_str(), (*iter)->channelId.c_str());
if ( (*iter) != NULL && !(*iter)->uri.compare(uri) && !(*iter)->channelId.compare(channelId) ) {
- ApplicationInstance *appInfo = *iter;
+ AppCommServiceApplication *appInfo = *iter;
_D("COMMUNCATION_STOP : uri : %s, channel_id : %s", uri.c_str(), channelId.c_str());
IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
- ApplicationInstance *appInfo = NULL;
+ AppCommServiceApplication *appInfo = NULL;
Json result;
for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {