/** * Get a context ID for a transcoded device * Implicitly generates a new context if device is new * * @param lladdr Low-level address, format is opaque * @param plugin The related transcoding plug-in for the device * @return Context ID */ ContextId trans_context_get(char *lladdr, TransPlugin *plugin) { TransDevice *dev = get_device_by_addr(lladdr); if (dev) { return dev->context; } else if (! trans_comm_plugin) { ERROR("Transcoding comm plugin not loaded"); } else if (plugin) { dev = malloc(sizeof(TransDevice)); ContextId c = {communication_plugin_id(trans_comm_plugin), new_context++}; new_context++; dev->context = c; dev->lladdr = strdup(lladdr); dev->plugin = plugin; gil_lock(); llist_add(devices(), dev); gil_unlock(); return dev->context; } else { ERROR("Trans context w/ unknown plugin"); } ContextId c = {0, 0}; return c; }
/** * Find device by context id * * @param id Context id * @return TransDevice struct or NULL if not found */ static TransDevice *get_device_by_context(ContextId id) { gil_lock(); TransDevice *dev = llist_search_first(devices(), &id, search_by_context); gil_unlock(); return dev; }
/** * Returns a transcoded device struct, search by low-level addr * @param lladdr low-level address as string * @return transcoded device or NULL if not found */ static TransDevice *get_device_by_addr(char *lladdr) { gil_lock(); TransDevice *dev = llist_search_first(devices(), lladdr, search_by_addr); gil_unlock(); return dev; }
struct variable *sys_file_listen(struct context *context) { struct variable *arguments = (struct variable*)stack_pop(context->operand_stack); const char *path = param_str(arguments, 1); struct variable *listener = param_var(arguments, 2); gil_unlock(context, "sys_file_listen"); hal_file_listen(context, path, listener); return NULL; }