Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Contact / AddressBookController.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        AddressBookController.h
19  * @author      Kisub Song (kisubs.song@samsung.com)
20  * @version     0.1
21  * @brief
22  */
23
24 #ifndef _TIZEN_CONTACT_ADDRESS_BOOK_CONTROLLER_H_
25 #define _TIZEN_CONTACT_ADDRESS_BOOK_CONTROLLER_H_
26
27 #include <dpl/log/log.h>
28 #include <dpl/shared_ptr.h>
29 #include <Commons/EventReceiver.h>
30 #include <Commons/EventListener.h>
31 #include <CommonsJavaScript/PrivateObject.h>
32 #include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
33 #include <CommonsJavaScript/JSPendingOperation.h>
34 #include <API/Contact/IAddressBook.h>
35
36 namespace TizenApis {
37 namespace Tizen1_0 {
38 namespace Contact {
39
40 typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::IAddressBookPtr,
41                                                            WrtDeviceApis::CommonsJavaScript::NoOwnership> AddressBookPrivObject;
42
43 typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookAddBatch> EventAddressBookAddBatchEventAnswerReceiver;
44 typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookUpdateBatch> EventAddressBookUpdateBatchEventAnswerReceiver;
45 typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookRemoveBatch> EventAddressBookRemoveBatchEventAnswerReceiver;
46 typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookFind> EventAddressBookFindEventAnswerReceiver;
47 typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Contact::EventAddressBookChangeListener> EventAddressBookChangeListenerListener;
48
49 class AddressBookController :
50         public EventAddressBookAddBatchEventAnswerReceiver,
51         public EventAddressBookUpdateBatchEventAnswerReceiver,
52         public EventAddressBookRemoveBatchEventAnswerReceiver,
53         public EventAddressBookFindEventAnswerReceiver,
54         public EventAddressBookChangeListenerListener,
55         public AddressBookPrivObject
56 {
57 public:
58         AddressBookController(JSContextRef context,
59                         TizenApis::Api::Contact::IAddressBookPtr addressBook);
60         virtual ~AddressBookController();
61 protected:
62         void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
63         void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
64         void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
65         void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
66         void     onAnswerReceived(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
67 };
68
69 typedef DPL::SharedPtr<AddressBookController> AddressBookControllerPtr;
70
71 // Pending operation objects
72 class AddressBookAddBatchPendingOperation : public WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject
73 {
74 public:
75         AddressBookAddBatchPendingOperation(
76                         DPL::SharedPtr<WrtDeviceApis::Commons::IEventController> &event) :
77                 WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject(event)
78         {
79         }
80         virtual void handleCallingCallbacks();
81 };
82
83 class AddressBookUpdateBatchPendingOperation : public WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject
84 {
85   public:
86         AddressBookUpdateBatchPendingOperation(
87                         DPL::SharedPtr<WrtDeviceApis::Commons::IEventController> &event) :
88                 WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject(event)
89         {
90         }
91         virtual void handleCallingCallbacks();
92 };
93
94 class AddressBookRemoveBatchPendingOperation : public WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject
95 {
96   public:
97         AddressBookRemoveBatchPendingOperation(
98                         DPL::SharedPtr<WrtDeviceApis::Commons::IEventController> &event) :
99                 WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject(event)
100         {
101         }
102         virtual void handleCallingCallbacks();
103 };
104
105 class AddressBookFindPendingOperation : public WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject
106 {
107   public:
108         AddressBookFindPendingOperation(
109                         DPL::SharedPtr<WrtDeviceApis::Commons::IEventController> &event) :
110                 WrtDeviceApis::CommonsJavaScript::IJSPendingOperationPrivateObject(event)
111         {
112         }
113         virtual void handleCallingCallbacks();
114 };
115
116 //common part
117 class AddressBookAsyncAnswerHandler
118 {
119 public:
120         static void addBatch(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
121         static void updateBatch(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
122         static void removeBatch(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
123         static void find(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
124         static void changeListenerError(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
125         static void changeListenerContactAdded(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
126         static void changeListenerContactUpdated(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
127         static void changeListenerContactRemoved(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
128         static void changeListenerAddressBookReset(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
129 };
130
131 } // Contact
132 } // Tizen1_0
133 } // TizenApis
134
135 #endif // _TIZEN_CONTACT_ADDRESS_BOOK_CONTROLLER_H_