#include <glib.h>
#include <connman/property.h>
+#include <connman/types.h>
#include <connman/ipv4.h>
/**
extern struct connman_element *connman_element_ref(struct connman_element *element);
extern void connman_element_unref(struct connman_element *element);
-extern int connman_element_set_static_property(struct connman_element *element,
- const char *name, int type, const void *value);
-extern int connman_element_set_static_array_property(struct connman_element *element,
- const char *name, int type, const void *value, int len);
-extern int connman_element_set_property(struct connman_element *element,
- enum connman_property_id id, const void *value);
extern int connman_element_get_value(struct connman_element *element,
enum connman_property_id id, void *value);
-extern gboolean connman_element_get_static_property(struct connman_element *element,
- const char *name, void *value);
-extern gboolean connman_element_get_static_array_property(struct connman_element *element,
- const char *name, void *value, int *len);
-extern gboolean connman_element_match_static_property(struct connman_element *element,
- const char *name, const void *value);
+
+extern int connman_element_set_string(struct connman_element *element,
+ const char *key, const char *value);
+extern const char *connman_element_get_string(struct connman_element *element,
+ const char *key);
+extern int connman_element_set_uint8(struct connman_element *element,
+ const char *key, connman_uint8_t value);
+extern connman_uint8_t connman_element_get_uint8(struct connman_element *element,
+ const char *key);
+extern int connman_element_set_blob(struct connman_element *element,
+ const char *key, const void *data, unsigned int size);
+extern const void *connman_element_get_blob(struct connman_element *element,
+ const char *key, unsigned int *size);
extern int connman_element_register(struct connman_element *element,
struct connman_element *parent);
CONNMAN_PROPERTY_ID_IPV4_NAMESERVER,
};
+enum connman_property_type {
+ CONNMAN_PROPERTY_TYPE_INVALID = 0,
+ CONNMAN_PROPERTY_TYPE_STRING,
+ CONNMAN_PROPERTY_TYPE_UINT8,
+ CONNMAN_PROPERTY_TYPE_BLOB,
+};
+
struct connman_property {
enum connman_property_id id;
int type;
int subtype;
void *value;
- int size;
+ unsigned int size;
};
#ifdef __cplusplus
struct connman_element *element = data;
DBusMessage *reply;
DBusMessageIter array, dict;
- connman_uint8_t strength = 0;
+ connman_uint8_t strength;
const char *device, *network;
- const char *type = NULL;
+ const char *type;
DBG("conn %p", conn);
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
- connman_element_get_static_property(element, "Type", &type);
-
+ type = connman_element_get_string(element, "Type");
if (type != NULL)
connman_dbus_dict_append_variant(&dict, "Type",
DBUS_TYPE_STRING, &type);
- connman_element_get_static_property(element, "Strength", &strength);
+ strength = connman_element_get_uint8(element, "Strength");
if (strength > 0)
connman_dbus_dict_append_variant(&dict, "Strength",
DBUS_TYPE_BYTE, &strength);
str = type2string(type);
if (str != NULL)
- connman_element_set_static_property(&device->element,
- "Type", DBUS_TYPE_STRING, &str);
+ connman_element_set_string(&device->element, "Type", str);
device->element.ipv4.method = CONNMAN_IPV4_METHOD_DHCP;
device->node = g_strdup(value);
}
- return 0;
+ return connman_element_set_string(&device->element, key, value);
}
/**
else if (g_str_equal(key, "Node") == TRUE)
return device->node;
- return NULL;
+ return connman_element_get_string(&device->element, key);
}
static void set_offlinemode(struct connman_element *element, gpointer user_data)
}
}
-int connman_element_set_static_property(struct connman_element *element,
+static int set_static_property(struct connman_element *element,
const char *name, int type, const void *value)
{
struct connman_property *property;
return 0;
}
-int connman_element_set_static_array_property(struct connman_element *element,
+static int set_static_array_property(struct connman_element *element,
const char *name, int type, const void *value, int len)
{
struct connman_property *property;
return 0;
}
-int connman_element_set_property(struct connman_element *element,
+#if 0
+static int set_property(struct connman_element *element,
enum connman_property_id id, const void *value)
{
switch (id) {
return 0;
}
+#endif
int connman_element_get_value(struct connman_element *element,
enum connman_property_id id, void *value)
return 0;
}
-gboolean connman_element_get_static_property(struct connman_element *element,
+static gboolean get_static_property(struct connman_element *element,
const char *name, void *value)
{
struct connman_property *property;
__connman_element_unlock(element);
if (found == FALSE && element->parent != NULL)
- return connman_element_get_static_property(element->parent,
- name, value);
+ return get_static_property(element->parent, name, value);
return found;
}
-gboolean connman_element_get_static_array_property(struct connman_element *element,
- const char *name, void *value, int *len)
+static gboolean get_static_array_property(struct connman_element *element,
+ const char *name, void *value, unsigned int *len)
{
struct connman_property *property;
gboolean found = FALSE;
return found;
}
-gboolean connman_element_match_static_property(struct connman_element *element,
+#if 0
+static gboolean match_static_property(struct connman_element *element,
const char *name, const void *value)
{
struct connman_property *property;
return result;
}
+#endif
+
+/**
+ * connman_element_set_string:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_element_set_string(struct connman_element *element,
+ const char *key, const char *value)
+{
+ return set_static_property(element, key, DBUS_TYPE_STRING, &value);
+}
+
+/**
+ * connman_element_get_string:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_element_get_string(struct connman_element *element,
+ const char *key)
+{
+ const char *value;
+
+ if (get_static_property(element, key, &value) == FALSE)
+ return NULL;
+
+ return value;
+}
+
+/**
+ * connman_element_set_uint8:
+ * @element: element structure
+ * @key: unique identifier
+ * @value: integer value
+ *
+ * Set integer value for specific key
+ */
+int connman_element_set_uint8(struct connman_element *element,
+ const char *key, connman_uint8_t value)
+{
+ return set_static_property(element, key, DBUS_TYPE_BYTE, &value);
+}
+
+/**
+ * connman_element_get_uint8:
+ * @element: element structure
+ * @key: unique identifier
+ *
+ * Get integer value for specific key
+ */
+connman_uint8_t connman_element_get_uint8(struct connman_element *element,
+ const char *key)
+{
+ connman_uint8_t value;
+
+ if (get_static_property(element, key, &value) == FALSE)
+ return 0;
+
+ return value;
+}
+
+/**
+ * connman_element_set_blob:
+ * @element: element structure
+ * @key: unique identifier
+ * @data: blob data
+ * @size: blob size
+ *
+ * Set binary blob value for specific key
+ */
+int connman_element_set_blob(struct connman_element *element,
+ const char *key, const void *data, unsigned int size)
+{
+ return set_static_array_property(element, key,
+ DBUS_TYPE_BYTE, data, size);
+}
+
+/**
+ * connman_element_get_blob:
+ * @element: element structure
+ * @key: unique identifier
+ * @size: pointer to blob size
+ *
+ * Get binary blob value for specific key
+ */
+const void *connman_element_get_blob(struct connman_element *element,
+ const char *key, unsigned int *size)
+{
+ void *value;
+
+ if (get_static_array_property(element, key, &value, size) == FALSE)
+ return NULL;
+
+ return value;
+}
int __connman_element_append_ipv4(struct connman_element *element,
DBusMessageIter *dict)
str = type2string(type);
if (str != NULL)
- connman_element_set_static_property(&network->element,
- "Type", DBUS_TYPE_STRING, &str);
+ connman_element_set_string(&network->element, "Type", str);
- connman_element_set_static_property(&network->element,
- "Strength", DBUS_TYPE_BYTE, &strength);
+ connman_element_set_uint8(&network->element, "Strength", strength);
network->type = type;
network->identifier = g_strdup(identifier);
network->wifi.passphrase = g_strdup(value);
}
- return 0;
+ return connman_element_set_string(&network->element, key, value);
}
/**
else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
return network->wifi.passphrase;
- return NULL;
+ return connman_element_get_string(&network->element, key);
}
/**
if (g_str_equal(key, "Priority") == TRUE)
network->priority = value;
- else if (g_str_equal(key, "Strength") == TRUE) {
+ else if (g_str_equal(key, "Strength") == TRUE)
network->strength = value;
- connman_element_set_static_property(&network->element,
- "Strength", DBUS_TYPE_BYTE, &value);
- }
- return 0;
+ return connman_element_set_uint8(&network->element, key, value);
}
/**
else if (g_str_equal(key, "Strength") == TRUE)
return network->strength;
- return 0;
+ return connman_element_get_uint8(&network->element, key);
}
/**
network->wifi.ssid_len = 0;
}
- return 0;
+ return connman_element_set_blob(&network->element, key, data, size);
}
/**
return network->wifi.ssid;
}
- return NULL;
+ return connman_element_get_blob(&network->element, key, size);
}
void __connman_network_set_device(struct connman_network *network,