merge wrt-plugins-tizen_0.2.0-3
[platform/framework/web/wrt-plugins-tizen.git] / src / platform / Tizen / Contact / AddressBook.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file        AddressBook.h
19  * @author      Kisub Song (kisubs.song@samsung.com)
20  * @version     0.1
21  * @brief
22  */
23
24 #ifndef _PLATFORM_CONTACT_ADDRESS_BOOK_H_
25 #define _PLATFORM_CONTACT_ADDRESS_BOOK_H_
26
27 #include <contacts-svc.h>
28
29 #include <string>
30 #include <vector>
31 #include <Commons/Emitters.h>
32 #include <API/Contact/IAddressBook.h>
33 #include <API/Contact/IContact.h>
34
35 namespace TizenApis {
36 namespace Platform {
37 namespace Contact {
38
39 class AddressBook : public TizenApis::Api::Contact::IAddressBook
40 {
41 private:
42         std::string             m_id;
43         std::string             m_name;
44         bool                    m_readOnly;
45
46 public:
47         explicit AddressBook(TizenApis::Api::Contact::IAddressBook::AddressBookType type);
48         virtual ~AddressBook();
49
50         virtual std::string getId() const { return m_id; }
51         virtual void        setId(const std::string &value) { m_id = value; }
52         virtual std::string getName() const { return m_name; }
53         virtual void            setName(const std::string &value) { m_name = value; }
54         virtual bool        getReadOnly() const { return m_readOnly; }
55         virtual void        setReadOnly(const bool &value) { m_readOnly = value; }
56
57         virtual TizenApis::Api::Contact::ContactPtr get(const std::string &contactId);
58         virtual void add(const TizenApis::Api::Contact::ContactPtr &contact);
59         virtual void update(const TizenApis::Api::Contact::ContactPtr &contact);
60         virtual void remove(const std::string &id);
61
62         virtual long addChangeListener(const TizenApis::Api::Contact::EventAddressBookChangeListenerEmitterPtr &emitter);
63         virtual void removeChangeListener(const long watchId);
64
65 protected:
66         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
67         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
68         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
69         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
70
71 private:
72         int m_latestVersion;
73
74         TizenApis::Api::Contact::ContactPtr internalGetById(const std::string &contactId);
75
76         void internalAddContact(const TizenApis::Api::Contact::ContactPtr &newContact);
77         void internalDeleteContactById(int id);
78         DPL::Mutex      m_contactEditingMutex;
79
80         typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter> AddressBookChangedEmitter;
81         AddressBookChangedEmitter       m_addressBookEmitters;
82         DPL::Mutex      m_addressBookEmittersMutex;
83
84 public:
85         static void contactsSvcContactChangedCallback(void *data);
86
87 private:
88         void contactsSvcContactChangedCallback();
89 };
90
91 } // Contact
92 } // Platform
93 } // TizenApis
94
95 #endif // _PLATFORM_CONTACT_ADDRESS_BOOK_H_