1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
/*
* cui library
*
* Copyright (C) 2011-2012 Intel Corporation. All rights reserved.
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __CUI_DBUS_H__
#define __CUI_DBUS_H__
#include <dbus/dbus.h>
#include <stdbool.h>
#ifndef DBUS_TIMEOUT_USE_DEFAULT
#define DBUS_TIMEOUT_USE_DEFAULT (-1)
#endif
/*
* Used for cui_dbus_append_dict_entry_dict,
* and cui_dbus_get_dict_entry.
* It should not be used anywhere else.
*/
enum cui_dbus_entry {
CUI_DBUS_ENTRY_BASIC = 0,
CUI_DBUS_ENTRY_ARRAY = 1,
CUI_DBUS_ENTRY_FIXED_ARRAY = 2,
CUI_DBUS_ENTRY_DICT = 3,
};
typedef void (*cui_dbus_property_f) (DBusMessageIter *iter,
void *user_data);
typedef bool (*cui_dbus_foreach_callback_f) (DBusMessageIter *iter,
void *user_data);
static inline
bool cui_dbus_open_dict(DBusMessageIter *iter, DBusMessageIter *dict) {
return dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
}
void cui_dbus_append_dict(DBusMessageIter *iter,
const char *key_name,
cui_dbus_property_f property_function,
void *user_data);
void cui_dbus_append_basic(DBusMessageIter *iter,
const char *key_name,
int dbus_type,
void *value);
void cui_dbus_append_array(DBusMessageIter *iter,
const char *key_name,
int dbus_type,
cui_dbus_property_f property_function,
void *user_data);
void cui_dbus_append_fixed_array(DBusMessageIter *iter,
const char *key_name,
int dbus_type,
int length,
void *value);
/* Use preferably the inline functions below this one */
void cui_dbus_append_dict_entry(DBusMessageIter *dict,
const char *key_name,
enum cui_dbus_entry entry_type,
int dbus_type,
int length,
cui_dbus_property_f property_function,
void *user_data);
static inline
void cui_dbus_append_dict_entry_basic(DBusMessageIter *dict,
const char *key_name,
int dbus_type,
void *value)
{
cui_dbus_append_dict_entry(dict, key_name,
CUI_DBUS_ENTRY_BASIC, dbus_type, 0, NULL, value);
}
static inline
void cui_dbus_append_dict_entry_array(DBusMessageIter *dict,
const char *key_name,
int dbus_type,
cui_dbus_property_f property_function,
void *user_data)
{
cui_dbus_append_dict_entry(dict, key_name,
CUI_DBUS_ENTRY_ARRAY, dbus_type, 0,
property_function, user_data);
}
static inline
void cui_dbus_append_dict_entry_fixed_array(DBusMessageIter *dict,
const char *key_name,
int dbus_type,
int length,
void *value)
{
cui_dbus_append_dict_entry(dict, key_name,
CUI_DBUS_ENTRY_FIXED_ARRAY, dbus_type,
length, NULL, value);
}
static inline
void cui_dbus_append_dict_entry_dict(DBusMessageIter *dict,
const char *key_name,
cui_dbus_property_f property_function,
void *user_data)
{
cui_dbus_append_dict_entry(dict, key_name,
CUI_DBUS_ENTRY_DICT, 0, 0,
property_function, user_data);
}
int cui_dbus_get_basic(DBusMessageIter *iter,
int dbus_type,
void *destination);
int cui_dbus_get_basic_variant(DBusMessageIter *iter,
int dbus_type,
void *destination);
int cui_dbus_get_array(DBusMessageIter *iter,
int dbus_type,
int *length,
void *destination);
int cui_dbus_get_fixed_array(DBusMessageIter *iter,
int *length,
void *destination);
int cui_dbus_foreach_dict_entry(DBusMessageIter *iter,
cui_dbus_foreach_callback_f callback,
void *user_data);
/* Use preferably the inline functions below this one */
int cui_dbus_get_dict_entry(DBusMessageIter *iter,
const char *key_name,
enum cui_dbus_entry entry_type,
int dbus_type,
int *length,
void *destination);
static inline
int cui_dbus_get_dict_entry_basic(DBusMessageIter *iter,
const char *key_name,
int dbus_type,
void *destination)
{
return cui_dbus_get_dict_entry(iter, key_name,
CUI_DBUS_ENTRY_BASIC,
dbus_type, NULL, destination);
}
static inline
int cui_dbus_get_dict_entry_array(DBusMessageIter *iter,
const char *key_name,
int dbus_type,
int *length,
void *destination)
{
return cui_dbus_get_dict_entry(iter, key_name,
CUI_DBUS_ENTRY_ARRAY,
dbus_type, length, destination);
}
static inline
int cui_dbus_get_dict_entry_fixed_array(DBusMessageIter *iter,
const char *key_name,
int dbus_type,
int *length,
void *destination)
{
return cui_dbus_get_dict_entry(iter, key_name,
CUI_DBUS_ENTRY_FIXED_ARRAY,
dbus_type, length, destination);
}
static inline
int cui_dbus_get_dict_entry_dict(DBusMessageIter *iter,
const char *key_name,
DBusMessageIter *dict)
{
return cui_dbus_get_dict_entry(iter, key_name,
CUI_DBUS_ENTRY_DICT,
DBUS_TYPE_INVALID, NULL, dict);
}
/* Use preferably the inline functions below this one */
int cui_dbus_get_struct_entry(DBusMessageIter *iter,
unsigned int position,
enum cui_dbus_entry entry_type,
int dbus_type,
int *length,
void *destination);
static inline
int cui_dbus_get_struct_entry_basic(DBusMessageIter *iter,
unsigned int position,
int dbus_type,
void *destination)
{
return cui_dbus_get_struct_entry(iter, position,
CUI_DBUS_ENTRY_BASIC,
dbus_type, NULL, destination);
}
static inline
int cui_dbus_get_struct_entry_array(DBusMessageIter *iter,
unsigned int position,
int dbus_type,
int *length,
void *destination)
{
return cui_dbus_get_struct_entry(iter, position,
CUI_DBUS_ENTRY_ARRAY,
dbus_type, length, destination);
}
static inline
int cui_dbus_get_struct_entry_fixed_array(DBusMessageIter *iter,
unsigned int position,
int dbus_type,
int *length,
void *destination)
{
return cui_dbus_get_struct_entry(iter, position,
CUI_DBUS_ENTRY_FIXED_ARRAY,
dbus_type, length, destination);
}
static inline
int cui_dbus_get_struct_entry_dict(DBusMessageIter *iter,
unsigned int position,
DBusMessageIter *dict)
{
return cui_dbus_get_struct_entry(iter, position,
CUI_DBUS_ENTRY_DICT,
DBUS_TYPE_INVALID, NULL, dict);
}
static inline dbus_bool_t cui_dbus_is_service_running(DBusConnection *dbus_cnx,
const char *dbus_service_name)
{
if (dbus_bus_name_has_owner(dbus_cnx,
dbus_service_name, NULL) == FALSE)
return FALSE;
return TRUE;
}
#endif /* __CUI_DBUS_H__ */
|