3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
34 #include "MsgUtilFile.h"
35 #include "MsgContact.h"
36 #include "MsgUtilStorage.h"
37 #include "MsgGconfWrapper.h"
38 #include "MsgSqliteWrapper.h"
39 #include "MsgPluginManager.h"
40 #include "MsgStorageHandler.h"
45 /*==================================================================================================
47 ==================================================================================================*/
48 extern MsgDbHandler dbHandle;
51 /*==================================================================================================
52 FUNCTION IMPLEMENTATION
53 ==================================================================================================*/
54 MSG_ERROR_T MsgInitSimMessage(MSG_SIM_STATUS_T SimStatus)
56 MSG_DEBUG("Start SIM Message Initialization");
58 MSG_ERROR_T err = MSG_SUCCESS;
60 // Set SIM count of vconf to 0
61 if (MsgSettingSetInt(SIM_USED_COUNT, 0) != MSG_SUCCESS)
63 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
66 if (MsgSettingSetInt(SIM_TOTAL_COUNT, 0) != MSG_SUCCESS)
68 MSG_DEBUG("Error to set config data [%s]", SIM_TOTAL_COUNT);
71 if (SimStatus != MSG_SIM_STATUS_NOT_FOUND)
73 MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
74 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
78 MSG_DEBUG("No plugin for %d type", mainType);
79 return MSG_ERR_INVALID_PLUGIN_HANDLE;
83 MSG_DEBUG(" ** SIM is available - status : [%d] ** ", SimStatus);
85 err = plg->initSimMessage();
92 MSG_ERROR_T MsgStoClearSimMessageInDB()
94 MSG_ERROR_T err = MSG_SUCCESS;
96 char sqlQuery[MAX_QUERY_LEN+1];
98 queue<MSG_THREAD_ID_T> threadList;
100 // Get Address ID of SIM Message
101 memset(sqlQuery, 0x00, sizeof(sqlQuery));
103 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(B.ADDRESS_ID) \
105 WHERE A.ADDRESS_ID = B.ADDRESS_ID \
106 AND A.STORAGE_ID = %d",
107 MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, MSG_STORAGE_SIM);
111 err = dbHandle.getTable(sqlQuery, &rowCnt);
113 if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD)
115 MSG_DEBUG("sql query is %s.", sqlQuery);
117 dbHandle.freeTable();
123 dbHandle.freeTable();
127 for (int i = 1; i <= rowCnt; i++)
129 MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
130 threadList.push((MSG_THREAD_ID_T)dbHandle.getColumnToInt(i));
133 dbHandle.freeTable();
135 const char* tableList[] = {MSGFW_SMS_SENDOPT_TABLE_NAME, MSGFW_SIM_MSG_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME};
137 int listCnt = sizeof(tableList)/sizeof(char*);
139 dbHandle.beginTrans();
141 for (int i = 0; i < listCnt; i++)
143 memset(sqlQuery, 0x00, sizeof(sqlQuery));
145 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN \
146 (SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d);",
147 tableList[i], MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
149 // Delete SIM Message in tables
150 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
152 dbHandle.endTrans(false);
153 return MSG_ERR_DB_EXEC;
157 // Clear Address table
158 if (MsgStoClearAddressTable(&dbHandle) != MSG_SUCCESS)
160 dbHandle.endTrans(false);
161 return MSG_ERR_DB_EXEC;
165 while (!threadList.empty())
167 err = MsgStoUpdateAddress(&dbHandle, threadList.front());
171 if (err != MSG_SUCCESS)
173 dbHandle.endTrans(false);
178 dbHandle.endTrans(true);