static bool _on_create_cb(void *user_data) { dlog_print(DLOG_INFO ,"tdlna", "_on_create_cb 실행"); RETVM_IF(!user_data, false, "User_data is NULL"); RETVM_IF(_app_init(user_data) != SVC_RES_OK, false, "Failed to initialise application data"); return true; }
/* The length of resource type should be less than or equal to 61. * Duplicate strings are not allowed. */ API int iotcon_resource_types_add(iotcon_resource_types_h types, const char *type) { char *resource_type; RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED); RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER); RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER, "Don't modify it. It is already set."); if (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(type)) { ERR("The length of type(%s) should be less than or equal to %d.", type, ICL_RESOURCE_TYPE_LENGTH_MAX); return IOTCON_ERROR_INVALID_PARAMETER; } if (true == _icl_resource_types_duplicate_check(types, type)) { ERR("%s is already contained.", type); return IOTCON_ERROR_INVALID_PARAMETER; } resource_type = strdup(type); if (NULL == resource_type) { ERR("strdup() Fail"); return IOTCON_ERROR_INVALID_PARAMETER; } types->type_list = g_list_append(types->type_list, resource_type); return IOTCON_ERROR_NONE; }
/* Duplicate strings are not allowed. */ API int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces, const char *iface) { char *resource_iface; RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED); RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER); RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER, "Don't modify it. It is already set."); if (true == _icl_resource_interfaces_duplicate_check(ifaces, iface)) { ERR("%s is already contained.", iface); return IOTCON_ERROR_INVALID_PARAMETER; } resource_iface = strdup(iface); if (NULL == resource_iface) { ERR("strdup() Fail"); return IOTCON_ERROR_INVALID_PARAMETER; } ifaces->iface_list = g_list_append(ifaces->iface_list, resource_iface); return IOTCON_ERROR_NONE; }
Evas_Object *ui_utils_navi_add(Evas_Object *parent) { Evas_Object *navi = elm_naviframe_add(parent); RETVM_IF(!navi, NULL, "elm_naviframe_add() failed"); elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE); return navi; }
//앱 구동에 필요한 각종 appdata를 초기화 static int _app_init(app_data *app) { dlog_print(DLOG_INFO ,"tdlna", "_app_init 실행"); int result = SVC_RES_FAIL; RETVM_IF(!app, result, "Application data is NULL"); app->proxy_client = proxy_client_create(); RETVM_IF(!app->proxy_client, result, "Failed to create proxy client"); result = proxy_client_register_port(app->proxy_client, LOCAL_MESSAGE_PORT_NAME); if (result != SVC_RES_OK) { ERR("Failed to register proxy client port"); proxy_client_destroy(app->proxy_client); app->proxy_client = NULL; return result; } result = proxy_client_register_msg_receive_callback(app->proxy_client, _on_proxy_client_msg_received_cb, app); if (result != SVC_RES_OK) { ERR("Failed to register proxy client on message receive callback"); proxy_client_destroy(app->proxy_client); app->proxy_client = NULL; return result; } result = pthread_mutex_init(&app->proxy_locker, NULL); if(result != 0) { ERR("Failed to init message response mutex "); proxy_client_destroy(app->proxy_client); app->proxy_client = NULL; return SVC_RES_FAIL; } //tldna 서비스 appdata초기화 app->run_tdlna = false; app->tdlna_td = 0; get_DeviceID();//기본 기기 아이디값 가져오기 strcpy(app->deviceName,deviceName); return SVC_RES_OK; }
Evas_Object *ui_utils_layout_add(Evas_Object *parent, Evas_Object_Event_Cb destroy_cb, void *cb_data) { Evas_Object *layout = elm_layout_add(parent); RETVM_IF(!layout, NULL, "elm_layout_add() failed"); elm_layout_theme_set(layout, "layout", "application", "default"); evas_object_event_callback_add(layout, EVAS_CALLBACK_FREE, destroy_cb, cb_data); return layout; }
static int sendResponMessage(void *data){ app_data *appdata = data; bundle *resp_dir = bundle_create(); RETVM_IF(bundle_add_str(resp_dir, "folder_path", send_folders) != 0, SVC_RES_FAIL, "Failed to add data by key to bundle"); _app_send_response(appdata, resp_dir); bundle_free(resp_dir); return SVC_RES_OK; }
int proxy_client_register_msg_receive_callback(proxy_client *proxy_cl, proxy_client_callback_func callback_func, void *data) { RETVM_IF(!proxy_cl, SVC_RES_FAIL, "Proxy client is NULL"); proxy_cl->cb_func = callback_func; proxy_cl->cb_data = data; return SVC_RES_OK; }
int proxy_client_register_port(proxy_client *proxy_cl, const char *const port_name) { int result = SVC_RES_FAIL; RETVM_IF(!proxy_cl, result, "Proxy client is NULL"); RETVM_IF(!port_name, result, "Message port name is NULL"); int temp_id = message_port_register_local_port(port_name, _on_message_received_cb, proxy_cl); if (temp_id < 0) { _proxy_client_convert_msg_port_result(temp_id); ERR("Failed to register local message port"); proxy_cl->local_port_id = 0; return result; } DBG("Message port %s registered with id: %d", port_name, temp_id); proxy_cl->local_port_id = temp_id; return SVC_RES_OK; }
static Evas_Object *_tab_view_create_tab_content(tab_view_data *data) { RETVM_IF(!data, NULL, "data is NULL"); Evas_Object *list = elm_list_add(data->layout); if(!list) { return NULL; } _tab_view_fill_list(list, data); return list; }
int app_run(app_data *app, int argc, char **argv) { RETVM_IF(!app, -1, "Application data is NULL"); service_app_lifecycle_callback_s cbs = { .create = _on_create_cb, .terminate = _on_terminate_cb, .app_control = _on_app_control_callback }; return service_app_main(argc, argv, &cbs, app); }
int proxy_client_send_message(proxy_client *proxy_cl, bundle *const msg) { int result = SVC_RES_FAIL; RETVM_IF(!proxy_cl, result , "Proxy client is NULL"); RETVM_IF(!(proxy_cl->local_port_id), result, "Message port is not registered"); RETVM_IF(!(proxy_cl->remote_app_name), result, "Remote application name is not registered"); RETVM_IF(!(proxy_cl->remote_port_name), result, "Remote message port is not registered"); result = _proxy_client_convert_msg_port_result(message_port_send_message_with_local_port( proxy_cl->remote_app_name, proxy_cl->remote_port_name, msg, proxy_cl->local_port_id)); RETVM_IF(result != SVC_RES_OK, result, "Failed to send bidirectional message to: %s:%s", proxy_cl->remote_app_name, proxy_cl->remote_port_name); DBG("Message successfully send to: %s:%s", proxy_cl->remote_app_name, proxy_cl->remote_port_name); return result; }
static int _on_proxy_client_msg_received_cb(void *data, bundle *const rec_msg) { dlog_print(DLOG_INFO ,"tdlna", "_on_proxy_client_msg_received_cb 실행"); int result = SVC_RES_FAIL; RETVM_IF(!data, result, "Data is NULL"); app_data *app = data; req_operation req_operation = REQ_OPER_NONE; bundle *resp_msg = bundle_create(); RETVM_IF(!resp_msg, result, "Failed to create bundle"); result = _app_process_received_message(rec_msg, resp_msg, &req_operation); if (result != SVC_RES_OK) { ERR("Failed to generate response bundle"); bundle_free(resp_msg); return result; } result = _app_execute_operation(app, req_operation); if(result == SVC_RES_OK) { result = _app_send_response(app, resp_msg); if (result != SVC_RES_OK) { ERR("Failed to send message to remote application"); } } else { ERR("Failed to execute operation"); } bundle_free(resp_msg); return result; }
static int _proxy_client_set_remote_data(proxy_client *proxy_cl, const char *rem_app_name, const char *rem_port_name) { RETVM_IF(!proxy_cl, SVC_RES_FAIL, "Proxy pointer is NULL"); char *temp_rem_app_name = NULL; char *temp_rem_port_name = NULL; if (!proxy_cl->remote_app_name && rem_app_name) { temp_rem_app_name = strdup(rem_app_name); RETVM_IF(!temp_rem_app_name, SVC_RES_FAIL, "Failed to set remote application name. Strdup failed"); } if (!proxy_cl->remote_port_name && rem_port_name) { temp_rem_port_name = strdup(rem_port_name); if (!temp_rem_port_name) { ERR("Failed to set remote port name. Strdup failed"); free(temp_rem_app_name); return SVC_RES_FAIL; } } if (temp_rem_app_name) { proxy_cl->remote_app_name = temp_rem_app_name; } if (temp_rem_port_name) { proxy_cl->remote_port_name = temp_rem_port_name; } return SVC_RES_OK; }
OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle, OCClientResponse *resp) { int ret; struct icd_find_context *find_ctx; icd_sig_ctx_s *sig_context = ctx; RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION); RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION); if (NULL == resp->payload) /* normal case : payload COULD be NULL */ return OC_STACK_KEEP_TRANSACTION; RETVM_IF(PAYLOAD_TYPE_DISCOVERY != resp->payload->type, OC_STACK_KEEP_TRANSACTION, "Invalid payload type(%d)", resp->payload->type); find_ctx = calloc(1, sizeof(struct icd_find_context)); if (NULL == find_ctx) { ERR("calloc() Fail(%d)", errno); return OC_STACK_KEEP_TRANSACTION; } find_ctx->signal_number = sig_context->signal_number; find_ctx->bus_name = ic_utils_strdup(sig_context->bus_name); find_ctx->payload = icd_payload_res_to_gvariant(resp->payload, &resp->devAddr); find_ctx->conn_type = icd_ioty_transport_flag_to_conn_type(resp->devAddr.adapter, resp->devAddr.flags); ret = _ocprocess_worker_start(_worker_find_cb, find_ctx, _icd_find_context_free); if (IOTCON_ERROR_NONE != ret) { ERR("_ocprocess_worker_start() Fail(%d)", ret); ic_utils_gvariant_array_free(find_ctx->payload); _icd_find_context_free(find_ctx); return OC_STACK_KEEP_TRANSACTION; } /* DO NOT FREE sig_context. It MUST be freed in the ocstack */ /* DO NOT FREE find_ctx. It MUST be freed in the _worker_find_cb func */ return OC_STACK_KEEP_TRANSACTION; }
Evas_Object *main_view_add(Evas_Object *navi) { main_view *main_view_data = calloc(1, sizeof(main_view)); RETVM_IF(!main_view_data, NULL, "calloc() failed"); main_view_data->navi = navi; main_view_data->layout = ui_utils_layout_add(main_view_data->navi, _main_view_destroy, main_view_data); if(!main_view_data->layout) { ERR("ui_utils_layout_add() failed"); free(main_view_data); return NULL; } main_view_data->preview_canvas = evas_object_image_add(evas_object_evas_get(main_view_data->layout)); if(!main_view_data->preview_canvas) { ERR("_main_view_rect_create() failed"); evas_object_del(main_view_data->layout); return NULL; } elm_object_part_content_set(main_view_data->layout, "elm.swallow.content", main_view_data->preview_canvas); main_view_data->camera_enabled = _main_view_init_camera(main_view_data); if (!main_view_data->camera_enabled) { ERR("_main_view_start_preview failed"); _main_view_show_warning_popup(navi, _error, _camera_init_failed, _ok, main_view_data); } _main_view_register_cbs(main_view_data); main_view_data->navi_item = elm_naviframe_item_push(main_view_data->navi, NULL, NULL, NULL, main_view_data->layout, NULL); // main_view_data->navi_item = elm_naviframe_item_push(main_view_data->navi, "Color Picker", NULL, NULL, main_view_data->layout, NULL); elm_naviframe_item_title_enabled_set(main_view_data->navi_item, EINA_FALSE, EINA_TRUE); return main_view_data->layout; }
API int iotcon_resource_types_remove(iotcon_resource_types_h types, const char *type) { GList *found_node; char *node_data; RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED); RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER); RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER, "Don't modify it. It is already set."); found_node = g_list_find_custom(types->type_list, type, _icl_resource_types_strcmp); if (NULL == found_node) { ERR("g_list_find_custom() Fail"); return IOTCON_ERROR_NO_DATA; } node_data = found_node->data; types->type_list = g_list_delete_link(types->type_list, found_node); free(node_data); return IOTCON_ERROR_NONE; }
static int _app_execute_operation(app_data *appdata, req_operation operation_type) { dlog_print(DLOG_INFO ,"tdlna", "_app_execute_operation 실행"); bundle *resp_msg = bundle_create(); RETVM_IF(!appdata, SVC_RES_FAIL, "Application data is NULL"); char *resp_key_val = NULL; char respStr[50]; switch (operation_type) { case REQ_OPER_STATE: dlog_print(DLOG_INFO, "tdlna", "현재 상태 얻기"); if ((appdata->run_tdlna) == 0) { // 서비스가 꺼져있는 상태라면 dlog_print(DLOG_INFO, "tdlna", "서비스 상태 조회 %d", appdata->run_tdlna); resp_key_val = "STATE:OFF"; } else { resp_key_val = "STATE:ON"; dlog_print(DLOG_INFO, "tdlna", "서비스 상태 조회 %d", appdata->run_tdlna); } break; case REQ_OPER_FOLDER: dlog_print(DLOG_INFO, "tdlna", "미디어 정보 얻기"); send_folders[0] = '\0';//초기화 if(media_Directory(appdata)){//미디어 폴더 경로를 sendFolder함수로 전달해줌 //폴더검색후 sendResponMessage(appdata); dlog_print(DLOG_INFO,"tdlna","미디어 폴더 전송:%s",send_folders); } resp_key_val = "미디어 폴더 요청"; break; case REQ_OPER_META_GET_APP: dlog_print(DLOG_INFO,"tdlna","메타정보 가져오기 실행 "); //------------------------------------------------------------------------------------------------------김태형~~!!! char* testDir; mediaDirectory_folder(&testDir,2); dlog_print(DLOG_INFO,"tdlna","비디오 폴더 이어붙인것:%s",testDir); //------------------------------------------------------------------------------------------------------- // _media_search(appdata); // Meta_Get_from_path(appdata,"/opt/usr/media/DCIM/Camera/%"); // int videoC = 0,imageC=0,musicC = 0 ; // media_Count(&videoC,&imageC,&musicC,"/opt/usr/media/DCIM/Camera/%"); break; case REQ_OPER_DLNA_APP://실행 요청시 dlog_print(DLOG_INFO,"tdlna","dlna on 처리"); if(!(appdata->run_tdlna)){ // 서비스가 꺼져있는 상태라면 if(appdata->tdlna_td != 0){ dlog_print(DLOG_ERROR,"tdlna", "이전 실행된 서비스가 정상적으로 종료되지 않았습니다."); return 0; } if(serviceOn(appdata)){ dlog_print(DLOG_INFO,"tdlna","★ 서비스 ON ★ %d", appdata->run_tdlna); resp_key_val = "DLNA:ON"; }else{ dlog_print(DLOG_INFO,"tdlna","★ 실행 실패! ★ %d", appdata->run_tdlna); resp_key_val = "DLNA:Failed"; } } else{ resp_key_val = "DLNA:RUNNING"; dlog_print(DLOG_INFO,"tdlna","★ 이미 실행중 ★ %d", appdata->run_tdlna); } break; case REQ_OPER_DLNA_APP_OFF://종료 요청시 if (!(appdata->run_tdlna)) {// 서비스가 꺼져있는 상태라면 resp_key_val = "DLNA:OFF"; dlog_print(DLOG_INFO, "tdlna", "★ 이미 종료상태★ %d",appdata->run_tdlna); } else { serviceOff(appdata); resp_key_val = "DLNA:OFF"; dlog_print(DLOG_INFO, "tdlna", "★ 서비스 OFF ★ %d",appdata->run_tdlna); } break; case REQ_OPER_DEVICE_ID://tDlnaName 주기 if(deviceName){ strcpy(appdata->deviceName, deviceName); setDeviceProperty(appdata);//tdlnamain으로 전달 sprintf(respStr, "%s%s", "tDlnaName/", deviceName); }else sprintf(respStr, "%s%s", "tDlnaName/", "nameError!"); resp_key_val = respStr; dlog_print(DLOG_INFO, "tdlna", "resp_key_val값 가져오기 %s",resp_key_val); break; case REQ_SHARED_FOLDER: resp_key_val = "공유폴더!"; dlog_print(DLOG_INFO, "tdlna", "%s 폴더 공유 실행",shared_folder); insertSharingList(); // _META *test; // int testC=0; // testC= Meta_Get_from_path(appdata,shared_folder,2,&test); // dlog_print(DLOG_INFO, "tdlna", "리스트갯수:%d",testC); // dlog_print(DLOG_INFO, "tdlna", "리스트 1 :%s",test[1].path); // free(test); break; case REQ_UNSHARED_FOLDER: resp_key_val = "공유해제 폴더!"; dlog_print(DLOG_INFO, "tdlna", "%s 폴더 공유 해제 실행",shared_folder); deleteSharingList(); //공유 해제 폴더 처리 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ break; default: DBG("Unknown request id"); return SVC_RES_FAIL; break; } RETVM_IF(bundle_add_str(resp_msg, "server", resp_key_val) != 0, SVC_RES_FAIL, "Failed to add data by key to bundle"); _app_send_response(appdata, resp_msg); bundle_free(resp_msg); return SVC_RES_OK; }
static int _app_process_received_message(bundle *rec_msg, bundle *resp_msg, req_operation *req_oper) { dlog_print(DLOG_INFO ,"tdlna", "_app_process_received_message 실행"); RETVM_IF(!rec_msg, SVC_RES_FAIL,"Received message is NULL"); RETVM_IF(!resp_msg, SVC_RES_FAIL,"Response message is NULL"); const char *resp_key_val = NULL; char *rec_key_val = NULL,*rec_share_folder = NULL,*rec_unshare_folder = NULL; int res_shared = 0; bool reciveOK = false; res_shared = bundle_get_str(rec_msg, "shared", &rec_share_folder); if (res_shared == BUNDLE_ERROR_NONE) {//공유 폴더 수신 reciveOK = true; RETVM_IF(res_shared != BUNDLE_ERROR_NONE, SVC_RES_FAIL, "Failed to get string from shared_bundle"); dlog_print(DLOG_INFO ,"tdlna", "공유폴더 수신: %s",rec_share_folder); resp_key_val = "(공유폴더) 수신"; *req_oper = REQ_SHARED_FOLDER; strcpy(shared_folder,rec_share_folder+7); // strcat(shared_folder,"\%"); dlog_print(DLOG_INFO ,"tdlna", "공유폴더 저장: %s",shared_folder); } res_shared = bundle_get_str(rec_msg, "unshared", &rec_unshare_folder); if (res_shared == BUNDLE_ERROR_NONE) {//공유 취소 폴더수신 reciveOK = true; RETVM_IF(res_shared != BUNDLE_ERROR_NONE, SVC_RES_FAIL, "Failed to get string from unshared_bundle"); dlog_print(DLOG_INFO ,"tdlna", "공유취소폴더 수신: %s",rec_unshare_folder); resp_key_val = "(공유취소폴더) 수신"; *req_oper = REQ_UNSHARED_FOLDER; strcpy(shared_folder,rec_unshare_folder+7); // strcat(shared_folder,"\%"); dlog_print(DLOG_INFO ,"tdlna", "공유취소폴더 저장: %s",rec_unshare_folder); } int res = bundle_get_str(rec_msg, "command", &rec_key_val); if (res == BUNDLE_ERROR_NONE){ reciveOK = true; RETVM_IF(res != BUNDLE_ERROR_NONE, SVC_RES_FAIL, "Failed to get string from bundle"); dlog_print(DLOG_INFO,"tdlna","웹앱으로 부터 서비스 수신:%s",rec_key_val); if (strcmp(rec_key_val, "server state") == 0) {//현재 상태 확인 요청 dlog_print(DLOG_INFO ,"tdlna", "서비스 상태확인요청"); resp_key_val = "(state) 수신"; *req_oper = REQ_OPER_STATE; } else if(strcmp(rec_key_val,"media folder") == 0){ dlog_print(DLOG_INFO ,"tdlna", "서비스 상태확인요청"); resp_key_val = "(media folder) 수신"; *req_oper = REQ_OPER_FOLDER; } else if (strcmp(rec_key_val,"meta") == 0) { resp_key_val = "metaget"; *req_oper = REQ_OPER_META_GET_APP; } else if (strcmp(rec_key_val,"dlna on") == 0)//서비스 ON 요청 { dlog_print(DLOG_INFO ,"tdlna", "서비스 ON 요청 app_process_received_message"); resp_key_val = "(dlna 실행)수신.."; *req_oper = REQ_OPER_DLNA_APP; //*req_oper = REQ_OPER_EXIT_APP; } else if (strcmp(rec_key_val,"dlna off") == 0)//서비스 ON 요청 { dlog_print(DLOG_INFO ,"tdlna", "서비스 OFF 요청 app_process_received_message"); resp_key_val = "(dlna 종료)수신.."; *req_oper = REQ_OPER_DLNA_APP_OFF; //*req_oper = REQ_OPER_EXIT_APP; } else if (strstr(rec_key_val, "getDeviceId") != NULL) { dlog_print(DLOG_INFO, "tdlna","디바이스ID 요청 app_process_received_message"); char *str = strtok(rec_key_val, "|"); dlog_print(DLOG_INFO, "tdlna","strtok: %s",str); str = strtok(NULL, "|"); dlog_print(DLOG_INFO, "tdlna","strtok: %s",str); if(str != NULL){ if(strcmp(str,"&") == 0){//사용자가 빈값을 입력했을때, 장치 기본값으로 변경 get_DeviceID(); }else{//새로운 name을 저장 strcpy(deviceName,str); } } resp_key_val = "(getDeviceId)수신"; *req_oper = REQ_OPER_DEVICE_ID; } } if(!reciveOK) { dlog_print(DLOG_ERROR ,"tdlna", "처리를 못하는 명령"); resp_key_val = "unsupported"; *req_oper = REQ_OPER_NONE; } RETVM_IF(bundle_add_str(resp_msg, "server", resp_key_val) != 0, SVC_RES_FAIL, "Failed to add data by key to bundle"); return SVC_RES_OK; }