4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include "cal_typedef.h"
25 #include "cal_internal.h"
26 #include "cal_db_plugin_book_helper.h"
27 #include "cal_server_contacts.h"
29 static pthread_mutex_t cal_mutex_account = PTHREAD_MUTEX_INITIALIZER;
30 static account_subscribe_h cal_account_h = NULL;
32 static bool _noti_cb(const char* event_type, int account_id,
37 if (CAL_STRING_EQUAL == strcmp(event_type, ACCOUNT_NOTI_NAME_DELETE)) {
38 cal_db_delete_account(account_id);
39 cal_server_contacts_delete(account_id);
44 int cal_server_account_init(void)
48 pthread_mutex_lock(&cal_mutex_account);
49 ret = account_subscribe_create(&cal_account_h);
50 if (ACCOUNT_ERROR_NONE != ret) {
52 ERR("account_subscribe_create() Fail(%d)", ret);
53 pthread_mutex_unlock(&cal_mutex_account);
54 return CALENDAR_ERROR_SYSTEM;
58 ret = account_subscribe_notification(cal_account_h, _noti_cb, NULL);
59 if (ACCOUNT_ERROR_NONE != ret)
60 WARN("account_subscribe_notification Failed (%d)", ret);
62 pthread_mutex_unlock(&cal_mutex_account);
63 return CALENDAR_ERROR_NONE;
66 void cal_server_account_deinit(void)
68 pthread_mutex_lock(&cal_mutex_account);
71 account_unsubscribe_notification(cal_account_h);
75 pthread_mutex_unlock(&cal_mutex_account);