upload tizen1.0 source
[profile/ivi/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 protected:
58         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookGetPtr &event);
59         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddPtr &event);
60         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
61         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookUpdatePtr &event);
62         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
63         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemovePtr &event);
64         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
65         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
66         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddChangeListenerPtr &event);
67         virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveChangeListenerPtr &event);
68
69 private:
70         int m_latestVersion;
71
72         TizenApis::Api::Contact::ContactPtr internalGetById(const std::string &contactId);
73
74         void internalAddContact(const TizenApis::Api::Contact::ContactPtr &newContact);
75         void internalDeleteContactById(int id);
76         DPL::Mutex      m_contactEditingMutex;
77
78         typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter> AddressBookChangedEmitter;
79         AddressBookChangedEmitter       m_addressBookEmitters;
80         DPL::Mutex      m_addressBookEmittersMutex;
81
82         typedef std::map<long, TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter::IdType> WatchIdMap;
83         WatchIdMap m_watchIdMap;
84         long m_watchIdAcc;
85
86 public:
87         static void contactsSvcContactChangedCallback(void *data);
88
89 private:
90         void contactsSvcContactChangedCallback();
91 };
92
93 } // Contact
94 } // Platform
95 } // TizenApis
96
97 #endif // _PLATFORM_CONTACT_ADDRESS_BOOK_H_