Initial checkin for phone daemon for the HTML5 UI
[profile/ivi/phoned.git] / src / phone.h
1 #ifndef PHONE_H_
2 #define PHONE_H_
3
4 #include <gio/gio.h>
5
6 #include "connman.h"
7 #include "bluez.h"
8 #include "ofono.h"
9 #include "obex.h"
10 #include "utils.h"
11
12 namespace PhoneD {
13
14 /**
15  * \brief A namespace for all classes used to construct \b phoned daemon.
16  * @namespace PhoneD
17  */
18
19 /**
20  * @defgroup phoned phoned daemon
21  * \brief Phoned daemon to provide a single point to access phone functionality.
22  *
23  * A module to provide a signle point to access phone functionality. It provides a phoned daemon, which registers itself on D-Bus as \b org.tizen.phone service and exports phone specific methods on D-Bus, as well as emits a phone specific signals on the bus. See Phone for more details.
24  *
25  * @addtogroup phoned
26  * @{
27  */
28
29 /*! \class PhoneD::Phone
30  *  \brief Class which is utilizing ConnMan, Bluez, OFono and Obex D-Bus services to be used for operations with a phone.
31  *
32  * Class which is utilizing ConnMan, Bluez, OFono and Obex D-Bus services and in controlled way exports them via D-Bus to be used by WRT plugin @link wrt-plugins-ivi-phone wrt-plugins-ivi-phone @endlink to provide access to phone functionality from Web application. \n
33  * In the construction phase, it requests to get own name on the D-Bus. Once the bus acquired callback is called, it starts setup procedure. It registers a service \b org.tizen.phone on D-Bus, registers Bluez agent for BT authentication and finaly starts OFono (selects and activates a modem) and Obex (creates a session) instances. ConnMan instance is used for initial powering up BT technology. Bluez is used to subscribe for BT specific notifications, such as notifications about \b Powered state of BT, notifications about paired and selected device being removed/unpaired, and many more.
34  *
35  * When it registers a service on D-Bus, it exports the following methods on \b org.tizen.Phone interface:
36  * <ul>
37  * <li> \b SelectRemoteDevice ( \a \b address ) Selects a remote device/phone, to which the phone operations should be performed at. Will emit \b RemoteDeviceSelected signal, once the device gets selected. </li>
38  *     <ul>
39  *     <li> \a \b address [in] \b 's' MAC address of a remote device to be selected. </li>
40  *     </ul>
41  *
42  * <li> \b GetSelectedRemoteDevice ( \a \b address ) Gets a currently selected remote device used for phone operations. It returns \b "" if no device is currently selected. </li>
43  *     <ul>
44  *     <li> \a \b address [out] \b 's' MAC address of selected remote device. </li>
45  *     </ul>
46  *
47  * <li> \b UnselectRemoteDevice () Unselects selected remote device. Will emit \b RemoteDeviceSelected signal with an address argument \b "". </li>
48  *
49  * <li> \b Dial ( \a \b number ) Dials a given phone number. </li>
50  *     <ul>
51  *     <li> \a \b number [in] \b 's' A phone number to dial. </li>
52  *     </ul>
53  *
54  * <li> \b Answer () Answers an incoming phone call. </li>
55  *
56  * <li> \b Mute ( \a \b muted ) Mutes/unmutes the active phone call. </li>
57  *     <ul>
58  *     <li> \a \b muted [in] \b 'b' Specifies whether to mute, or unmute the call. </li>
59  *     </ul>
60  *
61  * <li> \b Hangup () A method to decline incoming call, or hangup the active one. </li>
62  *
63  * <li> \b ActiveCall ( \a \b call ) Gets the active phone call in JSON format, or \b {} when there is no active call. </li>
64  *     <ul>
65  *     <li> \a \b call [out] \b 'a{sv}' An active call in JSON format. </li>
66  *     </ul>
67  *
68  * <li> \b Synchronize () Synchronizes PB data from the phone (Contacts, CallHistory).
69  *
70  * <li> \b GetContacts ( \a \b count, \a \b contacts ) Gets \a \b count first contacts in \b tizen.Contact JSON format, or \b [] when the data are not synchronized, or there are no contacts on the remote device. </li>
71  *     <ul>
72  *     <li> \a \b count [in] \b 'u' A number to specify how many first contacts should be returned. \a \b 0 means to return all contacts. </li>
73  *     <li> \a \b contacts [out] \b 's' Returned \a \b count countacts in \b tizen.Contact JSON format. </li>
74  *     </ul>
75  *
76  * <li> \b GetCallHistory ( \a \b count, \a \b calls ) Gets \a \b count latest call entries from the history in \b tizen.CallHistoryEntry JSON format, or \b [] when the data are not synchronized, or there are no calls in the history on the remote device. </li>
77  *     <ul>
78  *     <li> \a \b count [in] \b 'u' A number to specify how many latest call entries should be returned. </li>
79  *     <li> \a \b calls [out] \b 's' Returned latest \a \b count call entries in \b tizen.CallHistoryEntry JSON format. </li>
80  *     </ul>
81  *
82  * </ul>
83
84  * And emits the following signals:
85  * <ul>
86  * <li> \b RemoteDeviceSelected ( \a \b device ) A signal which is emitted when the selected remote device has changed, eg. the selected remote device has been selected, or when the remote device has been unselected, eg. due to connection lost with the remote device, or as a result of calling \b UnselectRemoteDevice method.
87  *     <ul>
88  *     <li> \a \b device [in] \b 's' A device in JSON format describing the change. </li>
89  *     </ul>
90  *
91  * <li> \b ContactsChanged () A signal which is emitted when there is a change in synchronized contacts.
92  *
93  * <li> \b CallHistoryChanged () A signal which is emitted when there is a change in synchronized call history, eg. due to made/received phone call.
94  *
95  * <li> \b CallHistoryEntryAdded ( \a \b call ) A signal which is emitted when a call has been added to the call history, eg. due to made/received phone call.
96  *     <ul>
97  *     <li> \a \b call \b 's' A call in \b tizen.CallHistoryEntry fromat that has been added to the call history.
98  *     </ul>
99  *
100  * <li> \b CallChanged ( \a \b call ) A signal which is emitted when there is a change in the active call. It indicates incoming, as well as the individual states that the call may go through, like "alerting", "active", "disconnected".
101  *     <ul>
102  *     <li> \a \b call \b '(a{sv})' A call object which specifies \a \b state of the call, \a \b line \a \b identifier (the phone number) and the \a \b contact if there is a match with the \a \b line_id.
103  *     </ul>
104  * </ul>
105  */
106 class Phone : public ConnMan, public Bluez, public OFono, public Obex {
107     public:
108         /**
109          * A default constructor which initializes individual services and sets BT adapter "Powered" ON. It requests a name \b org.tizen.phone to register itself on D-Bus. Once the bus acquired callback is called, it registers Bluez agent for BT authentification and starts OFono and Obex services.
110          */
111         Phone();
112
113         /**
114          * A destructor.
115          * Unregisters the service from D-Bus and destructs the object.
116          */
117         virtual ~Phone();
118
119     private:
120         void setup(); // called once the bus is acquired
121         void startServices(); // starts OFono/Obex services
122         void stopServices(); // stops OFono/Obex services
123         static void busAcquiredCb(GDBusConnection *gdbus, const gchar *name, gpointer data);
124         static void nameAcquiredCb(GDBusConnection *gdbus, const gchar *name, gpointer data);
125         static void nameLostCb(GDBusConnection *gdbus, const gchar *name, gpointer data);
126         static void handleMethodCall( GDBusConnection       *connection,
127                                       const gchar           *sender,
128                                       const gchar           *object_path,
129                                       const gchar           *interface_name,
130                                       const gchar           *method_name,
131                                       GVariant              *parameters,
132                                       GDBusMethodInvocation *invocation,
133                                       gpointer               user_data);
134
135         // Bluez stuff
136         virtual void adapterPowered(bool value); // to handle "Powered" property changed on ADAPTER, due to eg. RF-kill
137         virtual void defaultAdapterAdded();
138         virtual void defaultAdapterRemoved();
139         virtual void deviceCreated(const char *device);
140         virtual void deviceRemoved(const char *device);
141         // OFono stuff
142         virtual void callChanged(const char* state, const char* phoneNumber);
143         virtual void modemAdded(std::string &modem); // MAC address of modem ... from ModemAdded DBUS
144         virtual void modemPowered(bool powered);
145         virtual void setModemPoweredFailed(const char *err);
146         // Obex stuff
147         virtual void contactsChanged();
148         virtual void callHistoryChanged();
149         virtual void pbSynchronizationDone();
150         virtual void createSessionFailed(const char *err);
151         virtual void createSessionDone(const char *s);
152         virtual void removeSessionDone();
153         // NOTE: entry is valid only for the time of call this method
154         virtual void callHistoryEntryAdded(std::string &entry);
155         // active transfer is stalled - ??? session is down ???
156         virtual void transferStalled();
157         static gboolean delayedSyncCallHistory(gpointer user_data);
158
159         // function to store MAC address of selected remote device in persistent storage/file
160         // returns bool indicating result of the operation: false = failed, true = OK
161         bool storeSelectedRemoteDeviceMAC(const std::string &btAddress);
162         // function to read MAC address of selected remote device from persistent storage/file
163         // remote address is returned via 'btAddress' argument to the function
164         // returns bool indicating result of the operation: false = failed, true = OK
165         bool readSelectedRemoteDeviceMAC(std::string &btAddress);
166
167         // sets selected remote device MAC address
168         void setSelectedRemoteDevice(std::string &btAddress);
169
170     private:
171         bool mAdapterPowered; // variable to hold the state of Default adpater - not to try to 'CreateSession' 'cause it will result in Powering up the device, which is unwanted behavior
172         std::string mWantedRemoteDevice; // a remote device that is requested to be 'Selected'
173         std::string mSelectedRemoteDevice; // selected remote device - if initialization of OFono/Obex is successfull
174         bool mPBSynchronized; // indicating whether PB data are synchronized, or not
175         std::vector<CtxCbData*> mSynchronizationDoneListeners; // listeners to be notified once the synchronization finishes
176         guint mNameRequestId;
177         guint mRegistrationId;
178         GDBusNodeInfo *mIntrospectionData;
179         GDBusInterfaceVTable mIfaceVTable;
180 };
181
182 } // PhoneD
183
184 #endif /* PHONE_H_ */
185
186 /** @} */
187