void initialize_string() { g_string_macro = new name("string_macro"); g_string_opcode = new std::string("Str"); g_nat = new expr(Const(get_nat_name())); g_char = new expr(Const(get_char_name())); g_char_of_nat = new expr(Const(get_char_of_nat_name())); g_string = new expr(Const(get_string_name())); g_empty = new expr(Const(get_string_empty_name())); g_str = new expr(Const(get_string_str_name())); g_fin_mk = new expr(Const(get_fin_mk_name())); g_list_char = new expr(mk_app(mk_constant(get_list_name(), {mk_level_one()}), *g_char)); g_list_cons = new expr(mk_constant(get_list_cons_name(), {mk_level_one()})); g_list_nil_char = new expr(mk_app(mk_constant(get_list_nil_name(), {mk_level_one()}), *g_char)); register_macro_deserializer(*g_string_opcode, [](deserializer & d, unsigned num, expr const *) { if (num != 0) throw corrupted_stream_exception(); std::string v = d.read_string(); return mk_string_macro(v); }); }
static void append_char_dict(DBusMessageIter *iter, struct characteristic *chr) { DBusMessageIter dict; const char *name = ""; char *uuid; gboolean broadcast; gboolean indicate; gboolean notify; gboolean readable; char **write_methods; uint8_t write_methods_count = 0; 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); uuid = g_strdup(chr->type); dict_append_entry(&dict, "UUID", DBUS_TYPE_STRING, &uuid); g_free(uuid); name = get_char_name(chr->type); /* FIXME: Translate UUID to name. */ if (name != NULL) dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &name); if (chr->desc) dict_append_entry(&dict, "Description", DBUS_TYPE_STRING, &chr->desc); /* Broadcast */ broadcast = ((chr->perm & GATT_CHAR_PROPS_BROADCAST) != 0) && ((chr->server_config & GATT_CHAR_SERVERCONF_BROADCAST) != 0); dict_append_entry(&dict, "Broadcast", DBUS_TYPE_BOOLEAN, &broadcast); /* Indicate */ indicate = ((chr->perm & GATT_CHAR_PROPS_INDICATE) != 0) && ((chr->client_config & GATT_CHAR_CLIENTCONF_INDICATE) != 0); dict_append_entry(&dict, "Indicate", DBUS_TYPE_BOOLEAN, &indicate); /* Notify */ notify = ((chr->perm & GATT_CHAR_PROPS_NOTIFY) != 0) && ((chr->client_config & GATT_CHAR_CLIENTCONF_NOTIFY) != 0); dict_append_entry(&dict, "Notify", DBUS_TYPE_BOOLEAN, ¬ify); /* Readable */ readable = ((chr->perm & GATT_CHAR_PROPS_READ) != 0) ; dict_append_entry(&dict, "Readable", DBUS_TYPE_BOOLEAN, &readable); write_methods = g_new0(char *, 5); /* WritableNoRsp */ if ((chr->perm & GATT_CHAR_PROPS_WRITE_NO_RSP) != 0) write_methods[write_methods_count++] = "WriteWithoutResponse"; /* WritableRsp */ if ((chr->perm & GATT_CHAR_PROPS_WRITE) != 0) write_methods[write_methods_count++] = "Write"; /* WritableAuth */ if ((chr->perm & GATT_CHAR_PROPS_WRITE_AUTHSIGN) != 0) write_methods[write_methods_count++] = "AuthenticatedSignedWrite"; if ((chr->ext_properties & GATT_CHAR_EXT_PROPS_WRITE_RELIABLE) != 0) write_methods[write_methods_count++] = "ReliableWrite"; /* TODO : add "WritableAuxiliaries" */ /* TODO : add CustomCharacteristicsDesc */ dict_append_array(&dict, "WriteMethods", DBUS_TYPE_STRING, &write_methods, write_methods_count); if (chr->value) dict_append_array(&dict, "Value", DBUS_TYPE_BYTE, &chr->value, chr->vlen); g_free(write_methods); /* FIXME: Missing Format, Value and Representation */ dbus_message_iter_close_container(iter, &dict); }