SET(CLIENT "d2d-conv-manager")
SET(DAEMON "d2d-conv-managerd")
-SET(DBUS_INTERFACE "org.tizen.d2d-conv-manager")
+SET(DBUS_INTERFACE "org.tizen.d2dconv")
ADD_SUBDIRECTORY(lib)
ADD_SUBDIRECTORY(daemon)
FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} service_provider/*.cpp)
FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} access_control/*.cpp)
FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} discovery_provider/iotcon/*.cpp)
+FILE(GLOB DAEMON_SRCS ${DAEMON_SRCS} discovery_provider/smartview/*.cpp)
SET(provider_deps "glib-2.0 dlog json-glib-1.0 iotcon capi-appfw-app-manager msf-api iotcon vconf capi-network-bluetooth capi-network-wifi-direct capi-appfw-application bundle capi-network-connection cynara-creds-gdbus cynara-client cynara-session capi-appfw-package-manager")
# SET(provider_deps "${provider_deps} security-server")
TARGET_LINK_LIBRARIES(${DAEMON} ${daemon_pkgs_LIBRARIES} -lpthread)
-
INSTALL(TARGETS ${DAEMON} DESTINATION ${BIN_INSTALL_DIR})
-
-SET(DBUS_SERVICE_FILE "org.tizen.d2dconv")
-CONFIGURE_FILE(${DBUS_SERVICE_FILE}.service.in ${DBUS_SERVICE_FILE}.service @ONLY)
-INSTALL(FILES ${DBUS_SERVICE_FILE}.service DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/services)
*creds = new(std::nothrow) credentials(package_id, client, session, user);
IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed");
+ g_free(app_id);
return true;
CATCH:
conv::client::~client()
{
for (service_info_map_t::iterator it = service_info_map.begin(); it != service_info_map.end(); ++it) {
-// delete (it->second);
+ delete (it->second);
}
service_info_map.clear();
}
service_info_map_t::iterator it;
it = service_info_map.find(std::pair<string, string>(type, id));
- if ( it != service_info_map.end() )
- {
+ if ( it != service_info_map.end() ) {
_D("service info found : %s, %s", type.c_str(), id.c_str());
return (service_info_base*)(it->second);
- }
- else
- {
+ } else {
_D("service info not found : %s, %s", type.c_str(), id.c_str());
return NULL;
}
#include <gio/gio.h>
#include "client.h"
#include "conv_json.h"
-#include "device.h"
+#include "device_iface.h"
#include "service_info_base.h"
namespace conv {
class client {
- typedef std::vector<device*> device_list_t;
+ typedef std::vector<device_iface*> device_list_t;
typedef std::pair<std::string, std::string> service_key_t;
typedef std::map<service_key_t, service_info_base*> service_info_map_t;
}
_D("new client obj created");
- client* client_obj = new conv::client(client_id, NULL);
+ client* client_obj = new(std::nothrow) conv::client(client_id, NULL);
client_list.push_back(client_obj);
return client_obj;
client_manager_impl();
~client_manager_impl();
- // int start(int time, request_info* request, json option);
- // int stop();
-
int init();
int release();
int handle_request(request* request_obj);
int error = CONV_ERROR_INVALID_OPERATION;
if ( !conv::privilege_manager::is_allowed(request_obj->get_creds(), CONV_PRIVILEGE_INTERNET) ||
- !conv::privilege_manager::is_allowed(request_obj->get_creds(), CONV_PRIVILEGE_BLUETOOTH) )
- {
+ !conv::privilege_manager::is_allowed(request_obj->get_creds(), CONV_PRIVILEGE_BLUETOOTH) ) {
_E("permission denied");
request_obj->reply(CONV_ERROR_PERMISSION_DENIED);
delete request_obj;
json::json(const char* s)
{
- if (s) {
+ if (s)
parse(s);
- } else {
+ else
parse(EMPTY_JSON_OBJECT);
- }
}
json::json(const std::string& s)
{
- if (s.empty()) {
+ if (s.empty())
parse(EMPTY_JSON_OBJECT);
- } else {
+ else
parse(s.c_str());
- }
}
json::~json()
{
release();
json_node = json_node_copy(j.json_node);
- if (!json_node) {
+ if (!json_node)
_E("Json object copy failed");
- }
+
return *this;
}
json& json::operator=(const char* s)
{
release();
- if (s) {
+ if (s)
parse(s);
- } else {
+ else
parse(EMPTY_JSON_OBJECT);
- }
+
return *this;
}
json& json::operator=(const std::string& s)
{
release();
- if (s.empty()) {
+ if (s.empty())
parse(EMPTY_JSON_OBJECT);
- } else {
+ else
parse(s.c_str());
- }
+
return *this;
}
return !operator==(rhs);
}
-/* TODO
-bool json::contains(const json& subset) const
-{
- return false;
-}
-*/
-
char* json::dup_cstr()
{
IF_FAIL_RETURN_TAG(json_node, NULL, _E, "Json object not initialized");
return output;
CATCH:
- if (jgen) {
+ if (jgen)
g_object_unref(jgen);
- }
_E("Memory allocation failed");
return NULL;
*length = 1;
- for (pch = path; *pch != '\0'; pch++) {
- if (*pch == PATH_DELIM) {
+ for (pch = path; *pch != '\0'; pch++)
+ if (*pch == PATH_DELIM)
*length = *length + 1;
- }
- }
tokens = static_cast<char**>(g_malloc((*length) * sizeof(char*)));
IF_FAIL_RETURN_TAG(tokens, NULL, _E, "Memory allocation failed");
begin = pch + 1;
}
- if (*pch == '\0') {
+ if (*pch == '\0')
break;
- }
}
return tokens;
CATCH:
- for (j = 0; j < i; j++) {
+ for (j = 0; j < i; j++)
g_free(tokens[j]);
- }
+
g_free(tokens);
return NULL;
}
{
int i;
if (tokens) {
- for (i = 0; i < length; i++) {
+ for (i = 0; i < length; i++)
g_free(tokens[i]);
- }
+
g_free(tokens);
}
}
goto CATCH;
}
}
+
child_node = json_object_get_member(jobj, path_token[depth]);
IF_FAIL_CATCH(child_node && json_node_get_node_type(child_node) == JSON_NODE_OBJECT);
JsonObject *jobj = traverse(json_node, path, true);
IF_FAIL_RETURN(jobj, false);
- if (json_object_has_member(jobj, key)) {
+ if (json_object_has_member(jobj, key))
json_object_remove_member(jobj, key);
- }
//NOTE: json-glib causes a precision issue while handling double values
json_object_set_string_member(jobj, key, double_to_string(val, prec).c_str());
JsonObject *jobj = traverse(json_node, path, true);
IF_FAIL_RETURN(jobj, false);
- if (json_object_has_member(jobj, key)) {
+ if (json_object_has_member(jobj, key))
json_object_remove_member(jobj, key);
- }
json_object_set_string_member(jobj, key, val.c_str());
return true;
node = json_object_dup_member(jobj, key);
IF_FAIL_RETURN_TAG(node, false, _E, "Memory allocation failed");
- if (val->json_node) {
+ if (val->json_node)
json_node_free(val->json_node);
- }
+
val->json_node = node;
return true;
IF_FAIL_RETURN(node, false);
GType vtype = json_node_get_value_type(node);
- if (vtype == G_TYPE_INT64) {
+ if (vtype == G_TYPE_INT64)
*val = json_node_get_int(node);
- } else if (vtype == G_TYPE_STRING) {
+ else if (vtype == G_TYPE_STRING)
//TODO: if the string is not a number?
*val = static_cast<int64_t>(string_to_double(json_node_get_string(node)));
- } else {
+ else
return false;
- }
return true;
}
IF_FAIL_RETURN(node, false);
GType vtype = json_node_get_value_type(node);
- if (vtype == G_TYPE_DOUBLE) {
+ if (vtype == G_TYPE_DOUBLE)
*val = json_node_get_double(node);
- } else if (vtype == G_TYPE_INT64) {
+ else if (vtype == G_TYPE_INT64)
*val = json_node_get_int(node);
- } else if (vtype == G_TYPE_STRING) {
+ else if (vtype == G_TYPE_STRING)
//NOTE: json-glib causes a precision issue while handling double values
*val = string_to_double(json_node_get_string(node));
- } else {
+ else
return false;
- }
return true;
}
return NULL;
}
}
+
node = json_object_get_member(jobj, key);
IF_FAIL_RETURN_TAG(node && json_node_get_node_type(node) == JSON_NODE_ARRAY,
NULL, _W, "Type mismatched: %s", key);
JsonNode *node_copy = json_node_copy(node);
IF_FAIL_RETURN_TAG(node_copy, false, _E, "Memory allocation failed");
- if (val->json_node) {
+ if (val->json_node)
json_node_free(val->json_node);
- }
+
val->json_node = node_copy;
return true;
IF_FAIL_RETURN(ltype == rtype, false);
switch (ltype) {
- case JSON_NODE_VALUE:
- IF_FAIL_RETURN(value_equals(lhs, rhs), false);
- break;
- case JSON_NODE_OBJECT:
- IF_FAIL_RETURN(object_equals(lhs, rhs), false);
- break;
- case JSON_NODE_ARRAY:
- IF_FAIL_RETURN(array_equals(lhs, rhs), false);
- break;
- default:
- _W("Unsupported type");
- return false;
+ case JSON_NODE_VALUE:
+ IF_FAIL_RETURN(value_equals(lhs, rhs), false);
+ break;
+ case JSON_NODE_OBJECT:
+ IF_FAIL_RETURN(object_equals(lhs, rhs), false);
+ break;
+ case JSON_NODE_ARRAY:
+ IF_FAIL_RETURN(array_equals(lhs, rhs), false);
+ break;
+ default:
+ _W("Unsupported type");
+ return false;
}
return true;
IF_FAIL_RETURN(ltype == rtype, false);
switch (ltype) {
- case G_TYPE_INT64:
- return json_node_get_int(lhs) == json_node_get_int(rhs);
- case G_TYPE_DOUBLE:
- return json_node_get_double(lhs) == json_node_get_double(rhs);
- case G_TYPE_STRING:
- return STR_EQ(json_node_get_string(lhs), json_node_get_string(rhs));
- default:
- _W("Unsupported type");
- return false;
+ case G_TYPE_INT64:
+ return json_node_get_int(lhs) == json_node_get_int(rhs);
+ case G_TYPE_DOUBLE:
+ return json_node_get_double(lhs) == json_node_get_double(rhs);
+ case G_TYPE_STRING:
+ return STR_EQ(json_node_get_string(lhs), json_node_get_string(rhs));
+ default:
+ _W("Unsupported type");
+ return false;
}
}
class dbus_server_iface {
public:
virtual ~dbus_server_iface() {}
-// virtual int64_t signal_subscribe(const char* sender, const char* path, const char* iface, const char* name, dbus_listener_iface* listener) = 0;
-// virtual void signal_unsubscribe(int64_t subscription_id) = 0;
}; /* class conv::dbus_server */
} /* namespace ctx */
conv::request *recv_request = NULL;
try{
recv_request = new conv::request(req_type, DEFAULT_APP_ID, req_id, subject, input, sender, creds, invocation);
-// recv_request = new conv::request(req_type, app_id, req_id, subject, input, sender, NULL, invocation);
} catch (std::bad_alloc& ba) {
_E("Memory Allocation Failed..");
g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", CONV_ERROR_INVALID_OPERATION, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
IF_FAIL_VOID_TAG(STR_EQ(obj_path, DBUS_PATH), _W, "Invalid path: %s", obj_path);
IF_FAIL_VOID_TAG(STR_EQ(iface, DBUS_IFACE), _W, "Invalid interface: %s", obj_path);
- if (STR_EQ(method_name, METHOD_REQUEST)) {
+ if (STR_EQ(method_name, METHOD_REQUEST))
handle_request(conn, sender, param, invocation);
- } else {
+ else
_W("Invalid method: %s", method_name);
- }
_D("end of handle_method_call");
}
void conv::dbus_server_impl::release()
{
- if (dbus_connection) {
+ if (dbus_connection)
g_dbus_connection_flush_sync(dbus_connection, NULL, NULL);
- }
if (dbus_owner_id > 0) {
g_bus_unown_name(dbus_owner_id);
g_dbus_connection_call(dbus_connection, dest, DBUS_PATH, DBUS_IFACE,
METHOD_RESPOND, param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, NULL, &err);
- if (err != NULL)
- {
+ if (err != NULL) {
_D("dbus_connection_call Error msg : %s", err->message);
-
HANDLE_GERROR(err);
}
- else
- {
- _D("err is NULL");
- }
}
static void handle_call_result(GObject *source, GAsyncResult *res, gpointer user_data)
#include "common.h"
#include "util.h"
+#include <algorithm>
+#include <functional>
+
+using namespace std;
static conv::discovery_manager_impl *_instance = NULL;
typedef std::map<std::string, conv::device_iface*> discovered_ones_map_t;
static discovered_ones_map_t discovered_results;
-using namespace std;
-
conv::discovery_manager_impl::discovery_manager_impl()
{
count_discovery_request = 0;
int conv::discovery_manager_impl::init()
{
_D("Discovery_Manager Init!!..");
- register_provider(new conv::smartview_discovery_provider());
- register_provider(new conv::ble_discovery_provider());
- register_provider(new conv::iotcon_discovery_provider());
+ IF_FAIL_RETURN_TAG(register_provider(new(std::nothrow) conv::smartview_discovery_provider()) == CONV_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "smartview_discover_provider register failed");
+ IF_FAIL_RETURN_TAG(register_provider(new(std::nothrow) conv::ble_discovery_provider()) == CONV_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "ble_discovery_provider register failed");
+ IF_FAIL_RETURN_TAG(register_provider(new(std::nothrow) conv::iotcon_discovery_provider()) == CONV_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "iotcon_discovery_provider register failed");
request_map.clear();
request_timer_map.clear();
-
return CONV_ERROR_NONE;
}
int conv::discovery_manager_impl::release()
{
- for (discovery_provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it) {
+ for (discovery_provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it)
(*it)->stop();
- }
- for (discovery_provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it) {
+ for (discovery_provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it)
delete *it;
- }
provider_list.clear();
{
// 1. When no client is using discovery, it should be stopped
_D("notify_time_up.. with current discovery count :%d", count_discovery_request);
- if (--count_discovery_request == 0)
- {
+ if (--count_discovery_request == 0) {
stop_discovery();
}
// 2. Reqeust to stop timer related to client in the timer_map
timer_map_t::iterator timer_itr = request_timer_map.find(client);
- if (timer_itr != request_timer_map.end())
- {
+ if (timer_itr != request_timer_map.end()) {
int timer_id = timer_itr->second;
_D("timer_id[%d]", timer_id);
conv::util::misc_stop_timer(reinterpret_cast<void*> (timer_id));
// 3. Notify the client that the requested discovery has been finished
request_map_t::iterator request_itr = request_map.find(client);
- if (request_itr != request_map.end())
- {
+ if (request_itr != request_map.end()) {
json no_data;
request* cur_Req = request_itr->second;
cur_Req->publish(CONV_DISCOVERY_FINISHED, no_data);
int conv::discovery_manager_impl::handle_request(request* request_obj)
{
_D("handle_request called .. request:%x _instance:%x", request_obj, _instance);
- if ( _instance )
- {
- if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_START) )
- {
+ if ( _instance ) {
+ if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_START) ) {
if ( !conv::privilege_manager::is_allowed(request_obj->get_creds(), CONV_PRIVILEGE_INTERNET) ||
- !conv::privilege_manager::is_allowed(request_obj->get_creds(), CONV_PRIVILEGE_BLUETOOTH) )
- {
+ !conv::privilege_manager::is_allowed(request_obj->get_creds(), CONV_PRIVILEGE_BLUETOOTH) ) {
_E("permission denied");
request_obj->reply(CONV_ERROR_PERMISSION_DENIED);
delete request_obj;
count_discovery_request++;
for (discovery_provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it)
- {
// Discovery Provider Starts!!!!
(*it)->start();
- }
const char* client = request_obj->get_sender();
- if (client == NULL)
- {
+ if (client == NULL) {
_D("client is empty..");
return CONV_ERROR_INVALID_OPERATION;
}
request_map_t::iterator map_itr = request_map.find(string(client));
- if ( map_itr == request_map.end())
- {
+ if ( map_itr == request_map.end()) {
// current request inserted into request_map..
request_map.insert(request_map_t::value_type(string(client), request_obj));
_D("client[%s] inserted into request_map", client);
- }
- else
- {
+ } else {
_D("client[%s] already in request_map.. Replace!!!", client);
map_itr->second = request_obj;
}
// request timer
gpointer *param = g_new0(gpointer, 2);
- param[0] = reinterpret_cast<void*>(new string(client));
+ param[0] = reinterpret_cast<void*>(new(std::nothrow) string(client));
param[1] = reinterpret_cast<void*>(this);
int timer_id = reinterpret_cast<int>(conv::util::misc_start_timer(timer_worker, timeout, param));
request_timer_map[ string(client) ] = timer_id;
request_obj->reply(CONV_ERROR_NONE);
-
- //delete request_obj;
} else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_STOP) ){
stop_discovery();
request_obj->reply(CONV_ERROR_NONE);
- //delete request_obj;
+ delete request_obj;
}
return CONV_ERROR_NONE;
{
if (!provider) {
_E("Provider NULL");
- throw static_cast<int>(CONV_ERROR_INVALID_PARAMETER);
+ return CONV_ERROR_INVALID_PARAMETER;
}
provider_list.push_back(provider);
+ if (provider->set_manager(this) != CONV_ERROR_NONE) {
+ _E("Provider set_manager failed");
+ return CONV_ERROR_INVALID_OPERATION;
+ }
+
if (provider->init() != CONV_ERROR_NONE) {
_E("Provider initialization failed");
- throw CONV_ERROR_INVALID_OPERATION;
+ return CONV_ERROR_INVALID_OPERATION;
}
- if (provider->set_manager(this) != CONV_ERROR_NONE) {
- _E("Provider set_manager failed");
- throw CONV_ERROR_INVALID_OPERATION;
- }
return CONV_ERROR_NONE;
}
int conv::discovery_manager_impl::convert_device_into_json(conv::device_iface* device_info, json* json_data)
return CONV_ERROR_NONE;
}
-int conv::discovery_manager_impl::append_discovered_result(conv::device_iface* disc_device, conv::service_iface* disc_service)
+static bool serviceComparision(conv::service_iface* obj, int serviceType)
+{
+ if (obj->getServiceType() == serviceType)
+ return true;
+ else
+ return false;
+}
+
+// return value : the number of new services
+int conv::discovery_manager_impl::merge_exclude_services(conv::device_iface* org_device, conv::device_iface* new_device)
+{
+ int new_serv_count = 0;
+ std::list<service_iface*> org_serv_list;
+ std::list<service_iface*> new_serv_list;
+
+ org_device->get_services_list(&org_serv_list);
+ _D("[%d] Services in the origin device info[%s]", org_serv_list.size(), org_device->getName().c_str() );
+ new_device->get_services_list(&new_serv_list);
+ _D("[%d] Services in the new device info[%s]", new_serv_list.size(), new_device->getName().c_str() );
+
+ std::list<service_iface*>::iterator new_iter = new_serv_list.begin();
+ for (; new_iter != new_serv_list.end(); ++new_iter) {
+ service_iface* cur_serv = *new_iter;
+ std::list<service_iface*>::iterator org_iter =
+ std::find_if(org_serv_list.begin(), org_serv_list.end(), std::bind(serviceComparision, std::placeholders::_1, cur_serv->getServiceType()));
+ if (org_iter != org_serv_list.end()) {
+ // already exists in org_device.. means it's not new!.. so remove the service from new!!
+ new_device->remove_service(cur_serv);
+ // add the service into the original device
+ org_device->add_service(cur_serv);
+ _D("Service[%d] has been already found in Device[%s]", cur_serv->getServiceType(), org_device->getName().c_str() );
+ } else {
+ _D("New Service[%d] found in Device[%s]", cur_serv->getServiceType(), org_device->getName().c_str() );
+ new_serv_count++;
+ }
+ }
+ return new_serv_count;
+}
+
+int conv::discovery_manager_impl::append_discovered_result(conv::device_iface* disc_device)
{
_D("Append Discovered Result.. Device:%x, Service:%x");
IF_FAIL_RETURN_TAG((disc_device != NULL), CONV_ERROR_INVALID_PARAMETER, _E, "device_iface not initialized..");
_D("Check if key[%s] exists in discovered_results", disc_device->getId().c_str());
discovered_ones_map_t::iterator itor_disc;
itor_disc = discovered_results.find(disc_device->getId());
- if (itor_disc != discovered_results.end())
- {
+ if (itor_disc != discovered_results.end()) {
_D("update discovered device's info [%s]", disc_device->getId().c_str());
device_iface* cur_device = itor_disc->second;
- cur_device->add_service(disc_service);
- }
- else
- {
+
+ int count_new_services = merge_exclude_services(cur_device, disc_device);
+ if (count_new_services == 0)
+ return CONV_ERROR_NONE;
+ } else {
_D("newbie!! discovered device's info [%s]", disc_device->getId().c_str());
discovered_results.insert(discovered_ones_map_t::value_type(disc_device->getId(), disc_device));
}
convert_device_into_json(disc_device, &device_json);
_D("Convert service info into json type..");
- if (disc_service !=NULL)
- convert_service_into_json(disc_service, &device_json);
- else
- {
- typedef std::list<service_iface*> serv_list_t;
- serv_list_t serv_list;
- disc_device->get_services_list(&serv_list);
-
- for (serv_list_t::iterator iterPos = serv_list.begin(); iterPos != serv_list.end(); ++iterPos)
- {
- service_iface* cur_serv = *iterPos;
- convert_service_into_json(cur_serv, &device_json);
- }
+ typedef std::list<service_iface*> serv_list_t;
+ serv_list_t serv_list;
+ disc_device->get_services_list(&serv_list);
+
+ for (serv_list_t::iterator iterPos = serv_list.begin(); iterPos != serv_list.end(); ++iterPos) {
+ service_iface* cur_serv = *iterPos;
+ convert_service_into_json(cur_serv, &device_json);
}
// 1.set data info about device
_D("Iterate through request_map to publish..");
int index = 0;
request_map_t::iterator IterPos;
- for (IterPos = request_map.begin(); IterPos != request_map.end(); ++IterPos)
- {
+ for (IterPos = request_map.begin(); IterPos != request_map.end(); ++IterPos) {
request* cur_Req = IterPos->second;
cur_Req->publish(CONV_ERROR_NONE, device_json);
int handle_request(request* request_obj);
// discovery_manager aggregates devices with services which have been discovered through the registered discover providers
- int append_discovered_result(device_iface* disc_device, service_iface* disc_service);
+ int append_discovered_result(device_iface* disc_device);
int notify_time_up(std::string client);
int stop_discovery();
int start_discovery();
int set_discovery_filter(request* req_obj);
int isvalid_discovery_on_filter(json& filter_json);
int checkBoundaryForTimeout(int givenTimeout);
+ int merge_exclude_services(conv::device_iface* org_device, conv::device_iface* new_device);
};
namespace discovery_manager {
bool _cb_discovered_peers_impl(wifi_direct_discovered_peer_info_s* peer, void* user_data)
{
-// conv::ble_discovery_provider* disc_provider = (conv::ble_discovery_provider*)user_data;
-
-// conv::service *conv_service = new conv::service;
-
#if 0//def TEMP_TEST
static int first = 1;
if (!strcmp(peer->device_name, "D2d note" ) ) {
#endif
#if 0 // TODO: make and notice if it's device support d2d
+ conv::ble_discovery_provider* disc_provider = (conv::ble_discovery_provider*)user_data;
+ conv::service *conv_service = new(std::nothrow) conv::service;
+
conv_service->setName(peer->device_name);
conv_service->setVersion("0.0");
conv_service->setType("");
if (owner) {
wifi_direct_get_ip_address(&ip_addr);
if (NULL != ip_addr) {
- sprintf(status, "<color=#FFFFFF>GO - IP : %s", ip_addr);
+ snprintf(status, sizeof(status), "<color=#FFFFFF>GO - IP : %s", ip_addr);
free(ip_addr);
}
} else {
wifi_direct_get_ip_address(&ip_addr);
if (NULL != ip_addr) {
- sprintf(status, "<color=#FFFFFF>STA - IP : %s", ip_addr);
+ snprintf(status, sizeof(status), "<color=#FFFFFF>STA - IP : %s", ip_addr);
free(ip_addr);
}
}
} else {
- if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT)
- _D("Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT");
- else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED)
- _D("Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED");
- else if (error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED)
- _D("Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED");
+ _E("Error : wifi direct (Error Code:%d)", error_code);
}
}
break;
break;
default:
+ _D("event - %d", connection_state);
break;
}
}
int conv::ble_discovery_provider::start()
{
- return start_wfd_discovery();
-}
-
-int conv::ble_discovery_provider::stop()
-{
+ //return start_wfd_discovery();
return CONV_ERROR_NONE;
}
-int conv::ble_discovery_provider::set_manager(discovery_manager_impl* disc_manager)
+int conv::ble_discovery_provider::stop()
{
- discovery_manager = disc_manager;
return CONV_ERROR_NONE;
}
// insert into cache
string cache_key = conv_service->getId(); // Serivce URI as Map Key..
- if (cache.find(cache_key) == cache.end())
- {
+ if (cache.find(cache_key) == cache.end()) {
_D("conv_service with key[%s] does not exist..so go into the cache", cache_key.c_str());
cache.insert(map<string, conv::service*>::value_type(cache_key, conv_service));
return CONV_ERROR_NONE;
- }
- else
- {
+ } else {
_D("conv_service with key[%s] already exists..", cache_key.c_str());
- return 1; // temp..
+ return 1;
}
}
if (!alreadyExisted) {
//the discovered one is NEW!!
- discovery_manager->append_discovered_result(NULL, conv_service);
+ // TO-DO : need to re-write this code
+ //_discovery_manager->append_discovered_result(NULL, conv_service);
}
return CONV_ERROR_NONE;
#include "../discovery_provider_base.h"
#include "../request.h"
-#include "../service.h"
+#include "smartview/service.h"
namespace conv {
class ble_discovery_provider : public discovery_provider_base {
int start();
int stop();
- int set_manager(discovery_manager_impl* disc_manager);
int notice_discovered(conv::service* conv_service);
private:
- discovery_manager_impl* discovery_manager;
-
- // for double check..
map <string, conv::service*> cache;
int checkExistence(conv::service* conv_service);
*/
#include "device_adapter.h"
+#include <algorithm>
+#include <functional>
using namespace std;
{
}
+static bool serviceComparision(conv::service_iface* obj, int serviceType)
+{
+ if (obj->getServiceType() == serviceType)
+ return true;
+ else
+ return false;
+}
+
int conv::device_adapter::add_service(service_iface* service_obj)
{
- service_list.push_back(service_obj);
+ service_list_t::iterator itr;
+ itr = std::find_if(service_list.begin(), service_list.end(), std::bind(serviceComparision, std::placeholders::_1, service_obj->getServiceType()));
+
+ if (itr == service_list.end()) {
+ _D("New Service Type[%d] added to the device[%s]",
+ service_obj->getServiceType(), getId().c_str());
+ service_list.push_back(service_obj);
+ } else {
+ _D("Service Type[%d] is already included in device[%s] so skipped!",
+ service_obj->getServiceType(), getId().c_str());
+ }
return CONV_ERROR_NONE;
}
int conv::device_adapter::get_services_list(std::list<service_iface*> *list)
{
- for (service_list_t::iterator iterPos = service_list.begin(); iterPos != service_list.end(); ++iterPos)
- {
+ for (service_list_t::iterator iterPos = service_list.begin(); iterPos != service_list.end(); ++iterPos) {
list->push_back(*iterPos);
}
return CONV_ERROR_NONE;
static discovery_complete_list_t discovery_complete_list;
static discovery_process_map_t discovery_process_map;
-static conv::discovery_manager_impl* disc_manager;
-
conv::iotcon_discovery_provider::iotcon_discovery_provider()
{
}
_E("Failed iotcon_connect... Error:%d", ret);
}
- if (resource_h_map != NULL) delete resource_h_map;
- resource_h_map = new (std::nothrow) resource_h_map_t;
+ if (resource_h_map != NULL)
+ delete resource_h_map;
+ resource_h_map = new(std::nothrow) resource_h_map_t;
return CONV_ERROR_NONE;
}
{
iotcon_deinitialize();
- if (resource_h_map != NULL) delete resource_h_map;
+ if (resource_h_map != NULL)
+ delete resource_h_map;
return CONV_ERROR_NONE;
}
discovery_complete_list_t::iterator itor;
_D("Check if key[%s] already exists in complete_list", discoveryKey.c_str());
itor = find(discovery_complete_list.begin(), discovery_complete_list.end(), discoveryKey);
- if (itor != discovery_complete_list.end() ) return; // Already done pushing upwards..
+ if (itor != discovery_complete_list.end() )
+ return; // Already done pushing upwards..
// Retreive info from process_map..
resource_handle cur_resource_h;
discovery_process_map_t::iterator itor_process;
itor_process = discovery_process_map.find(discoveryKey);
_D("Check if key[%s] exists in process_map", discoveryKey.c_str());
- if (itor_process != discovery_process_map.end())
+ if (itor_process != discovery_process_map.end()) {
cur_resource_h = itor_process->second;
- else
- {
+ } else {
_D("Not supposed to happen");
return;
}
char* service_json_char = NULL;
ret = iotcon_state_get_str(recv_state, "service_json", &service_json_char);
- if (service_json_char == NULL)
- {
+ if (service_json_char == NULL) {
_D("service_json does not exist...");
service_json_char = const_cast<char*>("");
}
_D("on_response : device_id[%s] device_name[%s] device_type[%s] version[%s] service_list[%s]"
, device_id, device_name, device_type, version, service_list);
- if (disc_manager != NULL)
- {
+ if (_discovery_manager != NULL) {
device_adapter* device = new(std::nothrow) device_adapter (cur_resource_h);
int num_service = service_list_json.array_get_size(NULL, "service_list");
- for (int index = 0; index < num_service; index++)
- {
+ for (int index = 0; index < num_service; index++) {
int serv_type_int;
json cur_service_json;
bool ret = service_list_json.get_array_elem(NULL, "service_list", index, &cur_service_json);
- if (ret != true)
- {
+ if (ret != true) {
_D("json get array elem with service_list error..");
continue;
}
device->add_service(serv);
}
- disc_manager->append_discovered_result(device, NULL);
+ _discovery_manager->append_discovered_result(device);
}
discovery_complete_list.push_back(discoveryKey);
_D("On Received Detail Info.. with type[%d]", request_type);
switch (request_type) {
- case IOTCON_REQUEST_GET :
- _on_response_get(resource, response, NULL);
- break;
- case IOTCON_REQUEST_PUT:
- case IOTCON_REQUEST_POST:
- case IOTCON_REQUEST_DELETE:
- _D("Not supported request_type");
- break;
- default:
- _E("Invalid Request Type");
- return;
+ case IOTCON_REQUEST_GET :
+ _on_response_get(resource, response, NULL);
+ break;
+ case IOTCON_REQUEST_PUT:
+ case IOTCON_REQUEST_POST:
+ case IOTCON_REQUEST_DELETE:
+ _D("Not supported request_type");
+ break;
+ default:
+ _E("Invalid Request Type");
+ return;
}
}
iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
resource_handle res_handle;
- // uri_path
+ // uri_path
res_handle.set_uri_path(string(resource_uri_path));
- // host_address
+ // host_address
res_handle.set_host_address(string(resource_host));
- // resource types
+ // resource types
iotcon_resource_types_foreach(resource_types, _get_resource_foreach_types, (void*)(&res_handle.get_types()) );
// Add resource handle into Temp Cache
return CONV_ERROR_NONE;
}
-int conv::iotcon_discovery_provider::set_manager(discovery_manager_impl* disco_manager)
-{
- _D("set discovery manager..");
- disc_manager = disco_manager;
-
- return CONV_ERROR_NONE;
-}
-
int start();
int stop();
- int set_manager(discovery_manager_impl* disc_manager);
static int notice_discovered(service_iface* service);
};
}
#include "device.h"
#include "log.h"
#include "d2d_conv_manager.h"
+#include <algorithm>
+#include <functional>
using namespace std;
{
}
+template <typename T>
+struct GenericComparator
+{
+ typedef int (T::*GETTER)() const;
+ GETTER m_getterFunc;
+ int m_data;
+ GenericComparator(GETTER getterFunc, int data)
+ {
+ m_getterFunc = getterFunc;
+ m_data = data;
+ }
+ bool operator()(const T & obj)
+ {
+ if ((obj.*m_getterFunc)() == m_data)
+ return true;
+ else
+ return false;
+ }
+};
+
+static bool serviceComparision(conv::service_iface* obj, int serviceType)
+{
+ if (obj->getServiceType() == serviceType)
+ return true;
+ else
+ return false;
+}
+
int conv::device::add_service(service_iface* service_obj)
{
- service_list.push_back(service_obj);
+ service_list_t::iterator itr;
+ itr = std::find_if(service_list.begin(), service_list.end(), std::bind(serviceComparision, std::placeholders::_1, service_obj->getServiceType()));
+
+ if (itr == service_list.end()) {
+ _D("New Service Type[%d] added to the device[%s]",
+ service_obj->getServiceType(), getId().c_str());
+ service_list.push_back(service_obj);
+ } else {
+ _D("Service Type[%d] is already included in device[%s] so skipped!",
+ service_obj->getServiceType(), getId().c_str());
+ }
return CONV_ERROR_NONE;
}
int conv::device::remove_service(service_iface* service_obj)
{
+ service_list.remove(service_obj);
return CONV_ERROR_NONE;
}
#include <string>
#include <vector>
-#include "service_iface.h"
-#include "conv_json.h"
+#include "../../service_iface.h"
+#include "../../conv_json.h"
-#include "device_iface.h"
+#include "../../device_iface.h"
namespace conv {
class device : public device_iface {
public:
- typedef std::vector<service_iface*> service_list_t;
+ typedef std::list<service_iface*> service_list_t;
device();
~device();
int conv::service::getServiceType()
{
- return 0; //string("oic.r.tizen.app-communication");
+ return 0;
}
string conv::service::getServiceInfo()
#define __CONV_SERVICE_H__
#include <string>
-#include "conv_json.h"
-#include "service_iface.h"
+#include "../../conv_json.h"
+#include "../../service_iface.h"
using namespace std;
int getServiceType();
string getServiceInfo();
- //
void setName(string name);
void setVersion(string version);
void setType(string type);
int service_type;
string service_info;
- //..
string service_version;
string service_id;
string service_uri;
#include "smartview_discovery_provider.h"
#include "../discovery_mgr_impl.h"
-#include "../service.h"
-#include "../device.h"
#include "../conv_json.h"
#include "../util.h"
conv::smartview_discovery_provider* disc_provider;
public:
- void set_discovery_manager(conv::discovery_manager_impl* disc_manager)
+ void set_discovery_manager(conv::discovery_manager_impl* discovery_manager)
{
- this->disc_manager = disc_manager;
+ this->disc_manager = discovery_manager;
}
- void set_discovery_provider(conv::smartview_discovery_provider* disc_provider)
+ void set_discovery_provider(conv::smartview_discovery_provider* discovery_provider)
{
- this->disc_provider = disc_provider;
+ this->disc_provider = discovery_provider;
}
void onStart() {
int conv::smartview_discovery_provider::init()
{
_D("smartview_discovery init");
- search = new Search();
- if (listener_impl == NULL)
- {
- listener_impl = new SearchListenerImpl;
+ search = new(std::nothrow) Search();
+ ASSERT_ALLOC(search);
+ if (listener_impl == NULL) {
+ listener_impl = new(std::nothrow) SearchListenerImpl;
+ if ( listener_impl == NULL) {
+ _E("listener_impl allocation failed");
+ delete search;
+ return CONV_ERROR_OUT_OF_MEMORY;
+ }
listener_impl->set_discovery_provider(this);
+ listener_impl->set_discovery_manager(_discovery_manager);
}
search->setSearchListener(listener_impl);
int conv::smartview_discovery_provider::release()
{
- if ( search != NULL )
- {
+ if ( search != NULL ) {
delete search;
}
return CONV_ERROR_NONE;
}
-int conv::smartview_discovery_provider::set_manager(discovery_manager_impl* disc_manager)
-{
- discovery_manager = disc_manager;
-
- listener_impl->set_discovery_manager(disc_manager);
- return CONV_ERROR_NONE;
-}
-
conv::device* conv::smartview_discovery_provider::convert_into_conv_device(Service* smartview_service)
{
string serv_name, serv_version, serv_type, serv_id, serv_uri;
device_info->setId(serv_id);
device_info->setName(serv_name);
- /*
- conv::service* service_info = new(std::nothrow) conv::service;
- service_info->setVersion (serv_version);
- service_info->setType (serv_type);
- service_info->setUri (serv_uri);
-
- device_info->add_service (service_info);
- */
-
return device_info;
}
json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SERVICE_DATA_VERSION, serv_version);
json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SERVICE_DATA_TYPE, serv_type);
- conv::service *conv_service = new conv::service;
+ conv::service *conv_service = new(std::nothrow) conv::service;
+ if ( conv_service == NULL ) {
+ _E("conv_service allocation failed");
+ return NULL;
+ }
conv_service->setName(serv_name);
conv_service->setVersion(serv_version);
conv_service->setType(serv_type);
if (!alreadyExisted) {
//the discovered one is NEW!!
- discovery_manager->append_discovered_result(conv_device, conv_service);
+ _discovery_manager->append_discovered_result(conv_device);
}
return CONV_ERROR_NONE;
#include "../discovery_provider_base.h"
#include "../request.h"
-#include "../service.h"
-#include "../device.h"
+#include "smartview/service.h"
+#include "smartview/device.h"
#include <msf-api/Search.h>
#include <msf-api/Service.h>
int start();
int stop();
- int set_manager(discovery_manager_impl* disc_manager);
int notice_discovered(Service *service);
-
private:
Service service;
Search* search;
- discovery_manager_impl* discovery_manager;
map <string, conv::service*> cache; // for double check
--- /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 "discovery_mgr_impl.h"
+
+conv::discovery_manager_impl* conv::discovery_provider_base::_discovery_manager = NULL;
+
+int conv::discovery_provider_base::set_manager(discovery_manager_impl* discovery_manager)
+{
+ _discovery_manager = discovery_manager;
+ return CONV_ERROR_NONE;
+}
virtual int start() = 0;
virtual int stop() = 0;
- virtual int set_manager(discovery_manager_impl* discovery_manager) = 0;
+ int set_manager(discovery_manager_impl* discovery_manager);
+
+ protected:
+ static discovery_manager_impl* _discovery_manager;
}; /* class discovery_provider_base */
}
virtual int init() = 0;
virtual int release() = 0;
virtual int handle_request(request* request_obj) = 0;
-// virtual int publish(const char* subject, json data_updated, json option) = 0;
}; /* class manager_iface */
}
+++ /dev/null
-[D-BUS Service]
-Name=@DBUS_INTERFACE@
-Exec=@BIN_INSTALL_DIR@/d2d-conv-managerd
-
-Libs: -L${libdir} -pthread
conv::request::~request()
{
- if ( __creds != NULL )
- {
+ if ( __creds != NULL ) {
delete __creds;
}
}
int result = CONV_ERROR_INVALID_OPERATION;
switch (request_obj->get_type()) {
- case REQ_SUBSCRIBE:
- _D("Requested type : REQ_SUBSCRIBE..");
- if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_RECV) )
- {
- result = service_manager::handle_request(request_obj);
- }
- else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_START) )
- {
- result = connection_manager::handle_request(request_obj);
- }
- break;
- case REQ_UNSUBSCRIBE:
- if (!strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_RECV) )
- {
- result = service_manager::handle_request(request_obj);
- }
- else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_START) )
- {
- result = connection_manager::handle_request(request_obj);
- }
- break;
- case REQ_READ:
- break;
- case REQ_READ_SYNC:
- break;
- case REQ_WRITE:
- _D("Requested type : REQ_WRITE..");
- if (!strcmp (request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_START) || !strcmp (request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_STOP))
- {
- return discovery_manager::handle_request (request_obj);
- }
- else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_START) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_STOP)
- || !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_SET) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_GET))
- {
- result = service_manager::handle_request(request_obj);
- }
- else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_START) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_STOP) )
- {
- result = connection_manager::handle_request(request_obj);
- }
- break;
- case REQ_SUPPORT:
- break;
- default:
- _E("Invalid type of request");
- request_obj->reply(result);
- delete request_obj;
+ case REQ_SUBSCRIBE:
+ _D("Requested type : REQ_SUBSCRIBE..");
+ if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_RECV) )
+ result = service_manager::handle_request(request_obj);
+ else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_START) )
+ result = connection_manager::handle_request(request_obj);
+ break;
+ case REQ_UNSUBSCRIBE:
+ if (!strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_RECV) )
+ result = service_manager::handle_request(request_obj);
+ else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_START) )
+ result = connection_manager::handle_request(request_obj);
+ break;
+ case REQ_READ:
+ break;
+ case REQ_READ_SYNC:
+ break;
+ case REQ_WRITE:
+ _D("Requested type : REQ_WRITE..");
+ if (!strcmp(request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_START) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_DISCOVERY_STOP))
+ return discovery_manager::handle_request (request_obj);
+ else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_START) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_STOP)
+ || !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_SET) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_COMMUNICATION_GET))
+ result = service_manager::handle_request(request_obj);
+ else if ( !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_START) || !strcmp(request_obj->get_subject(), CONV_SUBJECT_CONNECTION_STOP) )
+ result = connection_manager::handle_request(request_obj);
+ break;
+ case REQ_SUPPORT:
+ break;
+ default:
+ _E("Invalid type of request");
+ request_obj->reply(result);
+ delete request_obj;
}
return result;
int conv::service_manager_impl::init()
{
- register_provider(new conv::app_comm_service_provider());
- register_provider(new conv::remote_app_control_service_provider());
+ IF_FAIL_RETURN_TAG(register_provider(new(std::nothrow) conv::app_comm_service_provider()) == CONV_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "app_comm_service_provider register failed");
+ IF_FAIL_RETURN_TAG(register_provider(new(std::nothrow) conv::remote_app_control_service_provider()) == CONV_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "remote_app_control_service_provider register failed");
- //TBD
register_discovery_info();
return CONV_ERROR_NONE;
}
{
if (!provider) {
_E("Provider NULL");
- throw static_cast<int>(CONV_ERROR_INVALID_PARAMETER);
+ return CONV_ERROR_INVALID_PARAMETER;
}
provider_list.push_back(provider);
if (provider->init() != CONV_ERROR_NONE) {
_E("Provider initialization failed");
- throw CONV_ERROR_INVALID_OPERATION;
+ return CONV_ERROR_INVALID_OPERATION;
}
return CONV_ERROR_NONE;
for (service_provider_list_t::iterator it = provider_list.begin(); it != provider_list.end(); ++it) {
json service_info;
- if ( (*it)->get_service_info_for_discovery(&service_info) == CONV_ERROR_NONE )
- {
+ if ((*it)->get_service_info_for_discovery(&service_info) == CONV_ERROR_NONE) {
service_json->array_append(NULL, "service_list", service_info);
}
}
return;
}
- if (IOTCON_REQUEST_GET == type)
- {
+ if (IOTCON_REQUEST_GET == type) {
iotcon_representation_h resp_repr;
_I("GET request");
class app_comm_service_listener : public OnConnectListener, public OnDisconnectListener, public OnClientConnectListener, public OnClientDisconnectListener,
public OnMessageListener, public OnErrorListener {
public:
- conv::request* request_obj;
+ conv::request** request_obj;
string uri;
string channel_id;
}
void onClientConnect(Client client){
- _D("onClientDisconnect Called");
+ _D("onClientConnect Called");
publish_response(CONV_ERROR_NONE, "onClientConnect", &client);
}
void onMessage(Message message){
_D("onMessage Called");
- if ( request_obj != NULL )
+ if ((*request_obj) != NULL)
{
_D(RED("publishing_response"));
json result;
- json payload;
json message_json;
json description;
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_json = payload_str;
- message_json.set(NULL, CONV_JSON_PAYLOAD, payload_json);
- message_json.set(NULL, CONV_JSON_PAYLOAD_SIZE, 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, "onMessage");
payload.set(NULL, CONV_JSON_MESSAGE, message_json);
- description = request_obj->get_description();
+ 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);
- request_obj->publish(CONV_ERROR_NONE, result);
+ (*request_obj)->publish(CONV_ERROR_NONE, result);
}
}
bool isHost = client->isHost();
int connecttime = client->getConnectTime();
- if ( request_obj != NULL )
+ if ((*request_obj) != NULL)
{
_D(RED("publishing_response"));
json result;
payload.set(NULL, CONV_JSON_RESULT_TYPE, result_type);
payload.set(NULL, CONV_JSON_CLIENT, client_json);
- description = request_obj->get_description();
+ 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);
- request_obj->publish(error, result);
+ (*request_obj)->publish(error, result);
}
}
};
public:
Channel* application;
app_comm_service_listener service_listener;
+ Service local_service;
};
typedef vector<application_info*> application_info_list_t;
app_comm_service_info *svc_info = NULL;
- if (is_local == 1)
- {
+ if (is_local == 1) {
service_info_base* svc_info_base = client_obj->get_service_info(_type, "LOCAL_HOST");
if ( svc_info_base != NULL ) {
_D("local service instance already exists");
svc_info = reinterpret_cast<app_comm_service_info*>(svc_info_base);
- if (svc_info == NULL)
- {
+ if (svc_info == NULL) {
_D("casting failed");
return CONV_ERROR_INVALID_OPERATION;
}
- }
- else
- {
+ } else {
_D("allocating new service instance for local service");
- svc_info = new app_comm_service_info();
+ svc_info = new(std::nothrow) app_comm_service_info();
+ ASSERT_ALLOC(svc_info);
svc_info->is_local = true;
client_obj->add_service_info(_type, "LOCAL_HOST", (service_info_base*)svc_info);
_D("service instance already exists");
svc_info = reinterpret_cast<app_comm_service_info*>(svc_info_base);
- if (svc_info == NULL)
- {
+ if (svc_info == NULL) {
_D("casting failed");
return CONV_ERROR_INVALID_OPERATION;
}
- }
- else
- {
+ } else {
_D("allocating new service instance");
- svc_info = new app_comm_service_info();
+ svc_info = new(std::nothrow) app_comm_service_info();
+ ASSERT_ALLOC(svc_info);
_D("uri : %s", uri.c_str());
- svc_info->service_obj = new Service(id, version, name, type, uri);
+ svc_info->service_obj = new(std::nothrow) Service(id, version, name, type, uri);
+ ASSERT_ALLOC(svc_info->service_obj);
svc_info->is_local = false;
client_obj->add_service_info(_type, id, (service_info_base*)svc_info);
for (application_info_list_t::iterator iter = svc_info->application_info_list.begin(); iter != svc_info->application_info_list.end(); ++iter) {
_D("iteration");
- if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) )
- {
- if ( (*iter)->application != NULL )
- {
+ if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) ) {
+ if ( (*iter)->application != NULL ) {
_D("already started");
// check if it's connected and re-try if it's not
return CONV_ERROR_INVALID_OPERATION;
}
}
- if ( app_info == NULL )
- {
- app_info = new application_info();
+ if ( app_info == NULL ) {
+ app_info = new(std::nothrow) application_info();
+ ASSERT_ALLOC(app_info);
app_info->service_listener.uri = uri;
app_info->service_listener.channel_id = channel_id;
}
// if it's local -> server application
- if ( svc_info->is_local )
- {
+ if ( svc_info->is_local ) {
_D("COMMUNCATION_START : local channel. channel_id : %s", channel_id.c_str());
- Channel* application = Service::getLocal().createChannel(channel_id);
+
+ app_info->local_service = Service::getLocal();
+
+ Channel* application = app_info->local_service.createChannel(channel_id);
// add listeners
- app_info->service_listener.request_obj = svc_info->registered_request;
+ app_info->service_listener.request_obj = &(svc_info->registered_request);
application->setonConnectListener(&app_info->service_listener);
application->setonClientConnectListener(&app_info->service_listener);
application->setonClientDisconnectListener(&app_info->service_listener);
svc_info->application_info_list.push_back(app_info);
} else {
_D("COMMUNCATION_START : uri : %s, channel_id : %s", uri.c_str(), channel_id.c_str());
- Application* application = new Application(svc_info->service_obj, uri, channel_id);
+ Application* application = new(std::nothrow) Application(svc_info->service_obj, uri, channel_id);
+ ASSERT_ALLOC(application);
// add listeners
- app_info->service_listener.request_obj = svc_info->registered_request;
+ app_info->service_listener.request_obj = &(svc_info->registered_request);
application->setonConnectListener(&app_info->service_listener);
application->setonClientConnectListener(&app_info->service_listener);
application->setonClientDisconnectListener(&app_info->service_listener);
for (application_info_list_t::iterator iter = svc_info->application_info_list.begin(); iter != svc_info->application_info_list.end(); ++iter) {
_D("%s, %s", (*iter)->service_listener.uri.c_str(), (*iter)->service_listener.channel_id.c_str());
- if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) )
- {
+ if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) ) {
application_info *app_info = *iter;
_D("COMMUNCATION_STOP : uri : %s, channel_id : %s", uri.c_str(), channel_id.c_str());
- if ( *iter == NULL )
- {
+ if ( *iter == NULL ) {
_D("iter is NULL");
}
- if ( svc_info->is_local )
- {
+ if ( svc_info->is_local ) {
result_disconnect.app_info = app_info;
app_info->application->set_disconnect_result(NULL);
app_info->application->disconnect();
for (application_info_list_t::iterator iter = svc_info->application_info_list.begin(); iter != svc_info->application_info_list.end(); ++iter) {
_D("iteration");
- if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) )
- {
- if ( (*iter)->application != NULL )
- {
+ if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) ) {
+ if ( (*iter)->application != NULL ) {
_D("app_info exists and application instance exists");
app_info = (*iter);
Clients* client_list = app_info->application->getclients();
- if ( svc_info->registered_request == NULL)
- {
+ if ( svc_info->registered_request == NULL) {
_D("No callback is registered");
request_obj->reply(CONV_ERROR_INVALID_OPERATION);
delete request_obj;
{
_D(RED("publishing_response"));
json result;
- json description;
- payload.set(NULL, CONV_JSON_RESULT_TYPE, "getClient");
+ json description = request_obj->get_description();
- description = request_obj->get_description();
+ payload.set(NULL, CONV_JSON_RESULT_TYPE, "getClient");
result.set(NULL, CONV_JSON_DESCRIPTION, description);
result.set(NULL, CONV_JSON_PAYLOAD, payload);
for (application_info_list_t::iterator iter = svc_info->application_info_list.begin(); iter != svc_info->application_info_list.end(); ++iter) {
_D("iteration");
- if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) )
- {
- if ( (*iter)->application != NULL )
- {
+ if ( (*iter) != NULL && !(*iter)->service_listener.uri.compare(uri) && !(*iter)->service_listener.channel_id.compare(channel_id) ) {
+ if ( (*iter)->application != NULL ) {
_D("publishing payload");
json payload;
request_obj->get_payload_from_description(&payload);
- char* message = new char[strlen(payload.str().c_str())+1];
+ char* message = new(std::nothrow) char[strlen(payload.str().c_str())+1];
+ ASSERT_ALLOC(message);
- strcpy(message, payload.str().c_str());
+ strncpy(message, payload.str().c_str(), strlen(payload.str().c_str()));
string payload_str = payload.str();
_D("publishing done");
- delete message;
+ delete[] message;
return CONV_ERROR_NONE;
}
}
{
_D("communcation/recv requested");
app_comm_service_info *svc_info = reinterpret_cast<app_comm_service_info*>(request_obj->service_info);
- svc_info->registered_request = request_obj;
-
- request_obj->reply(CONV_ERROR_NONE);
- _D("subscribe requested");
+ switch (request_obj->get_type()) {
+ case REQ_SUBSCRIBE:
+ if ( svc_info->registered_request != NULL ) {
+ delete svc_info->registered_request;
+ }
+ svc_info->registered_request = request_obj;
+ request_obj->reply(CONV_ERROR_NONE);
+ _D("subscribe requested");
+ break;
+ case REQ_UNSUBSCRIBE:
+ svc_info->registered_request = NULL;
+ request_obj->reply(CONV_ERROR_NONE);
+ delete request_obj;
+ break;
+ default:
+ request_obj->reply(CONV_ERROR_INVALID_OPERATION);
+ delete request_obj;
+ return CONV_ERROR_INVALID_OPERATION;
+ break;
+ }
return CONV_ERROR_NONE;
}
char* address = NULL;
int ret = connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &address);
- if(ret != CONNECTION_ERROR_NONE)
- {
+ if(ret != CONNECTION_ERROR_NONE) {
_E("connection error");
- if (connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &address) != CONNECTION_ERROR_NONE)
- {
+ if (connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &address) != CONNECTION_ERROR_NONE) {
_E("connection error");
connection_destroy(connection);
return CONV_ERROR_NOT_SUPPORTED;
}
}
- if ( address == NULL || strlen(address) < 1 )
- {
+ if ( address == NULL || strlen(address) < 1 ) {
_E("connection error");
connection_destroy(connection);
return CONV_ERROR_NOT_SUPPORTED;
} else {
- char uri[1000];
+ char uri[200];
Service local_service = Service::getLocal();
- sprintf(uri, "http://%s:8001/api/v2/", address);
+ if (local_service.getUri().empty()) {
+ g_free(address);
+ return CONV_ERROR_NOT_SUPPORTED;
+ }
+
+ snprintf(uri, sizeof(uri), "http://%s:8001/api/v2/", address);
json info;
iotcon_state_get_int(state, CONV_JSON_REPLY, &reply);
- if ( reply == 1 )
- {
+ if (reply == 1) {
bool waiting_reply = false;
// check if it's already launched and waiting for app_control response
}
}
- if ( !waiting_reply )
- {
+ if (!waiting_reply) {
int req_id;
int reply_id = get_req_id();
iotcon_response_result_e result;
ret = app_control_send_launch_request(app_control, NULL, NULL);
- if (ret != APP_CONTROL_ERROR_NONE)
- {
+ if (ret != APP_CONTROL_ERROR_NONE) {
_E("Launch request failed(%d)", ret);
result = IOTCON_RESPONSE_ERROR;
} else {
_D("request type : %d", type);
- if (IOTCON_REQUEST_PUT == type)
- {
+ if (IOTCON_REQUEST_PUT == type) {
iotcon_representation_h req_repr;
_I("GET request");
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 )
- {
+ if (svc_info->iotcon_info_obj.iotcon_resource_handle != NULL) {
_D("already started");
return CONV_ERROR_INVALID_OPERATION;
}
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 )
- {
+ if (svc_info->iotcon_info_obj.iotcon_resource_handle == NULL) {
_D("not even started");
return CONV_ERROR_INVALID_OPERATION;
}
}
_D(RED("publishing_response"));
- json result;
- json payload;
- json description;
+ if (cb_info.request_obj) {
+ json result;
+ json payload;
+ json description;
- payload.set(NULL, CONV_JSON_APP_CONTROL, appctl_char);
+ 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);
- result.set(NULL, CONV_JSON_DESCRIPTION, cb_info.request_obj->get_description());
- result.set(NULL, CONV_JSON_PAYLOAD, payload);
-
- if ( cb_info.request_obj )
- {
cb_info.request_obj->publish(CONV_ERROR_NONE, result);
_D("response published");
}
iotcon_state_add_str(state, CONV_JSON_APP_CONTROL, (char*)app_control.c_str());
iotcon_state_add_int(state, CONV_JSON_REPLY, reply);
- if ( reply == 1 )
- {
+ if (reply == 1) {
int req_id = get_req_id();
iotcon_state_add_int(state, CONV_JSON_REQ_ID, req_id);
{
_D("communcation/recv requested");
remote_app_control_service_info *svc_info = reinterpret_cast<remote_app_control_service_info*>(request_obj->service_info);
- svc_info->registered_request = request_obj;
- request_obj->reply(CONV_ERROR_NONE);
- _D("subscribe requested");
+ switch (request_obj->get_type()) {
+ case REQ_SUBSCRIBE:
+ if (svc_info->registered_request != NULL) {
+ delete svc_info->registered_request;
+ }
+ svc_info->registered_request = request_obj;
+ request_obj->reply(CONV_ERROR_NONE);
+ _D("subscribe requested");
+ break;
+ case REQ_UNSUBSCRIBE:
+ svc_info->registered_request = NULL;
+ request_obj->reply(CONV_ERROR_NONE);
+ delete request_obj;
+ break;
+ default:
+ request_obj->reply(CONV_ERROR_INVALID_OPERATION);
+ delete request_obj;
+ return CONV_ERROR_INVALID_OPERATION;
+ break;
+ }
return CONV_ERROR_NONE;
}
remote_app_control_service_info *svc_info = NULL;
service_info_base* svc_info_base = client_obj->get_service_info(_type, device_id);
- if ( svc_info_base != NULL ) {
+ if (svc_info_base != NULL) {
_D("service instance already exists");
svc_info = reinterpret_cast<remote_app_control_service_info*>(svc_info_base);
_D("casting failed");
return CONV_ERROR_INVALID_OPERATION;
}
- }
- else
- {
+ } else {
_D("allocating new service instance");
- svc_info = new remote_app_control_service_info();
+ svc_info = new(std::nothrow) remote_app_control_service_info();
+ IF_FAIL_RETURN_TAG(svc_info, CONV_ERROR_OUT_OF_MEMORY, _E, "svc_info alloc failed");
svc_info->device_id = device_id;
svc_info->device_name = device_name;
std::string conv::util::get_bt_mac_address()
{
static std::string g_mac_address;
- if(g_mac_address.empty()){
+ if(g_mac_address.empty()) {
bt_initialize();
char* mac_address;
bt_adapter_enable();
static std::string g_device_name;
if(g_device_name.empty()) {
char* device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
- //jhp27.park
- if (device_name == NULL)
- {
+ if (device_name == NULL) {
g_device_name = "Tizen";
} else {
g_device_name = device_name;
std::string conv::util::get_p2p_mac_address()
{
static std::string g_p2p_mac_address;
- if(g_p2p_mac_address.empty()){
+ if(g_p2p_mac_address.empty()) {
char p2p_mac[MAC_ADDR_STR_LEN];
memset(p2p_mac, 0x0, MAC_ADDR_STR_LEN);
char* temp_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
- if (temp_addr == NULL)
- {
+ if (temp_addr == NULL) {
_E("vconf_get_str Failed for %s", VCONFKEY_WIFI_BSSID_ADDRESS);
- }
- else
- {
+ } else {
memcpy(p2p_mac, temp_addr, MAC_ADDR_STR_LEN-1);
p2p_mac[1] = make_p2p_mac(p2p_mac[1]);
_I("P2P mac is %s", p2p_mac);
{
_D("timer_work..");
gpointer *tdata = (gpointer*)ud;
- if (tdata[0])
- {
+ if (tdata[0]) {
((conv::util::timer_function)tdata[0])(tdata[1]);
}
return TRUE;
_D("misc_start_timer with interval[%d]", interval);
src = g_timeout_source_new(interval*1000);
- //ASSERT(src != NULL);
tdata = g_new0(gpointer, 2);
- //ASSERT(tdata != NULL);
tdata[0] = (void*)function;
tdata[1] = data;
{
guint id = (guint) timer;
_D("Requested Stop Timer[%d]", id);
- if (id)
- {
- if (!g_source_remove(id))
- {
+ if (id) {
+ if (!g_source_remove(id)) {
_E("g_source_remove is fail (timer)");
}
}
typedef std::map<int, device_callback_info_s*> callback_map_t;
static callback_map_t callback_map;
-//static device_callback_info_s* device_callback;
static void conv_subject_cb(const char* subject, int req_id, int error, json data){
_D("Callback response %d : subject[%s] json_data[%s]", req_id, subject, data.str().c_str());
- conv_device_h device = new (std::nothrow) _conv_device_handle_s();
+ conv_device_h device = new(std::nothrow) _conv_device_handle_s();
IF_FAIL_VOID_TAG(device, _E, "Memory Allocation Failed");
device->jbody = data;
conv::dbus_client::release();
std::list<int>::iterator itr_end = handle->request_ids.end();
callback_map_t::iterator map_iter_end = callback_map.end();
- for (std::list<int>::iterator iter_pos = handle->request_ids.begin(); iter_pos != itr_end; iter_pos++)
- {
+ for (std::list<int>::iterator iter_pos = handle->request_ids.begin(); iter_pos != itr_end; iter_pos++) {
callback_map_t::iterator map_iter = callback_map.find(*iter_pos);
if (map_iter != map_iter_end)
callback_map.erase(map_iter);
ASSERT_NOT_NULL(handle);
ASSERT_NOT_NULL(callback);
- //temp
- //conv_set_discovery_cb(handle, callback, user_data);
-
register_subject_callbacks();
device_callback_info_s *cb_info = new(std::nothrow)device_callback_info_s();
// unset callback..
std::list<int>::iterator req_itr = handle->request_ids.begin();
- for (; req_itr != handle->request_ids.end(); req_itr++)
- {
+ for (; req_itr != handle->request_ids.end(); req_itr++) {
int cur_req_id = *req_itr;
- if (callback_map[cur_req_id] != NULL)
- {
+ if (callback_map[cur_req_id] != NULL) {
_D("free memory for callback[id:%d]", cur_req_id);
delete callback_map[cur_req_id];
callback_map.erase(callback_map.find(cur_req_id));
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
ASSERT_NOT_NULL(original_handle);
ASSERT_NOT_NULL(target_handle);
- _conv_device_handle* device = new (std::nothrow) _conv_device_handle();
+ _conv_device_handle* device = new(std::nothrow) _conv_device_handle();
device->jbody = original_handle->jbody;
*target_handle = device;
std::string strval;
bool ret = handle->jbody.get(NULL, key, &strval); // path is NULL..
- if (ret == false || strval.empty()) return CONV_ERROR_NO_DATA;
+ if (ret == false || strval.empty())
+ return CONV_ERROR_NO_DATA;
*value = strdup(strval.c_str());
return CONV_ERROR_NONE;
EXTAPI int conv_device_foreach_service(conv_device_h handle, conv_service_foreach_cb cb, void* user_data)
{
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
+ ASSERT_NOT_NULL(handle);
+ ASSERT_NOT_NULL(cb);
+
json json_data = handle->jbody;
std::string strval;
int service_count = 0;
service_count = json_data.array_get_size(CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_DATA); // json data..
- for (int index =0; index < service_count; index++)
- {
- _conv_service_handle* service = new (std::nothrow) _conv_service_handle();
+ for (int index =0; index < service_count; index++) {
+ _conv_service_handle* service = new(std::nothrow) _conv_service_handle();
ASSERT_ALLOC(service);
// service json data
json json_service;
std::string version, type, uri;
conv_service_e service_type;
- /*
- json_data.get_array_elem (CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_DATA_VERSION, index, &version);
- json_data.get_array_elem (CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_DATA_TYPE, index, &type);
- json_data.get_array_elem (CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_DATA_URI, index, &uri);
- json_data.get_array_elem (CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_TYPE, index, (int*)&service_type);
- */
json_data.get_array_elem(CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_DATA, index, &json_service);
json_data.get_array_elem(CONV_JSON_SERVICE_PATH, CONV_JSON_SERVICE_TYPE, index, (int*)&service_type);
_D("index[%d] service json : %s", index, json_service.str().c_str());
- //typedef void(* conv_service_foreach_cb)(conv_service_h service_handle, void* user_data);
cb(service, user_data);
delete service;
-
- // service json data includes features like name, version, type, uri and id..
}
return CONV_ERROR_NONE;
#include "common.h"
#include "d2d_conv_manager.h"
+#include "d2d_conv_internal.h"
#include "conv_lib_json.h"
#include "internal_types.h"
#include "dbus_client.h"
return CONV_ERROR_NONE;
}
+// internal API
+EXTAPI int conv_channel_internal_export_to_string(conv_channel_h handle, char** value)
+{
+ IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
+ ASSERT_NOT_NULL(handle);
+ ASSERT_NOT_NULL(value);
+
+ *value = g_strdup(handle->jchannel.str().c_str());
+ ASSERT_ALLOC(*value);
+
+ return CONV_ERROR_NONE;
+}
json::json(const char* s)
{
- if (s) {
+ if (s)
parse(s);
- } else {
+ else
parse(EMPTY_JSON_OBJECT);
- }
}
json::json(const std::string& s)
{
- if (s.empty()) {
+ if (s.empty())
parse(EMPTY_JSON_OBJECT);
- } else {
+ else
parse(s.c_str());
- }
}
json::~json()
{
release();
json_node = json_node_copy(j.json_node);
- if (!json_node) {
+ if (!json_node)
_E("Json object copy failed");
- }
+
return *this;
}
json& json::operator=(const char* s)
{
release();
- if (s) {
+ if (s)
parse(s);
- } else {
+ else
parse(EMPTY_JSON_OBJECT);
- }
+
return *this;
}
json& json::operator=(const std::string& s)
{
release();
- if (s.empty()) {
+ if (s.empty())
parse(EMPTY_JSON_OBJECT);
- } else {
+ else
parse(s.c_str());
- }
+
return *this;
}
return !operator==(rhs);
}
-/* TODO
-bool json::contains(const json& subset) const
-{
- return false;
-}
-*/
-
char* json::dup_cstr()
{
IF_FAIL_RETURN_TAG(json_node, NULL, _E, "Json object not initialized");
return output;
CATCH:
- if (jgen) {
+ if (jgen)
g_object_unref(jgen);
- }
_E("Memory allocation failed");
return NULL;
*length = 1;
- for (pch = path; *pch != '\0'; pch++) {
- if (*pch == PATH_DELIM) {
+ for (pch = path; *pch != '\0'; pch++)
+ if (*pch == PATH_DELIM)
*length = *length + 1;
- }
- }
tokens = static_cast<char**>(g_malloc((*length) * sizeof(char*)));
IF_FAIL_RETURN_TAG(tokens, NULL, _E, "Memory allocation failed");
begin = pch + 1;
}
- if (*pch == '\0') {
+ if (*pch == '\0')
break;
- }
}
return tokens;
CATCH:
- for (j = 0; j < i; j++) {
+ for (j = 0; j < i; j++)
g_free(tokens[j]);
- }
+
g_free(tokens);
return NULL;
}
{
int i;
if (tokens) {
- for (i = 0; i < length; i++) {
+ for (i = 0; i < length; i++)
g_free(tokens[i]);
- }
+
g_free(tokens);
}
}
goto CATCH;
}
}
+
child_node = json_object_get_member(jobj, path_token[depth]);
IF_FAIL_CATCH(child_node && json_node_get_node_type(child_node) == JSON_NODE_OBJECT);
JsonObject *jobj = traverse(json_node, path, true);
IF_FAIL_RETURN(jobj, false);
- if (json_object_has_member(jobj, key)) {
+ if (json_object_has_member(jobj, key))
json_object_remove_member(jobj, key);
- }
//NOTE: json-glib causes a precision issue while handling double values
json_object_set_string_member(jobj, key, double_to_string(val, prec).c_str());
JsonObject *jobj = traverse(json_node, path, true);
IF_FAIL_RETURN(jobj, false);
- if (json_object_has_member(jobj, key)) {
+ if (json_object_has_member(jobj, key))
json_object_remove_member(jobj, key);
- }
json_object_set_string_member(jobj, key, val.c_str());
return true;
JsonObject *jobj = traverse(json_node, path, true);
IF_FAIL_RETURN(jobj, false);
- if (json_object_has_member(jobj, key)) {
- json_object_remove_member(jobj, key);
- }
+ if (json_object_has_member(jobj, key))
+ json_object_remove_member(jobj, key);
return true;
}
node = json_object_dup_member(jobj, key);
IF_FAIL_RETURN_TAG(node, false, _E, "Memory allocation failed");
- if (val->json_node) {
+ if (val->json_node)
json_node_free(val->json_node);
- }
+
val->json_node = node;
return true;
IF_FAIL_RETURN(node, false);
GType vtype = json_node_get_value_type(node);
- if (vtype == G_TYPE_INT64) {
+ if (vtype == G_TYPE_INT64)
*val = json_node_get_int(node);
- } else if (vtype == G_TYPE_STRING) {
+ else if (vtype == G_TYPE_STRING)
//TODO: if the string is not a number?
*val = static_cast<int64_t>(string_to_double(json_node_get_string(node)));
- } else {
+ else
return false;
- }
return true;
}
IF_FAIL_RETURN(node, false);
GType vtype = json_node_get_value_type(node);
- if (vtype == G_TYPE_DOUBLE) {
+ if (vtype == G_TYPE_DOUBLE)
*val = json_node_get_double(node);
- } else if (vtype == G_TYPE_INT64) {
+ else if (vtype == G_TYPE_INT64)
*val = json_node_get_int(node);
- } else if (vtype == G_TYPE_STRING) {
+ else if (vtype == G_TYPE_STRING)
//NOTE: json-glib causes a precision issue while handling double values
*val = string_to_double(json_node_get_string(node));
- } else {
+ else
return false;
- }
return true;
}
return NULL;
}
}
+
node = json_object_get_member(jobj, key);
IF_FAIL_RETURN_TAG(node && json_node_get_node_type(node) == JSON_NODE_ARRAY,
NULL, _W, "Type mismatched: %s", key);
JsonNode *node_copy = json_node_copy(node);
IF_FAIL_RETURN_TAG(node_copy, false, _E, "Memory allocation failed");
- if (val->json_node) {
+ if (val->json_node)
json_node_free(val->json_node);
- }
+
val->json_node = node_copy;
return true;
IF_FAIL_RETURN(ltype == rtype, false);
switch (ltype) {
- case JSON_NODE_VALUE:
- IF_FAIL_RETURN(value_equals(lhs, rhs), false);
- break;
- case JSON_NODE_OBJECT:
- IF_FAIL_RETURN(object_equals(lhs, rhs), false);
- break;
- case JSON_NODE_ARRAY:
- IF_FAIL_RETURN(array_equals(lhs, rhs), false);
- break;
- default:
- _W("Unsupported type");
- return false;
+ case JSON_NODE_VALUE:
+ IF_FAIL_RETURN(value_equals(lhs, rhs), false);
+ break;
+ case JSON_NODE_OBJECT:
+ IF_FAIL_RETURN(object_equals(lhs, rhs), false);
+ break;
+ case JSON_NODE_ARRAY:
+ IF_FAIL_RETURN(array_equals(lhs, rhs), false);
+ break;
+ default:
+ _W("Unsupported type");
+ return false;
}
return true;
IF_FAIL_RETURN(ltype == rtype, false);
switch (ltype) {
- case G_TYPE_INT64:
- return json_node_get_int(lhs) == json_node_get_int(rhs);
- case G_TYPE_DOUBLE:
- return json_node_get_double(lhs) == json_node_get_double(rhs);
- case G_TYPE_STRING:
- return STR_EQ(json_node_get_string(lhs), json_node_get_string(rhs));
- default:
- _W("Unsupported type");
- return false;
+ case G_TYPE_INT64:
+ return json_node_get_int(lhs) == json_node_get_int(rhs);
+ case G_TYPE_DOUBLE:
+ return json_node_get_double(lhs) == json_node_get_double(rhs);
+ case G_TYPE_STRING:
+ return STR_EQ(json_node_get_string(lhs), json_node_get_string(rhs));
+ default:
+ _W("Unsupported type");
+ return false;
}
}
#include "common.h"
#include "d2d_conv_manager.h"
+#include "d2d_conv_internal.h"
#include "conv_lib_json.h"
#include "internal_types.h"
#include "dbus_client.h"
return CONV_ERROR_NONE;
}
+
+// internal API
+EXTAPI int conv_payload_internal_export_to_string(conv_payload_h handle, char** value)
+{
+ IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
+ ASSERT_NOT_NULL(handle);
+ ASSERT_NOT_NULL(value);
+
+ *value = g_strdup(handle->jpayload.str().c_str());
+ ASSERT_ALLOC(*value);
+
+ return CONV_ERROR_NONE;
+}
key.set(NULL, CONV_JSON_SERVICE, service);
key.set(NULL, CONV_JSON_TYPE, service_type);
+ key.set(NULL, CONV_JSON_IS_LOCAL, is_local);
+ _D("key:%s", key.str().c_str());
std::map<std::string, _conv_service_callback_info*>::iterator it = callback_map.find(key.str());
if (it == callback_map.end()) {
ASSERT_ALLOC(*handle);
(*handle)->is_local = 1;
+ (*handle)->service_type = CONV_SERVICE_NONE;
(*handle)->connection_state = CONV_SERVICE_CONNECTION_STATE_CONNECTED;
return CONV_ERROR_NONE;
ASSERT_NOT_NULL(handle);
if ( handle->callback )
- {
delete handle->callback;
- }
delete handle;
json service = handle->jservice;
std::string type = convert_type_to_string(handle->service_type);
+ if (type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_TYPE, type);
+ description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
_conv_service_callback_info *cb_info = new(std::nothrow)_conv_service_callback_info();
cb_info->cb = callback;
json service = handle->jservice;
std::string type = convert_type_to_string(handle->service_type);
+ if (type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_TYPE, type);
+ description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
int req_id;
- int err = conv::dbus_client::request(REQ_UNSUBSCRIBE, &req_id, CONV_SUBJECT_COMMUNICATION_RECV, NULL, NULL, NULL);
+ int err = conv::dbus_client::request(REQ_UNSUBSCRIBE, &req_id, CONV_SUBJECT_COMMUNICATION_RECV, description.str().c_str(), NULL, NULL);
IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Unset observe failed");
std::map<std::string, _conv_service_callback_info*>::iterator it = callback_map.find(description.str());
json channel;
if ( channel_handle != NULL )
- {
channel = channel_handle->jchannel;
- }
json service = handle->jservice;
json device = handle->jdevice;
std::string type = convert_type_to_string(handle->service_type);
+ if (type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_CHANNEL, channel);
return CONV_ERROR_NONE;
}
-EXTAPI int conv_service_get(conv_service_h handle, conv_channel_h channel_handle, conv_payload_h payload_handle)
+EXTAPI int conv_service_read(conv_service_h handle, conv_channel_h channel_handle, conv_payload_h payload_handle)
{
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
ASSERT_NOT_NULL(handle);
json channel;
if ( channel_handle != NULL )
- {
channel = channel_handle->jchannel;
- }
json payload;
- if ( payload_handle != NULL) {
+ if ( payload_handle != NULL)
payload = payload_handle->jpayload;
- }
json service = handle->jservice;
std::string type = convert_type_to_string(handle->service_type);
+ if (type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_CHANNEL, channel);
json channel;
if ( channel_handle != NULL )
- {
channel = channel_handle->jchannel;
- }
json service = handle->jservice;
json device = handle->jdevice;
std::string type = convert_type_to_string(handle->service_type);
+ if (type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_CHANNEL, channel);
json description;
json channel;
+ json payload;
- if ( channel_handle != NULL )
- {
+ if (channel_handle != NULL)
channel = channel_handle->jchannel;
- }
- json payload = payload_handle->jpayload;
+ if (payload_handle != NULL)
+ payload = payload_handle->jpayload;
+
json service = handle->jservice;
json device = handle->jdevice;
+
std::string type = convert_type_to_string(handle->service_type);
+ if (type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_CHANNEL, channel);
json service = handle->jservice;
std::string service_type = convert_type_to_string(handle->service_type);
+ if (service_type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_TYPE, service_type);
json device = handle->jdevice;
std::string service_type = convert_type_to_string(handle->service_type);
+ if (service_type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_TYPE, service_type);
description.set(NULL, CONV_JSON_DEVICE, device);
description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
- //temp
conv_service_set_connected_cb(handle, description, callback, user_data);
int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_CONNECTION_START, description.str().c_str(), NULL, NULL);
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
ASSERT_NOT_NULL(handle);
- //temp
conv_service_unset_connected_cb(handle);
int req_id;
json service = handle->jservice;
json device = handle->jdevice;
std::string service_type = convert_type_to_string(handle->service_type);
+ if (service_type.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_TYPE, service_type);
std::string strval;
bool ret = handle->jservice.get(NULL, key, &strval); // path is NULL..
- if (ret == false || strval.empty()) return CONV_ERROR_NO_DATA;
+ if (ret == false || strval.empty())
+ return CONV_ERROR_NO_DATA;
*value = strdup(strval.c_str());
return CONV_ERROR_NONE;
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
ASSERT_NOT_NULL(handle);
+ std::string value_str = convert_type_to_string(value);
+ if (value_str.empty())
+ return CONV_ERROR_INVALID_PARAMETER;
+
handle->service_type = value;
return CONV_ERROR_NONE;
{
conv_service_e service_type = CONV_SERVICE_NONE;
- if ( !type_name.compare(CONV_SERVICE_TYPE_SMARTVIEW_APP_COMMUNICATION))
- {
+ if ( !type_name.compare(CONV_SERVICE_TYPE_SMARTVIEW_APP_COMMUNICATION)) {
service_type = CONV_SERVICE_APP_TO_APP_COMMUNICATION;
} else if ( !type_name.compare(CONV_SERVICE_TYPE_REMOTE_APP_CONTROL)) {
service_type = CONV_SERVICE_REMOTE_APP_CONTROL;
g_variant_get(param, "(i&si&s)", &req_id, &subject, &error, &data);
_D("[Response] ReqId: %d, Subject: %s, Error: %d", req_id, subject, error);
- // conv::response_handler::deliver(subject, req_id, error, data);
response_cb_map_t::iterator it = response_cb_map->find(subject);
IF_FAIL_VOID_TAG(it!= response_cb_map->end(), _E, "Unknown subject'%s'", subject);
it->second(subject, req_id, error, data);
bool conv::dbus_client::init()
{
-// static GMutex connection_mutex;
-// conv::scope_mutex sm(&connection_mutex);
-
_D("dbus_client init with dbus_connection %d response_cb_map:%x", dbus_connection, response_cb_map);
if (dbus_connection) {
return true;
}
- //response_cb_map = g_new0 (response_cb_map_t,1);
- response_cb_map = new (std::nothrow) response_cb_map_t;
+ response_cb_map = new(std::nothrow) response_cb_map_t;
_D("dbus_client init with response_cb_map:%x", response_cb_map);
GError *gerr = NULL;
--- /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 __TIZEN_D2D_CONV_INTERNAL_H__
+#define __TIZEN_D2D_CONV_INTERNAL_H__
+
+#include <d2d_conv_error.h>
+#include <d2d_conv_channel.h>
+#include <d2d_conv_payload.h>
+#include <d2d_conv_service.h>
+#include <d2d_conv_device.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @file d2d_conv_internal.h
+ */
+
+/**
+ * @brief Exports json string from channel.
+ * @since_tizen 3.0
+ * @remarks The @a value must be released using free().
+ *
+ * @param[in] handle The channel handle
+ * @param[out] value The result value
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONV_ERROR_NONE Successful
+ * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONV_ERROR_NOT_SUPPORTED Not supported
+ * @retval #CONV_ERROR_NO_DATA No Data
+ * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int conv_channel_internal_export_to_string(conv_channel_h handle, char** value);
+
+/**
+ * @brief Exports json string from payload.
+ * @since_tizen 3.0
+ * @remarks The @a value must be released using free().
+ *
+ * @param[in] handle The payload handle
+ * @param[out] value The result value
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #CONV_ERROR_NONE Successful
+ * @retval #CONV_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONV_ERROR_NOT_SUPPORTED Not supported
+ * @retval #CONV_ERROR_NO_DATA No Data
+ * @retval #CONV_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ */
+int conv_payload_internal_export_to_string(conv_payload_h handle, char** value);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+/**
+* @}
+*/
+
+#endif /* __TIZEN_D2D_CONV_INTERNAL_H__ */
[Unit]
Description=D2D Convergence Manager Daemon
-#Wants=net-config.service,bt-service
-#After=net-config.service,bt-service
[Service]
Type=dbus
%config %{_sysconfdir}/dbus-1/session.d/d2d-conv-manager.conf
%{_unitdir_user}/%{name}.service
%{_bindir}/%{name}d
-%{_datadir}/dbus-1/services/org.tizen.d2dconv.service
%{_bindir}/%{name}-test
%{_datadir}/license/%{name}
LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib/include)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib/disc_mgr/include)
SET(TEST "d2d-conv-manager-test")
}
printf("next\n");
-
-
}
}
printf("conv_service_stop called..\n");
conv_service_stop(handle, channel_handle, NULL);
- /*
+/*
printf("conv_service_get called..\n");
conv_service_get(handle, channel_handle, NULL, NULL);
- */
+*/
printf("conv_payload_destroy called..\n");
conv_payload_destroy(payload_handle);
conv_discovery_start(handle, 10, device_conv_app_communication_discovery_cb, NULL);
}
-
// Simple Test.. Start/Stop Discovery
void simple_test_conv_start_stop_discovery()
{
/*
printf("set discovery cb..\n");
- //conv_set_discovery_cb (handle, simple_test_conv_discovery_cb, NULL);
- conv_set_discovery_cb (handle, device_conv_discovery_cb, NULL);
+ conv_set_discovery_cb(handle, device_conv_discovery_cb, NULL);
*/
printf("conv_discovery_start called..\n");
loop = g_main_loop_new(NULL, FALSE);
if (argc > 1) {
- printf("1");
int type = atoi(argv[1]);
struct arg_data* args = g_slice_alloc(sizeof(*args));
args->type = type;