1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2025-04-21 12:27:27 +03:00

tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure

- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
  new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
  driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
  to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
  cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
  "driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
  SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
  driver spec. One -s retrieves the local spec, -s -s the remote/final.
This commit is contained in:
Werner Almesberger
2011-04-20 08:58:17 -03:00
parent 4fa909debc
commit 2961482cac
7 changed files with 84 additions and 3 deletions

View File

@@ -24,6 +24,7 @@
struct atrf_dsc {
const struct atrf_driver *driver;
void *handle;
char *spec;
enum atrf_chip_id chip_id;
};
@@ -164,6 +165,15 @@ struct atrf_dsc *atrf_open(const char *spec)
}
dsc->driver = driver;
dsc->handle = handle;
if (spec) {
dsc->spec = strdup(spec);
if (!dsc->spec) {
perror("strdup");
exit(1);
}
} else {
dsc->spec= NULL;
}
dsc->chip_id = identify(dsc);
return dsc;
}
@@ -173,10 +183,21 @@ void atrf_close(struct atrf_dsc *dsc)
{
if (dsc->driver->close)
dsc->driver->close(dsc->handle);
free(dsc->spec);
free(dsc);
}
const char *atrf_driver_spec(struct atrf_dsc *dsc, int last)
{
if (!dsc->spec)
return dsc->driver->name;
if (!last || !dsc->driver->driver_spec)
return dsc->spec;
return dsc->driver->driver_spec(dsc->handle);
}
void atrf_reset(struct atrf_dsc *dsc)
{
if (dsc->driver->reset)