mce-dbus.h 12.8 KB
Newer Older
1 2 3 4 5
/**
 * @file mce-dbus.h
 * Headers for the D-Bus handling code for the Mode Control Entity
 * <p>
 * Copyright © 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
6
 * Copyright (C) 2013-2019 Jolla Ltd.
7
 * Copyright (c) 2019 Open Mobile Platform LLC.
8 9
 * <p>
 * @author David Weinehall <david.weinehall@nokia.com>
10
 * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * mce is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * mce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with mce.  If not, see <http://www.gnu.org/licenses/>.
 */
24 25
#ifndef  MCE_DBUS_H_
# define MCE_DBUS_H_
26

27
# include "builtin-gconf.h"
28

29
# include <unistd.h>
30

31
# include <dbus/dbus.h>
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
/* ========================================================================= *
 * NON-PUBLIC mce dbus method calls
 * ========================================================================= */

# ifdef ENABLE_BATTERY_SIMULATION
/** Override current charger state
 *
 * Available in devel flavor mce only, and only to privileged applications.
 *
 * @since mce 1.99.0
 *
 * @param string: current charger state, one of:
 * - #MCE_CHARGER_STATE_UNKNOWN
 * - #MCE_CHARGER_STATE_ON
 * - #MCE_CHARGER_STATE_OFF
 *
 * @return boolean true if accepted, false / error reply otherwise
 */
#  define MCE_CHARGER_STATE_REQ                   "req_charger_state"

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/** Override current charger type
 *
 * Available in devel flavor mce only, and only to privileged applications.
 *
 * @since mce 1.102.0
 *
 * @param string: current charger type, one of:
 * - #MCE_CHARGER_TYPE_NONE
 * - #MCE_CHARGER_TYPE_USB
 * - #MCE_CHARGER_TYPE_DCP
 * - #MCE_CHARGER_TYPE_HVDCP
 * - #MCE_CHARGER_TYPE_CDP
 * - #MCE_CHARGER_TYPE_WIRELESS
 * - #MCE_CHARGER_TYPE_OTHER
 *
 * @return boolean true if accepted, false / error reply otherwise
 */
#  define MCE_CHARGER_TYPE_REQ                   "req_charger_type"

72 73 74 75 76 77 78 79 80 81 82 83 84
/** Override current battery level
 *
 * Available in devel flavor mce only, and only to privileged applications.
 *
 * @since mce 1.99.0
 *
 * @param int32: battery level percent, or #MCE_BATTERY_LEVEL_UNKNOWN
 *
 * @return boolean true if accepted, false / error reply otherwise
 */
#  define MCE_BATTERY_LEVEL_REQ                   "req_battery_level"
# endif // ENABLE_BATTERY_SIMULATION

85 86 87 88
/* ========================================================================= *
 * DSME DBUS SERVICE
 * ========================================================================= */

89 90
/** Well known dbus name of dsme service */
# define DSME_DBUS_SERVICE                        "com.nokia.dsme"
91

92 93 94 95
/* ========================================================================= *
 * COMPOSITOR DBUS SERVICE
 * ========================================================================= */

96 97 98 99
/** Well known dbus name of compositor service */
# define COMPOSITOR_SERVICE                       "org.nemomobile.compositor"
# define COMPOSITOR_PATH                          "/"
# define COMPOSITOR_IFACE                         "org.nemomobile.compositor"
100 101

/* Enabling/disabling display updates via compositor service */
102
# define COMPOSITOR_SET_UPDATES_ENABLED           "setUpdatesEnabled"
103

104
/** Query owner of topmost ui window */
105
# define COMPOSITOR_GET_TOPMOST_WINDOW_PID        "privateTopmostWindowProcessId"
106 107

/** Change notification for owner of topmost ui window */
108
# define COMPOSITOR_TOPMOST_WINDOW_PID_CHANGED    "privateTopmostWindowProcessIdChanged"
109

110 111 112 113
/* ========================================================================= *
 * LIPSTICK DBUS SERVICE
 * ========================================================================= */

114 115 116 117
/** Well known dbus name of systemui service */
# define LIPSTICK_SERVICE                         "org.nemomobile.lipstick"
# define LIPSTICK_PATH                            "/"
# define LIPSTICK_IFACE                           "org.nemomobile.lipstick"
118

119 120 121 122
/* ========================================================================= *
 * USB_MODED DBUS SERVICE
 * ========================================================================= */

123 124
/** Well known service name for usb_moded service */
# define USB_MODED_DBUS_SERVICE                   "com.meego.usb_moded"
125 126

/** D-Bus interface name for usb_moded */
127
# define USB_MODED_DBUS_INTERFACE                 "com.meego.usb_moded"
128 129

/** D-Bus object name for usb_moded */
130
# define USB_MODED_DBUS_OBJECT                    "/com/meego/usb_moded"
131 132

/** Query current usb mode method call */
133
# define USB_MODED_QUERY_MODE_REQ                 "mode_request"
134 135

/** Current usb mode changed signal */
136
# define USB_MODED_MODE_CHANGED_SIG               "sig_usb_state_ind"
137

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
/* ========================================================================= *
 * FINGERPRINT_DAEMON_DBUS_SERVICE (API Version 1)
 * ========================================================================= */

# define FINGERPRINT1_DBUS_SERVICE               "org.sailfishos.fingerprint1"

# define FINGERPRINT1_DBUS_ROOT_OBJECT           "/org/sailfishos/fingerprint1"

# define FINGERPRINT1_DBUS_INTERFACE             "org.sailfishos.fingerprint1"

# define FINGERPRINT1_DBUS_REQ_ENROLL            "Enroll"
# define FINGERPRINT1_DBUS_REQ_IDENTIFY          "Identify"
# define FINGERPRINT1_DBUS_REQ_ABORT             "Abort"
# define FINGERPRINT1_DBUS_REQ_GET_ALL           "GetAll"
# define FINGERPRINT1_DBUS_REQ_REMOVE            "Remove"
# define FINGERPRINT1_DBUS_REQ_VERIFY            "Verify"
# define FINGERPRINT1_DBUS_REQ_GET_STATE         "GetState"

# define FINGERPRINT1_DBUS_SIG_ADDED             "Added"
# define FINGERPRINT1_DBUS_SIG_REMOVED           "Removed"
# define FINGERPRINT1_DBUS_SIG_IDENTIFIED        "Identified"
# define FINGERPRINT1_DBUS_SIG_ABORTED           "Aborted"
# define FINGERPRINT1_DBUS_SIG_FAILED            "Failed"
# define FINGERPRINT1_DBUS_SIG_VERIFIED          "Verified"

# define FINGERPRINT1_DBUS_SIG_STATE_CHANGED     "StateChanged"
# define FINGERPRINT1_DBUS_SIG_ERROR_INFO        "ErrorInfo"
# define FINGERPRINT1_DBUS_SIG_ACQUISITION_INFO  "AcquisitionInfo"
# define FINGERPRINT1_DBUS_SIG_ENROLL_PROGRESS   "EnrollProgressChanged"

168 169 170 171
/* ========================================================================= *
 * D-Bus connection and message handling
 * ========================================================================= */

172 173 174
/** Placeholder for any basic dbus data type */
typedef union
{
175 176 177
    dbus_int16_t   i16;
    dbus_int32_t   i32;
    dbus_int64_t   i64;
178

179 180 181
    dbus_uint16_t  u16;
    dbus_uint32_t  u32;
    dbus_uint64_t  u64;
182

183 184 185 186
    dbus_bool_t    b;
    unsigned char  o;
    const char    *s;
    double         d;
187 188 189

} dbus_any_t;

spiiroin's avatar
spiiroin committed
190 191 192 193 194 195
/** D-Bus message handler data
 *
 * For use with mce_dbus_handler_register() etc
 */
typedef struct
{
196 197 198 199 200 201 202 203 204 205
    const char *sender;
    const char *interface;
    const char *name;
    const char *rules;
    const char *args;
    int         type;
    gboolean  (*callback)(DBusMessage *const msg);
    bool        privileged;

    gconstpointer cookie;
spiiroin's avatar
spiiroin committed
206 207
} mce_dbus_handler_t;

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
DBusConnection *dbus_connection_get(void);

DBusMessage *dbus_new_signal(const gchar *const path,
                             const gchar *const interface,
                             const gchar *const name);

DBusMessage *dbus_new_method_call(const gchar *const service,
                                  const gchar *const path,
                                  const gchar *const interface,
                                  const gchar *const name);

DBusMessage *dbus_new_method_reply(DBusMessage *const message);

gboolean dbus_send_message(DBusMessage *const msg);

gboolean dbus_send(const gchar *const service, const gchar *const path,
                   const gchar *const interface, const gchar *const name,
                   DBusPendingCallNotifyFunction callback,
                   int first_arg_type, ...);

gboolean dbus_send_ex(const char *service,
                      const char *path,
                      const char *interface,
                      const char *name,
                      DBusPendingCallNotifyFunction callback,
                      void *user_data, DBusFreeFunction user_free,
                      DBusPendingCall **ppc,
                      int first_arg_type, ...);

gboolean dbus_send_ex2(const char *service,
                       const char *path,
                       const char *interface,
                       const char *name,
                       DBusPendingCallNotifyFunction callback,
                       int timeout,
                       void *user_data, DBusFreeFunction user_free,
                       DBusPendingCall **ppc,
                       int first_arg_type, ...);

void mce_dbus_send_config_notification(GConfEntry *entry);

spiiroin's avatar
spiiroin committed
249
const char *mce_dbus_type_repr(int type);
250 251 252
char *mce_dbus_message_repr(DBusMessage *const msg);
char *mce_dbus_message_iter_repr(DBusMessageIter *iter);

spiiroin's avatar
spiiroin committed
253
bool mce_dbus_iter_at_end(DBusMessageIter *iter);
254 255
bool mce_dbus_iter_req_type(DBusMessageIter *iter, int want);
bool mce_dbus_iter_get_basic(DBusMessageIter *iter, void *pval, int type);
spiiroin's avatar
spiiroin committed
256 257 258
bool mce_dbus_iter_get_object(DBusMessageIter *iter, const char **pval);
bool mce_dbus_iter_get_string(DBusMessageIter *iter, const char **pval);
bool mce_dbus_iter_get_bool(DBusMessageIter *iter, bool *pval);
259 260
bool mce_dbus_iter_get_int32(DBusMessageIter *iter, dbus_int32_t *pval);
bool mce_dbus_iter_get_uint32(DBusMessageIter *iter, dbus_uint32_t *val);
spiiroin's avatar
spiiroin committed
261 262 263 264
bool mce_dbus_iter_get_array(DBusMessageIter *iter, DBusMessageIter *sub);
bool mce_dbus_iter_get_struct(DBusMessageIter *iter, DBusMessageIter *sub);
bool mce_dbus_iter_get_entry(DBusMessageIter *iter, DBusMessageIter *sub);
bool mce_dbus_iter_get_variant(DBusMessageIter *iter, DBusMessageIter *sub);
265

spiiroin's avatar
spiiroin committed
266 267
void mce_dbus_handler_register(mce_dbus_handler_t *self);
void mce_dbus_handler_unregister(mce_dbus_handler_t *self);
268

spiiroin's avatar
spiiroin committed
269 270 271
void mce_dbus_handler_register_array(mce_dbus_handler_t *array);
void mce_dbus_handler_unregister_array(mce_dbus_handler_t *array);

272 273
void mce_dbus_pending_call_blocks_suspend(DBusPendingCall *pc);

274
/* ========================================================================= *
275
 * D-Bus client tracking
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
 * ========================================================================= */

/** D-Bus peer identity/availability tracking state */
typedef enum
{
    /** Freshly created */
    PEERSTATE_INITIAL,

    /** Doing org.freedesktop.DBus.GetNameOwner */
    PEERSTATE_QUERY_OWNER,

    /** org.freedesktop.DBus.GetConnectionUnixProcessID */
    PEERSTATE_QUERY_PID,

    /** Owner known and available on D-Bus */
    PEERSTATE_RUNNING,

293
    /** Owner possibly known, but no longer available on D-Bus
294 295 296 297 298 299 300 301 302
     *
     * The peer info is retained briefly so that it is still
     * available when for example logging client cleanup actions.
     */
    PEERSTATE_STOPPED,
} peerstate_t;

const char *peerstate_repr(peerstate_t state);

303
/** Opaque object type for holding D-Bus peer details */
304 305
typedef struct peerinfo_t peerinfo_t;

306 307 308 309 310 311
const char *peerinfo_name (const peerinfo_t *self);
peerstate_t peerinfo_get_state (const peerinfo_t *self);
pid_t peerinfo_get_owner_pid(const peerinfo_t *self);
uid_t peerinfo_get_owner_uid(const peerinfo_t *self);
gid_t peerinfo_get_owner_gid(const peerinfo_t *self);
const char *peerinfo_get_owner_cmd(const peerinfo_t *self);
312

313
/** Callback function type used by dbus name tracking functionality */
314 315 316
typedef void (*peernotify_fn)(const peerinfo_t *peerinfo, gpointer userdata);

void mce_dbus_name_tracker_add(const char     *name,
317 318 319
                               peernotify_fn   callback,
                               gpointer        userdata,
                               GDestroyNotify  userfree);
320 321

void mce_dbus_name_tracker_remove(const char     *name,
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
                                  peernotify_fn   callback,
                                  gpointer        userdata);

const char *mce_dbus_get_name_owner_ident(const char *name);
const char *mce_dbus_get_message_sender_ident(DBusMessage *msg);
const char *mce_dbus_nameowner_get(const char *name);

gssize mce_dbus_owner_monitor_add(const gchar *service,
                                  gboolean (*callback)(DBusMessage *const msg),
                                  GSList **monitor_list,
                                  gssize max_num);

gssize mce_dbus_owner_monitor_remove(const gchar *service,
                                     GSList **monitor_list);

void mce_dbus_owner_monitor_remove_all(GSList **monitor_list);

/* ========================================================================= *
 * Module init/quit
 * ========================================================================= */

gboolean mce_dbus_init(const gboolean systembus);
void     mce_dbus_exit(void);
345

346
#endif /* MCE_DBUS_H_ */