3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include <sync_agent.h>
25 #include "common/dm_common_def.h"
26 #include "common/dm_common.h"
27 #include "common/util/util.h"
28 #include "framework/task/oma_dm_task_request.h"
29 #include "framework/san-parser/pm_sanparser.h"
30 #include "dm-engine/dm_common_engine.h"
31 #include "dm-engine/fumo/fumo_engine.h"
32 #include "dm-engine/lawmo/lawmo_engine.h"
33 #include "mo-handler/dm_mo_common_internal.h"
34 #include "mo-handler/dm_mo_common.h"
35 #include "serviceadapter/dm-phase-handler/dm_phase_handler.h"
36 #include "serviceadapter/sa_define.h"
37 #include "serviceadapter/sa_session.h"
38 #include "serviceadapter/sa_session_internal.h"
39 #include "ipc_common.h"
40 #include "ipc_agent.h"
42 #ifndef OMADM_AGENT_LOG
44 #define LOG_TAG "COMMON_ENGINE"
47 static DM_ERROR _change_engine_status(char *server_id, char *full_path, char *correlator, int service_engine_status);
49 static DM_ERROR _change_engine_status(char *server_id, char *full_path, char *correlator, int service_engine_status)
54 retvm_if((server_id) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
55 retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
58 task_id = sync_agent_get_self_request_id();
59 _DEBUG_TRACE("service engine db update");
61 engine_status *status;
64 is_exist = IsExist_Engine_id(service_engine_status);
67 ret = Get_Engine_Status(service_engine_status, &status);
68 _DEBUG_TRACE("get engine status : %d", ret);
70 status = (engine_status *) calloc(1, sizeof(engine_status));
71 _DEBUG_TRACE("get engine status error");
75 _DEBUG_TRACE("calloc failed !!");
76 ret = COMMON_ERR_ALLOC;
80 if (correlator != NULL) {
81 status->correlator = strdup(correlator);
83 status->correlator = NULL;
86 status->engine_status = DM_SERVICE_ING;
87 status->engine_id = service_engine_status;
88 status->mo_path = strdup(full_path);
89 status->server_url = NULL;
90 status->result_status = DM_OK;
91 status->server_id = strdup(server_id);
92 status->task_id = task_id;
93 status->ui_noti_type = 0;
94 status->download_click = 0;
98 /* if(IsExist_Engine_id(SERVICE_ENGINE)) {
99 ret = Delete_Engine_Status(SERVICE_ENGINE);
101 ret = Update_Engine_Status(status);
102 _DEBUG_TRACE(" update engine status : %d \n", ret);
105 Free_Memory_Engine_Status(&status, 1);
108 // DB_End_Transaction(TRANSACTION_ROLLBACK_);
112 /* ret = Update_Engine_Status_Column(IDLE_ENGINE, VALUE_ENGINE_STATUS, &service_engine_status);
113 _DEBUG_TRACE(" update engine status : %d \n", ret);
115 DB_End_Transaction(TRANSACTION_ROLLBACK_);
123 _DEBUG_TRACE(" end error : %d \n", ret);
128 void init_Dm_Engine()
132 /* always rebooting operation but excepted bootstrap */
139 DM_ERROR engine_start(char *server_id, char *full_path, char *correlator, ENGINE_ID * service_engine_id, int *resultCode)
143 DM_ERROR ret = DM_OK;
145 if (server_id == NULL || full_path == NULL) {
146 (*resultCode) = CLIENT_ERROR;
147 ret = COMMON_ERR_IS_NULL;
151 sync_agent_dm_mo_error_e err_code = SYNC_AGENT_DM_MO_SUCCESS;
152 sync_agent_dm_mo_type_e mo_type;
154 err_code = sync_agent_get_mo_type(full_path, &mo_type);
155 _DEBUG_INFO("get mo type result : %d", err_code);
157 (*resultCode) = DM_ERR_ACCEPTED_FOR_PROCESSING;
159 _DEBUG_INFO(" ------------------------------------------------------------------------------------------------------------------------------------- ");
160 _DEBUG_INFO(" mo_type : %d , server id : %s , full_path : %s , correlator : %s ", mo_type, server_id, full_path, correlator);
161 _DEBUG_INFO(" ------------------------------------------------------------------------------------------------------------------------------------- ");
164 case SYNC_AGENT_DM_MO_TYPE_FUMO:
166 _DEBUG_INFO("---------------------------------------------------------------- fumo engine ready --------------------------------------------------------------------- ");
167 ret = _change_engine_status(server_id, full_path, correlator, FUMO_SERVICE_ENGINE);
171 if (correlator == NULL) {
172 /*because of gcf server */
173 /*ret = fumo_exec(full_path, correlator, (FUMO_Error *)resultCode);
178 *service_engine_id = FUMO_SERVICE_ENGINE;
181 case SYNC_AGENT_DM_MO_TYPE_LAWMO:
182 _DEBUG_INFO("---------------------------------------------------------------- lawmo engine ready --------------------------------------------------------------------- ");
183 ret = _change_engine_status(server_id, full_path, correlator, LAWMO_SERVICE_ENGINE);
188 // 1 : this is just check , available operation
189 ret = lawmo_exec(full_path, correlator, (LAWMO_Result_code *) resultCode, CHECK_OPERATION);
194 *service_engine_id = LAWMO_SERVICE_ENGINE;
198 (*resultCode) = CLIENT_ERROR;
199 _DEBUG_INFO(" not existed engine \n");
203 _DEBUG_INFO("====================result code : %d====================\n", *resultCode);
204 _DEBUG_INFO(" end!! resut code : %d\n", *resultCode);
209 _DEBUG_INFO("====================result code : %d====================\n", *resultCode);
210 _DEBUG_INFO(" error end %d result code : %d", ret, *resultCode);
215 DM_ERROR service_engine_start(ENGINE_ID service_engine_id, DM_ERROR * service_ret)
219 _DEBUG_INFO(" start : service_engine_id : %d", service_engine_id);
220 DM_ERROR ret = DM_OK;
221 engine_status *service_status = NULL;
222 engine_status *after_service_status = NULL;
223 char *full_path = NULL;
224 char *correlator = NULL;
225 char *server_id = NULL;
226 int service_engine_status;
227 bool cancel_flag = 0;
229 cancel_flag = sync_agent_check_cancel_flag();
230 if (cancel_flag != 0) {
231 ret = DM_ERR_OPERATION_CANCELLED;
235 if (IsExist_Engine_id(service_engine_id) == 1) {
237 _DEBUG_INFO("service engine id = %d\n", service_engine_id);
238 _DEBUG_INFO(" engine must re-start");
240 ret = Get_Engine_Status(service_engine_id, &service_status);
241 _DEBUG_INFO(" get engine status : %d \n", ret);
245 if (service_status == NULL) {
246 _DEBUG_INFO("service status is null");
247 ret = COMMON_ERR_IS_NULL;
251 if (service_status->engine_status == DM_SERVICE_UNKNOWN) {
252 _DEBUG_INFO("engine status unknown");
256 if (service_status->engine_status == DM_SERVICE_ING) {
257 _DEBUG_INFO("-------------------------------------------- service type ------------------------------------------------ : %d", service_engine_id);
259 int engine_return = OPERATION_SUCCEEDED;
261 if (service_status->mo_path != NULL) {
262 full_path = strdup(service_status->mo_path);
263 _DEBUG_INFO("full path : %s ", full_path);
265 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
269 if (service_status->server_id != NULL) {
270 server_id = strdup(service_status->server_id);
271 _DEBUG_INFO("server_id : %s", server_id);
273 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
277 if (service_status->correlator != NULL) {
278 correlator = strdup(service_status->correlator);
279 _DEBUG_INFO("correlator : %s", correlator);
282 _DEBUG_INFO("service status : %d", service_status->engine_status);
284 switch (service_engine_id) {
285 case FUMO_SERVICE_ENGINE:
286 _DEBUG_INFO(" fumo exec");
287 ret = fumo_exec(full_path, correlator, (FUMO_Error *) (&engine_return));
288 _DEBUG_INFO("fumo ret : %d", ret);
290 if (ret != DM_OK && ret != DM_ERR_USER_CANDELLED && ret != DM_ERR_REMINDER_INTERVAL /*|| ret != DM_ERR_DEVICE_ABORTED */ )
293 case LAWMO_SERVICE_ENGINE:
294 _DEBUG_INFO(" lawmo exec");
295 ret = lawmo_exec(full_path, correlator, (LAWMO_Result_code *) (&engine_return), NON_CHECK_OPERATION);
296 _DEBUG_INFO("lawmo ret : %d", ret);
304 _DEBUG_INFO("exe resutlt : %d , server id : %s", engine_return, server_id);
305 _DEBUG_INFO("correlator : %s", correlator);
307 ret = Get_Engine_Status(service_engine_id, &after_service_status);
308 _DEBUG_INFO(" get engine status : %d \n", ret);
312 if (after_service_status == NULL) {
313 _DEBUG_INFO("service status is null");
314 ret = COMMON_ERR_IS_NULL;
318 if (after_service_status->download_click != RESUME_STATUS_INSTALL_BEFORE) {
319 /*engine status generic alert status */
320 service_engine_status = DM_GENERICALERT_ING;
321 ret = Update_Engine_Status_Column(service_engine_id, VALUE_ENGINE_STATUS, &service_engine_status);
322 _DEBUG_INFO("service engine status generic alert");
324 ret = Update_Engine_Status_Column(service_engine_id, VALUE_RESULT_STATUS, &engine_return);
325 _DEBUG_INFO("service engine status generic alert status : %d", engine_return);
328 str_free(&full_path);
329 str_free(&correlator);
330 str_free(&server_id);
332 if (service_status != NULL) {
333 Free_Memory_Engine_Status(&service_status, 1);
335 if (after_service_status != NULL) {
336 Free_Memory_Engine_Status(&after_service_status, 1);
340 if (service_status != NULL) {
341 Free_Memory_Engine_Status(&service_status, 1);
343 _DEBUG_INFO(" non service engine ing");
347 _DEBUG_INFO(" non service engine ");
354 if (service_status != NULL) {
355 Free_Memory_Engine_Status(&service_status, 1);
358 if (after_service_status != NULL) {
359 Free_Memory_Engine_Status(&after_service_status, 1);
362 str_free(&full_path);
363 str_free(&correlator);
364 str_free(&server_id);
365 _DEBUG_INFO(" error end %d ", ret);
370 DM_ERROR set_engine_status_idle(ENGINE_ID service_engine_id)
374 DM_ERROR ret = DM_OK;
376 if (IsExist_Engine_id(service_engine_id) == 1) {
377 _DEBUG_INFO("service engine id = %d\n", service_engine_id);
380 ret = set_end_engine_status_idle();
387 _DEBUG_INFO(" error end %d ", ret);
392 DM_ERROR set_end_engine_status_idle()
396 DM_ERROR ret = DM_OK;
398 int common_engine_status = DM_IDLE;
399 _DEBUG_INFO(" engine idle");
400 ret = Update_Engine_Status_Column(IDLE_ENGINE, VALUE_ENGINE_STATUS, &common_engine_status);
408 _DEBUG_INFO(" error end %d ", ret);
413 DM_ERROR dm_common_start(Event_Contents * pEvent_data)
417 DM_ERROR ret = DM_OK;
419 retvm_if((pEvent_data) == NULL, COMMON_ERR_IS_NULL, "pEvent_data is NULL!!");
421 ret = dm_common_operation(pEvent_data);
430 _DEBUG_INFO(" end!! error : %d\n", ret);
436 DM_ERROR dm_common_operation(Event_Contents * pEvent_data)
440 DM_ERROR ret = DM_OK;
442 retvm_if((pEvent_data) == NULL, COMMON_ERR_IS_NULL, "pEvent_data is NULL!!");
445 return_ret = remove(OMA_DM_MSG_PATH);
446 _DEBUG_INFO(" result file remove /tmp/dm.txt =[%d]\n", return_ret);
448 DM_ERROR service_ret = DM_OK;
449 ENGINE_ID service_engine_id = NO_SERVICE_ENGINE;
450 char *session_id = NULL;
451 char *server_id = NULL;
454 ret = get_server_info(pEvent_data, &server_id, &session_id, &session_type);
459 get_service_engine_id(&service_engine_id, pEvent_data->ui_mode);
463 int isgeneticAlert = 0;
464 void *session = NULL;
465 _DEBUG_INFO("----------------------------------------------------------------------------------------------------------\n");
466 _DEBUG_INFO(" setupphase Msg \n");
467 _DEBUG_INFO("----------------------------------------------------------------------------------------------------------\n");
468 ret = setup_phase(1, (Session **) & session, server_id, session_id, session_type, &service_engine_id, &isFinish, isgeneticAlert);
470 _DEBUG_INFO("connect to server fail in dm common operation (authentication fail or network fail)");
471 _DEBUG_INFO(" result =[%d]\n", ret);
480 _DEBUG_INFO("----------------------------------------------------------------------------------------------------------\n");
481 _DEBUG_INFO(" management Msg \n");
482 _DEBUG_INFO("----------------------------------------------------------------------------------------------------------\n");
483 ret = management_phase(1, (Session **) (&session), NULL, &service_engine_id, &isFinish);
489 _DEBUG_INFO("isFinish : %d\n", isFinish);
490 _DEBUG_INFO("----------------------------------------------------------------------------------------------------------\n");
492 ret = service_engine_start(service_engine_id, &service_ret);
496 ret = genericalert_operation(&session, &isFinish, service_engine_id);
500 set_engine_status_idle(service_engine_id);
503 terminate_oma_dm_ui(service_ret, service_engine_id);
510 terminate_oma_dm_ui(service_ret, service_engine_id);
512 if (ret == DM_ERR_OPERATION_CANCELLED && service_ret == DM_ERR_OPERATION_CANCELLED) {
513 Delete_Engine_Status(service_engine_id);
514 _DEBUG_INFO("Delete fumo service engine");
517 set_engine_status_idle(service_engine_id);
519 if (service_engine_id != NO_SERVICE_ENGINE) {
521 if (service_engine_id != FUMO_SERVICE_ENGINE && check_existed_fumo_reminder_interval() == 0) {
522 Delete_Engine_Status(service_engine_id);
523 _DEBUG_INFO("Delete fumo service engine");
527 _DEBUG_INFO(" end error ret : %d\n", ret);
532 DM_ERROR genericalert_operation(void **session, int *isFinish, ENGINE_ID service_engine_id)
537 DM_ERROR ret = DM_OK;
538 char *pServer_id = NULL;
539 engine_status *status = NULL;
541 if (IsExist_Engine_id(service_engine_id) == 1) {
542 ret = Get_Engine_Status(service_engine_id, &status);
545 _DEBUG_INFO(" result =[%d]\n", ret);
547 _DEBUG_INFO("server id : %s", status->server_id);
548 _DEBUG_INFO("engine_id : %d", status->engine_id);
549 _DEBUG_INFO("correlator : %s", status->correlator);
550 _DEBUG_INFO("engine_status : %d", status->engine_status);
551 _DEBUG_INFO("result status : %d", status->result_status);
552 _DEBUG_INFO("mo path : %s", status->mo_path);
553 _DEBUG_INFO("server url : %s", status->server_url);
555 if (status->engine_status == DM_GENERICALERT_ING) {
556 _DEBUG_INFO(" ----------------------------------------------------------------------generic alert-------------------------------------------------------------------------------");
557 _DEBUG_INFO("service engine id = %d\n", service_engine_id);
560 int isgeneticAlert = 1;
562 if (status->server_id != NULL) {
563 pServer_id = strdup(status->server_id);
564 _DEBUG_INFO(" server id is %s", status->server_id);
566 _DEBUG_INFO(" server id is NULL");
567 ret = COMMON_ERR_IS_NULL;
570 //void * session = NULL;
572 ret = generic_alert(1, (Session **) session, pServer_id, NULL, isFinish, isgeneticAlert, service_engine_id, status->result_status);
575 _DEBUG_INFO(" result =[%d]\n", ret);
577 /*update engine_status */
578 status->engine_status = DM_SERVICE_UNKNOWN;
579 ret = Update_Engine_Status(status);
580 _DEBUG_INFO(" update engine status : %d \n", ret);
582 str_free(&pServer_id);
585 _DEBUG_INFO("non generic alert");
588 if (status != NULL) {
589 Free_Memory_Engine_Status(&status, 1);
597 str_free(&pServer_id);
599 Free_Memory_Engine_Status(&status, 1);
601 _DEBUG_INFO(" error end ret : %d\n", ret);