Tizen 2.1 base
[platform/core/system/sync-agent.git] / include / account / manager.h
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #ifndef ACCOUNT_MANAGER_H_
19 #define ACCOUNT_MANAGER_H_
20
21 #include <glib.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif                          /* __cplusplus */
26
27 /**
28  * @file        manager.h
29  * @brief       Support to use framework Account module
30  */
31
32 /** @addtogroup account
33  *      @{
34  */
35
36 /**
37  * @brief       Enumerations of error codes for Account module
38  */
39         typedef enum {
40                 SYNC_AGENT_ACC_SUCCESS,
41                                 /**< when account operation is succeed */
42                 SYNC_AGENT_ACC_FAIL,            /**< when account operation is failed */
43                 SYNC_AGENT_ACC_EMPTY,   /**< when account is not exist */
44                 SYNC_AGENT_ACC_CHANGED
45                                 /**< when account storage changed */
46         } sync_agent_acc_error_e;
47
48 /**
49  * @brief       Structure of Framework Account instance
50  */
51         typedef struct {
52                 int account_id; /**< account id */
53                 char *email;    /**< e-mail address */
54                 char *password; /**< password */
55                 int enable;     /**< state flag */
56                 char *access_name;      /**< access name */
57         } sync_agent_fw_account_s;
58
59 /**
60  * @brief       Enumerations of Account query type
61  */
62         typedef enum {
63                 ACCOUNT_QUERY_BY_NONE,  /**< type of no query  */
64                 ACCOUNT_QUERY_BY_ACCESS_NAME,   /**< type by access name  */
65                 ACCOUNT_QUERY_BY_SERVICE_TYPE,  /**< type by service  */
66                 ACCOUNT_QUERY_BY_SERVICE_TYPE_SERVICE_ID_INDEX, /**< type by service id  */
67         } sync_agent_fw_account_query_type_e;
68
69 /**
70  * @brief       Structure of Framework Account query instance
71  */
72         typedef struct {
73                 sync_agent_fw_account_query_type_e query;       /**< type of query */
74                 char *access_name;      /**< access name */
75                 int service_type;       /**< service type */
76                 int service_account_id; /**< service account id */
77                 int index;      /**< index */
78                 int fw_account_id;      /**< framework account id */
79         } sync_agent_fw_account_query_s;
80
81 /**
82  * @brief               Create sync_agent_fw_account_s struct
83  * @par Usage:
84  * @code
85  
86  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
87  sync_agent_fw_account_s *fw_account = NULL;
88  
89  account_err = sync_agent_create_fw_account(&fw_account);
90  if (account_err != SYNC_AGENT_ACC_SUCCESS) {
91         ...
92  }
93  
94  * @endcode
95  * @param[out]  account instance of framework account info
96  * @return      SYNC_AGENT_ACC_SUCCESS  on success, otherwise a error value.
97  * @retval      SYNC_AGENT_ACC_SUCCESS  Successful
98  * @retval      SYNC_AGENT_ACC_FAIL              When memory allocation is failed
99  */
100         sync_agent_acc_error_e sync_agent_create_fw_account(sync_agent_fw_account_s ** account);
101
102 /**
103  * @brief               Register a new account to SyncAgent
104  * @par Usage:
105  * @code
106  
107  int account_id;
108  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
109  
110  account_err = sync_agent_add_fw_account(fw_account, &account_id);
111  if (account_err != SYNC_AGENT_ACC_SUCCESS) {
112         ...
113  }
114  
115  * @endcode
116  * @param[in]           account instance of framework account info
117  * @param[out]  account_id      framework account id
118  * @return      SYNC_AGENT_ACC_SUCCESS  on success, otherwise a error value.
119  * @retval      SYNC_AGENT_ACC_SUCCESS  Successful
120  * @retval      SYNC_AGENT_ACC_FAIL             When add account is failed
121  */
122         sync_agent_acc_error_e sync_agent_add_fw_account(sync_agent_fw_account_s * account, int *account_id);
123
124 /**
125  * @brief               Update account info
126  * @par Usage:
127  * @code
128  
129  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
130  
131  account_err = sync_agent_update_fw_account(fw_account);
132  if (account_err != SYNC_AGENT_ACC_SUCCESS) {
133         ...
134  }
135  
136  * @endcode
137  * @param[in]           account instance of framework account info
138  * @return      SYNC_AGENT_ACC_SUCCESS  on success, otherwise a error value.
139  * @retval      SYNC_AGENT_ACC_SUCCESS  Successful
140  * @retval      SYNC_AGENT_ACC_FAIL             When update account is failed
141  */
142         sync_agent_acc_error_e sync_agent_update_fw_account(sync_agent_fw_account_s * account);
143
144 /**
145  * @brief               Delete account
146  * @par Usage:
147  * @code
148  
149  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
150  
151  account_err = sync_agent_delete_fw_account(account_id);
152  if (account_err != SYNC_AGENT_ACC_SUCCESS) {
153         ...
154  }
155  
156  * @endcode
157  * @param[in]           account_id      framework account id
158  * @return      SYNC_AGENT_ACC_SUCCESS  on success, otherwise a error value.
159  * @retval      SYNC_AGENT_ACC_SUCCESS  Successful
160  * @retval      SYNC_AGENT_ACC_FAIL             When update account is failed
161  */
162         sync_agent_acc_error_e sync_agent_delete_fw_account(int account_id);
163
164 /**
165  * @brief               Get account info
166  * @par Usage:
167  * @code
168  
169  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
170  sync_agent_fw_account_s *fw_account = NULL;
171  
172  account_err = sync_agent_get_fw_account(account_id, &fw_account);
173  if (account_err != SYNC_AGENT_ACC_SUCCESS) {
174         ...
175  }
176  
177  * @endcode
178  * @param[in]           account_id      framework account id
179  * @param[out]  account         instance of framework account info
180  * @return      SYNC_AGENT_ACC_SUCCESS  on success, otherwise a error value.
181  * @retval      SYNC_AGENT_ACC_SUCCESS  Successful
182  * @retval      SYNC_AGENT_ACC_FAIL     when update account is failed
183  */
184         sync_agent_acc_error_e sync_agent_get_fw_account(int account_id, sync_agent_fw_account_s ** account);
185
186 /**
187  * @brief               Get account info by query
188  * @par Usage:
189  * @code
190  
191  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
192  sync_agent_fw_account_query_s query;
193  GList *account_info_list = NULL;
194  
195  query.query = ACCOUNT_QUERY_BY_SERVICE_TYPE;
196  query.service_type = FW_CONTACT;
197  
198  account_err = sync_agent_query_fw_account(&query, &account_info_list);
199  if (account_err != SYNC_AGENT_ACC_SUCCESS)
200         ...
201  }
202  
203  * @endcode
204  * @param[in]           query   instance of framework account query
205  * @param[out]  list    list of instance of framework account info
206  * @return      SYNC_AGENT_ACC_SUCCESS  on success, otherwise a error value.
207  * @retval      SYNC_AGENT_ACC_SUCCESS  Successful
208  * @retval      SYNC_AGENT_ACC_FAIL     when update account is failed
209  */
210         sync_agent_acc_error_e sync_agent_query_fw_account(sync_agent_fw_account_query_s * query, GList ** list);
211
212 /**
213  * @brief               Free sync_agent_fw_account_s struct
214  * @par Usage:
215  * @code
216  
217  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
218  sync_agent_fw_account_s *fw_account = NULL;
219  
220  account_err = sync_agent_get_fw_account(account_id, &fw_account);
221  ...
222  sync_agent_free_fw_account(fw_account);
223  
224  * @endcode
225  * @param[in]           fw_account      instance of framework account info
226  */
227         void sync_agent_free_fw_account(sync_agent_fw_account_s * fw_account);
228
229 /**
230  * @brief               Free list of sync_agent_fw_account_s struct
231  * @par Usage:
232  * @code
233  
234  sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS;
235  sync_agent_fw_account_query_s query;
236  GList *account_info_list = NULL;
237  
238  query.query = ACCOUNT_QUERY_BY_SERVICE_TYPE;
239  query.service_type = 1;
240  
241  account_err = sync_agent_query_fw_account(&query, &account_info_list);
242  ...
243  sync_agent_free_fw_account_list(account_info_list);
244  
245  * @endcode
246  * @param[in]           list    list of instance of framework account info
247  */
248         void sync_agent_free_fw_account_list(GList * list);
249
250 /**
251  * @}
252  */
253
254 #ifdef __cplusplus
255 }
256 #endif                          /* __cplusplus */
257 #endif                          /* ACCOUNT_MANAGER_H_ */