Query available modems and connect to first modem found
[profile/ivi/phoned.git] / src / ofono.h
1 #ifndef OFONO_H_
2 #define OFONO_H_
3
4 #include <glib.h>
5 #include <dbus/dbus.h>
6 #include <gio/gio.h>
7 #include <string>
8 #include <string.h>
9 #include <map>
10
11 namespace PhoneD {
12
13 /**
14  * @addtogroup phoned
15  * @{
16  */
17
18 /*! \class PhoneD::OFono
19  *  \brief Class which is utilizing OFono D-Bus service. It is a base class and is not meant to be instantiated directly.
20  *
21  * A class providing access to <a href="http://www.ofono.org">OFono</a> functionality. It allows make a phone call, answer/decline incoming call, hang-up active phone call.
22  */
23 class OFono {
24
25     public:
26
27     /*! \class Call
28      *  \brief A Class describing phone call object.
29      *
30      * A class describing phone call object. It is used to get information about active call.
31      */
32     class Call {
33         public:
34             /**
35              * A default constructor which constructs an empty object with NULL initialized members.
36              */
37             Call() : path(NULL), state(NULL), line_id(NULL) {};
38             /**
39              * Copy constructor to make a copy from the Call object specified by the pointer to it.
40              * @param[in] call A pointer to Call object to make a copy of.
41              */
42             Call(OFono::Call *call) {
43                 if(call->path)  path = strdup(call->path);
44                 if(call->state) state = strdup(call->state);
45                 if(call->line_id) line_id = strdup(call->line_id);
46             };
47             /**
48              * A destructor which frees the allocated memory of member variables and destroys the object.
49              */
50             ~Call() {
51                 if(path)    { g_free(path);    path=NULL;    }
52                 if(state)   { g_free(state);   state=NULL;   }
53                 if(line_id) { g_free(line_id); line_id=NULL; }
54             };
55         public:
56             char *path;     /*!< A path to the call object */
57             char *state;    /*!< A state of phone call (incoming,dialing,active,disconnected) */
58             char *line_id;  /*!< A line identifier. It contains a phone number of the caller, or the calling person respectively. */
59     };
60
61     public:
62         /**
63          * A default constructor. Constructs the object and subscribes for certain D-Bus signals of \b org.ofono service:
64          * <ul>
65          * <li> "ModemAdded" on \b org.ofono.Manager interface - To get notified when modem is added. </li>
66          * <li> "ModemRemoved" on \b org.ofono.Manager interface - To get notified when modem is removed.</li>
67          * </ul>
68          * It starts a timer to check whether default modem is \b Powered, or not. It handles the case, when the device gets out of the range, or when the user
69          * turns OFF and then turns ON the BT on the phone device, in which case there isn't a notification that the remote device got back.
70          * The timer in specific interval checks whether the modem is \b Powered and if not, it tries to power it up.
71          */
72         OFono();
73
74         /**
75          * A destructor. Unselects default modem and destructs the object. @see selectModem() and unselectModem()
76          */
77         ~OFono();
78
79         /**
80          * A method to select modem. It gets the list of available modems and checks them against the given MAC address. If the modem is for the device specified by the given MAC address, it is selected as default one.
81          * @param[in] btAddress A MAC address of a remote BT device for which the modem should be selected.
82          * @see unselectModem()
83          */
84         void selectModem(std::string &btAddress);
85
86         /**
87          * A method to unselect the default modem.
88          * @see selectModem()
89          */
90         void unselectModem();
91
92         /**
93          * A method to invoke phone call.
94          * @param[in] phoneNumber A phone number to invoke phone call.
95          * @param[out] error If the return value from the method is \b false, it contains a description of the error. The caller is responsible for freeing the memory if the error is set.
96          * @return \b True if D-Bus "Dial" method was successfuly called on \b org.ofono.VoiceCallManager interface, otherwise it returns \b false.
97          */
98         bool invokeCall(const char* phoneNumber, char **error);
99
100         /**
101          * A method to answer incoming phone call.
102          * @param[out] error If the return value from the method is \b false, it contains a description of the error. The caller is responsible for freeing the memory if the error is set.
103          * @return \b True if D-Bus "Answer" method was successfuly called on \b org.ofono.VoiceCall interface, otherwise it returns \b false.
104          */
105         bool answerCall(char **error);
106
107         /**
108          * A method to decline incoming, or hangup active phone call.
109          * @param[out] error If the return value from the method is \b false, it contains a description of the error. The caller is responsible for freeing the memory if the error is set.
110          * @return \b True if D-Bus "Hangup" method was successfuly called on \b org.ofono.VoiceCall interface, otherwise it returns \b false.
111          */
112         bool hangupCall(char **error);
113
114         /**
115          * A method to mute/unmute active phone call.
116          * @param[in] mute Specifies whether to mute/unmute phone call.
117          * @param[out] error If the return value from the method is \b false, it contains a description of the error. The caller is responsible for freeing the memory if the error is set.
118          * @return \b True if D-Bus "SetProperty" method to set "Muted" property was successfuly called on \b org.ofono.CallVolume interface, otherwise it returns \b false.
119          */
120         bool muteCall(bool mute, char **error);
121
122         /**
123          * Gets the information about active phone call. It creates new object (allocates a memory) and the caller has to delete it.
124          * @return OFono::Call object describing active phone call.
125          */
126         OFono::Call *activeCall();
127
128     private:
129         static void asyncSelectModemCallback(GObject *source, GAsyncResult *result, gpointer user_data); // async callback for "GetModems" invoked from selectModem() method
130         virtual void callChanged(const char* state, const char* phoneNumber) = 0;
131
132         void addModem(const char *path, GVariantIter *props);
133         virtual void modemAdded(std::string &modem) = 0; // MAC address of modem ... from ModemAdded DBUS
134         void removeModem(const char *modemPath);
135         virtual void modemPowered(bool powered) = 0;
136         virtual void setModemPoweredFailed(const char *err) = 0;
137         static void handleSignal(GDBusConnection *connection,  const gchar     *sender,
138                                  const gchar     *object_path, const gchar     *interface_name,
139                                  const gchar     *signal_name, GVariant        *parameters,
140                                  gpointer         user_data);
141
142         //DBUS: array{object,dict}
143         void getModems(); //Get an array of call object paths and properties of available modems
144         void getCalls(); //Get an array of call object paths and properties that represents the currently present calls.
145         void addCall(const char *path, GVariantIter *props);
146         void removeCall(OFono::Call **call);
147
148         // used to set property on ifaces that do have same object path, eg. Modem, CallVolume, ...
149         bool setProperty(const char* iface, const char* path, const char *property, int type, void *value); // returns success of the operation
150         void setPropertyAsync(const char* iface, const char* path, const char *property, int type, void *value, GAsyncReadyCallback callback);
151
152         void setModemPowered(const char *path, bool powered); // path of Modem object
153         bool isModemPowered(const char *modem);
154         static void asyncSetModemPoweredCallback(GObject *source, GAsyncResult *result, gpointer user_data); // async callback for "SetProperty" invoked from setModemPowered() method
155         static gboolean checkForModemPowered(gpointer user_data); // continuous timeout method to check for 'Selected' modem being Powered and power it on, if it's not
156
157         static void GDbusAsyncReadyCallback(GObject *source, GAsyncResult *result, gpointer user_data);
158
159     private:
160         DBusConnection               *mDBusConnection;
161         gchar                        *mModemPath;
162         OFono::Call                  *mActiveCall;
163 };
164
165 #endif /* OFONO_H_ */
166
167 } // PhoneD
168
169 /** @} */
170