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.
25 #include "cal_typedef.h"
26 #include "cal_internal.h"
27 #include "cal_db_plugin_book_helper.h"
28 #include "cal_server_contacts.h"
29 #include "cal_server_profile.h"
31 static pthread_mutex_t cal_mutex_account = PTHREAD_MUTEX_INITIALIZER;
32 static account_subscribe_h cal_account_h = NULL;
34 #ifndef TIZEN_FEATURE_NO_CONTACTS
35 static bool _noti_cb(const char* event_type, int account_id,
40 if (CAL_STRING_EQUAL == strcmp(event_type, ACCOUNT_NOTI_NAME_DELETE)) {
41 cal_db_delete_account(account_id);
42 cal_server_contacts_delete(account_id);
48 int cal_server_account_init(void)
55 pthread_mutex_lock(&cal_mutex_account);
56 ret = account_subscribe_create(&cal_account_h);
57 if (ACCOUNT_ERROR_NONE != ret) {
59 ERR("account_subscribe_create() Fail(%d)", ret);
60 pthread_mutex_unlock(&cal_mutex_account);
61 return CALENDAR_ERROR_SYSTEM;
65 ret = account_subscribe_notification(cal_account_h, _noti_cb, NULL);
66 if (ACCOUNT_ERROR_NONE != ret)
67 WARN("account_subscribe_notification Failed (%d)", ret);
69 pthread_mutex_unlock(&cal_mutex_account);
70 return CALENDAR_ERROR_NONE;
73 void cal_server_account_deinit(void)
78 pthread_mutex_lock(&cal_mutex_account);
81 account_unsubscribe_notification(cal_account_h);
85 pthread_mutex_unlock(&cal_mutex_account);