dist_man_MANS = doc/neard.8 doc/neard.conf.5 doc/nfctool.1
-test_scripts = test/test-adapter \
- test/dump-device test/dump-tag test/dump-record \
+test_scripts = test/test-adapter test/test-device \
+ test/dump-tag test/dump-record \
test/monitor-near test/write-tag \
- test/push-device test/bt-handover test/handover-agent \
+ test/bt-handover test/handover-agent \
test/phdc-simple-manager test/neardutils.py
if TEST
Interface org.neard.Device
Object path [variable prefix]/{nfc0}/{device0, device1...}
-Method dict GetProperties()
-
- Returns all properties for the device. See the
- properties section for available properties.
-
- Possible Errors: org.neard.Error.DoesNotExist
-
- void Push(dict attributes)
+Method void Push(dict attributes)
Creates an NDEF record from the attributes dictionary.
org.neard.Error.InvalidArguments
org.neard.Error.InProgress
-
-Signals PropertyChanged(string name, variant value)
-
- This signal indicates a changed value of the given
- property.
-
-
-Properties array{object} Records [readonly]
-
- List of NDEF records object paths.
return device->target_idx;
}
-static void append_records(DBusMessageIter *iter, void *user_data)
-{
- struct near_device *device = user_data;
- GList *list;
-
- DBG("");
-
- for (list = device->records; list; list = list->next) {
- struct near_ndef_record *record = list->data;
- char *path;
-
- path = __near_ndef_record_get_path(record);
- if (!path)
- continue;
-
- dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
- &path);
- }
-}
-
-static DBusMessage *get_properties(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- struct near_device *device = data;
- DBusMessage *reply;
- DBusMessageIter array, dict;
-
- DBG("conn %p", conn);
-
- reply = dbus_message_new_method_return(msg);
- if (!reply)
- return NULL;
-
- dbus_message_iter_init_append(reply, &array);
-
- near_dbus_dict_open(&array, &dict);
-
- near_dbus_dict_append_array(&dict, "Records",
- DBUS_TYPE_OBJECT_PATH, append_records, device);
-
- near_dbus_dict_close(&array, &dict);
-
- return reply;
-}
-
-static DBusMessage *set_property(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- DBG("conn %p", conn);
-
- return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-}
-
static void push_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
{
struct near_device *device;
}
static const GDBusMethodTable device_methods[] = {
- { GDBUS_METHOD("GetProperties",
- NULL, GDBUS_ARGS({"properties", "a{sv}"}),
- get_properties) },
- { GDBUS_METHOD("SetProperty",
- GDBUS_ARGS({"name", "s"}, {"value", "v"}),
- NULL, set_property) },
{ GDBUS_ASYNC_METHOD("Push", GDBUS_ARGS({"attributes", "a{sv}"}),
NULL, push_ndef) },
{ },
};
-static const GDBusSignalTable device_signals[] = {
- { GDBUS_SIGNAL("PropertyChanged",
- GDBUS_ARGS({"name", "s"}, {"value", "v"})) },
- { }
-};
-
void __near_device_remove(struct near_device *device)
{
char *path = device->path;
__near_agent_ndef_parse_records(device->records);
- near_dbus_property_changed_array(device->path,
- NFC_DEVICE_INTERFACE, "Records",
- DBUS_TYPE_OBJECT_PATH, append_records,
- device);
-
if (cb)
cb(device->adapter_idx, device->target_idx, status);
g_dbus_register_interface(connection, device->path,
NFC_DEVICE_INTERFACE,
- device_methods, device_signals,
- NULL, device, NULL);
+ device_methods, NULL, NULL,
+ device, NULL);
return device;
}
+++ /dev/null
-#!/usr/bin/python
-
-import sys
-import dbus
-
-if len(sys.argv) < 2:
- print "Usage: %s /org/neard/nfcX" % (sys.argv[0])
- sys.exit(1)
-
-bus = dbus.SystemBus()
-
-def extract_record(key, list):
- for i in list:
- record = dbus.Interface(bus.get_object("org.neard", i),
- "org.neard.Record")
-
- properties = record.GetProperties()
- print " Record = [ %s ]" % (str(i))
-
- for key in properties.keys():
- val = str(properties[key])
- print " %s = %s" % (key, val)
-
-device = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
- "org.neard.Device")
-
-properties = device.GetProperties()
-
-print "[ %s ]" % (sys.argv[1])
-
-for key in properties.keys():
- if key in ["Records"]:
- extract_record(key, properties[key])
-
SERVICE_NAME = "org.neard"
ADAPTER_INTERFACE = SERVICE_NAME + ".Adapter"
+DEVICE_INTERFACE = SERVICE_NAME + ".Device"
+RECORD_INTERFACE = SERVICE_NAME + ".Record"
def get_managed_objects():
bus = dbus.SystemBus()
obj = bus.get_object(SERVICE_NAME, path)
return dbus.Interface(obj, ADAPTER_INTERFACE)
raise Exception("NFC adapter not found")
+
+def find_device(pattern=None):
+ return find_device_in_objects(get_managed_objects(), pattern)
+
+def find_device_in_objects(objects, pattern=None):
+ bus = dbus.SystemBus()
+ for path, ifaces in objects.iteritems():
+ device = ifaces.get(DEVICE_INTERFACE)
+ if device is None:
+ continue
+ if not pattern or path.endswith(pattern):
+ obj = bus.get_object(SERVICE_NAME, path)
+ return dbus.Interface(obj, DEVICE_INTERFACE)
+ raise Exception("NFC adapter not found")
+
+def find_record(pattern=None):
+ return find_record_in_objects(get_managed_objects(), pattern)
+
+def find_record_in_objects(objects, pattern=None):
+ bus = dbus.SystemBus()
+ for path, ifaces in objects.iteritems():
+ record = ifaces.get(RECORD_INTERFACE)
+ if record is None:
+ continue
+ if not pattern or path.endswith(pattern):
+ obj = bus.get_object(SERVICE_NAME, path)
+ return dbus.Interface(obj, RECORD_INTERFACE)
+ raise Exception("NFC adapter not found")
+++ /dev/null
-#!/usr/bin/python
-
-import sys
-import dbus
-
-def help_text():
- print "Usage: %s <device-path> <record-type> <...>" % (sys.argv[0])
- print " If type is Text, parameters are <encoding> <language> <representation>"
- print " If type is URI, parameters are <uri>"
- print " If type is SmartPoster, parameters are <uri>"
- print " If type is Handover, parameters are <carrier>"
- print " If type is StaticHandover, parameters are <carrier>"
- print " If type is MIME, parameters are <mime_type> (only wifi_wsc and raw)"
- print " raw is for sending raw payload, parameters are <mime_type> <payload>"
- print "e.g. < %s /org/neard/nfc0/device0 Text UTF-8 en-US hello,Type2! >" % (sys.argv[0])
- print "e.g. < %s /org/neard/nfc0/device0 URI http://www.nfc-forum.com >" % (sys.argv[0])
- print "e.g. < %s /org/neard/nfc0/device0 SmartPoster http://www.nfc-forum.com >" % (sys.argv[0])
- print "e.g. < %s /org/neard/nfc0/device0 Handover bluetooth,wifi >" % (sys.argv[0])
- print "e.g. < %s /org/neard/nfc0/device0 StaticHandover bluetooth,wifi >" % (sys.argv[0])
- print "e.g. < %s /org/neard/nfc0/device0 MIME wifi_wsc>" % (sys.argv[0])
- print "e.g. < %s /org/neard/nfc0/device0 MIME raw application/xml '<your><xml tags></your>' >" % (sys.argv[0])
- sys.exit(1)
-
-if len(sys.argv) < 2:
- help_text()
-
-bus = dbus.SystemBus()
-
-device = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
- "org.neard.Device")
-
-if len(sys.argv) == 6:
- if sys.argv[2] in ["Text"]:
- device.Push(({ "Type" : "Text",
- "Encoding" : sys.argv[3],
- "Language" : sys.argv[4],
- "Representation" : sys.argv[5] }))
- elif sys.argv[2] in ["MIME"]:
- if sys.argv[3] in ["raw"]:
- device.Push(({ "Type" : "MIME",
- "MIME" : sys.argv[4],
- "Payload" : dbus.ByteArray(sys.argv[5]) }))
- else:
- help_text()
- else:
- help_text()
-
-elif len(sys.argv) == 4:
- if sys.argv[2] in ["URI"]:
- device.Push(({ "Type" : "URI",
- "URI" : sys.argv[3] }))
- elif sys.argv[2] in ["SmartPoster"]:
- device.Push(({ "Type" : "SmartPoster",
- "URI" : sys.argv[3] }))
- elif sys.argv[2] in ["Handover"]:
- device.Push(({ "Type" : "Handover",
- "Carrier" : sys.argv[3] }))
- elif sys.argv[2] in ["StaticHandover"]:
- device.Push(({ "Type" : "StaticHandover",
- "Carrier" : sys.argv[3] }))
- elif sys.argv[2] in ["MIME"]:
- if sys.argv[3] in ["wifi_wsc"]:
- device.Push(({ "Type" : "MIME",
- "MIME" : "application/vnd.wfa.wsc"}))
- else:
- help_text()
- else:
- help_text()
-else:
- help_text()