Driver* Manager::load_driver(const std::string& name) { Driver* driver = get_driver(name); if (driver) { return driver; } else { std::cout << "Manager: Loading driver '" << name << "'" << std::endl; driver = DriverFactory::create(name, this); if (!driver) { std::cout << "Manager: Unknown driver: " << name << std::endl; return 0; } else { drivers.push_back(driver); return driver; } } }
int mapi_stats(const char *dev, struct mapi_stat *stats) { if (dev == NULL) { printf("ERROR: Invalid device name given (NULL) in mapi_stats\n"); local_err = MAPI_DEVICE_INFO_ERR; return -1; } if (stats == NULL) { printf("ERROR: stats must have memory allocated first.\n"); local_err = MFUNCT_INVALID_ARGUMENT_2; return -1; } pthread_once(&initialized, (void*)init); if (!minit) { printf("MAPI not initialized! [%s:%d]\n", __FILE__, __LINE__); local_err = MAPI_INIT_ERROR; return -1; } void *driver = get_driver(dev); flowdrv_stats = drv_get_funct(driver, "flowdrv_stats"); return (*flowdrv_stats)(dev, stats); }
/* * test_get_drv * make test call to get_driver which should * return a pointer to the driver passed in * and increase the reference count to that * kobject */ static int test_get_drv() { int a, rc; struct device_driver *drv = &test_driver, *tmp = NULL; /* get reference count before test call */ a = atomic_read(&drv->kobj.refcount); /* make test call */ if ((tmp = get_driver(drv))) { rc = 0; printk("tbase: get driver returned driver\n"); } else { rc = 1; printk("tbase: get driver failed to return driver\n"); } /* check reference count */ if ((a == (atomic_read(&drv->kobj.refcount) - 1) )) { rc = 0; printk("tbase: correctly set ref count get driver\n"); } else { rc = 1; printk("tbase: incorrect ref count get driver\n"); } return rc; }
void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) { if (get_driver(drv)) { sysfs_remove_file(&drv->kobj, &attr->attr); put_driver(drv); } }
Driver* Manager::load_driver(const std::string& name) { Driver* driver_p = get_driver(name); if (driver_p) { return driver_p; } else { log_info("loading driver '%1%'", name); auto driver = DriverFactory::create(name, this); if (!driver) { log_error("unknown driver: %1%", name); return 0; } else { drivers.push_back(std::move(driver)); return drivers.back().get(); } } }
int mapi_create_flow(const char *dev) //Create new flow //dev=device that should be used { if(dev == NULL) { printf("ERROR: Wrong device name given (NULL) in mapi_create_flow\n"); local_err = MAPI_DEVICE_INFO_ERR; return -1; } // pthread_once(&initialized, (void*)init); init(); if (!minit) { printf("MAPI not initialized! [%s:%d]\n", __FILE__, __LINE__); local_err = MAPI_INIT_ERROR; return -1; } // XXX: Create flowlist_item here and insert when driver func completes successfully?? void *driver = get_driver(dev); flowdrv_create_flow = drv_get_funct(driver, "flowdrv_create_flow"); return (*flowdrv_create_flow)(dev); }
static void klist_drivers_get(struct klist_node *n) { struct device_driver *drv = container_of(n, struct device_driver, knode_bus); get_driver(drv); }
static void release_agents(void) { GHashTableIter iter; gpointer key, value; g_hash_table_iter_init(&iter, agent_hash); while (g_hash_table_iter_next(&iter, &key, &value)) agent_release(value, get_driver()->interface); }
int driver_create_file(struct device_driver * drv, struct driver_attribute * attr) { int error; if (get_driver(drv)) { error = sysfs_create_file(&drv->kobj, &attr->attr); put_driver(drv); } else error = -EINVAL; return error; }
static const apr_crypto_driver_t *get_nss_driver(abts_case *tc, apr_pool_t *pool) { apr_array_header_t *params; apr_crypto_param_t *param; /* initialise NSS */ params = apr_array_make(pool, 10, sizeof(apr_crypto_param_t)); param = apr_array_push(params); param->type = APR_CRYPTO_CA_TYPE_DIR; param->path = "data"; return get_driver(tc, pool, "nss", params); }
int main(void) { printf ("libnet chat client version %d.%d\n", VER_MAJOR, VER_MINOR); printf ("built at " __TIME__ " on " __DATE__ "\n"); printf ("\n"); net_init(); net_loadconfig (NULL); get_driver(); init(); do_client(); return 0; }
void ccwgroup_driver_unregister (struct ccwgroup_driver *cdriver) { struct device *dev; /* We don't want ccwgroup devices to live longer than their driver. */ get_driver(&cdriver->driver); while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, __ccwgroup_match_all))) { __ccwgroup_remove_symlinks(to_ccwgroupdev(dev)); device_unregister(dev); put_device(dev); } put_driver(&cdriver->driver); driver_unregister(&cdriver->driver); }
t_display *new_display(t_display_init_param params) { t_display *ret; ret = ft_memalloc(sizeof(*ret)); ret->param = params; ret->renderer_driver = get_driver(params.type, params.display_type); if (!ret->renderer_driver) { free(ret); ft_putendl("Specified backend cannot use the specified display mode"); return (0); } ret->user_ptr = params.user_ptr; ret->renderer_driver->param = params; init_display(ret, params.display_type); return (ret); }
/* phy_probe * * description: Take care of setting up the phy_device structure, * set the state to READY (the driver's init function should * set it to STARTING if needed). */ static int phy_probe(struct device *dev) { struct phy_device *phydev; struct phy_driver *phydrv; struct device_driver *drv; int err = 0; phydev = to_phy_device(dev); /* Make sure the driver is held. * XXX -- Is this correct? */ drv = get_driver(phydev->dev.driver); phydrv = to_phy_driver(drv); phydev->drv = phydrv; /* Disable the interrupt if the PHY doesn't support it */ if (!(phydrv->flags & PHY_HAS_INTERRUPT)) phydev->irq = PHY_POLL; spin_lock(&phydev->lock); /* Start out supporting everything. Eventually, * a controller will attach, and may modify one * or both of these values */ phydev->supported = phydrv->features; phydev->advertising = phydrv->features; /* Set the state to READY by default */ phydev->state = PHY_READY; if (phydev->drv->probe) err = phydev->drv->probe(phydev); spin_unlock(&phydev->lock); if (err < 0) return err; if (phydev->drv->config_init) err = phydev->drv->config_init(phydev); return err; }
/** * ccwgroup_driver_unregister() - deregister a ccw group driver * @cdriver: driver to be deregistered * * This function is mainly a wrapper around driver_unregister(). */ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver) { struct device *dev; /* We don't want ccwgroup devices to live longer than their driver. */ get_driver(&cdriver->driver); while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, __ccwgroup_match_all))) { struct ccwgroup_device *gdev = to_ccwgroupdev(dev); mutex_lock(&gdev->reg_mutex); __ccwgroup_remove_symlinks(gdev); device_unregister(dev); __ccwgroup_remove_cdev_refs(gdev); mutex_unlock(&gdev->reg_mutex); put_device(dev); } put_driver(&cdriver->driver); driver_unregister(&cdriver->driver); }
void DVSerialEngine::register_comport(std::list<std::string>& comList, std::list<std::string>& comList8250, const std::string& dir) { // Get the driver the device is using std::string driver = get_driver(dir); // Skip devices without a driver if (driver.size() > 0) { //std::cerr << "register_comport: dir: "<< dir << " driver: " << driver << std::endl; std::string devfile = std::string("/dev/") + basename((char *) dir.c_str()); // Put serial8250-devices in a seperate list if (driver == "serial8250") { comList8250.push_back(devfile); } else comList.push_back(devfile); } }
int connman_agent_queue_message(void *user_context, DBusMessage *msg, int timeout, agent_queue_cb callback, void *user_data, void *agent_data) { struct connman_agent_request *queue_data; struct connman_agent_driver *driver; struct connman_agent *agent = agent_data; int err; if (!user_context || !callback) return -EBADMSG; queue_data = g_new0(struct connman_agent_request, 1); if (!queue_data) return -ENOMEM; driver = get_driver(); DBG("driver %p", driver); if (driver && driver->context_ref) { queue_data->user_context = driver->context_ref(user_context); queue_data->driver = driver; } else queue_data->user_context = user_context; queue_data->msg = dbus_message_ref(msg); queue_data->timeout = timeout; queue_data->callback = callback; queue_data->user_data = user_data; agent->queue = g_list_append(agent->queue, queue_data); err = agent_send_next_request(agent); if (err < 0 && err != -EBUSY) DBG("send next request failed (%s/%d)", strerror(-err), -err); return err; }
/* * __device_release_driver() must be called with @dev->sem held. * When called for a USB interface, @dev->parent->sem must be held as well. */ static void __device_release_driver(struct device * dev) { struct device_driver * drv; drv = get_driver(dev->driver); if (drv) { driver_sysfs_remove(dev); sysfs_remove_link(&dev->kobj, "driver"); klist_remove(&dev->knode_driver); if (dev->bus) blocking_notifier_call_chain(&dev->bus->bus_notifier, BUS_NOTIFY_UNBIND_DRIVER, dev); if (dev->bus && dev->bus->remove) dev->bus->remove(dev); else if (drv->remove) drv->remove(dev); devres_release_all(dev); dev->driver = NULL; put_driver(drv); } }
static void release_all_agents(void) { connman_agent_driver_unregister(get_driver()); }
void update(void* instance) { InstancePtr inst = (InstancePtr) instance; MyInstancePtr my = inst->my; int device = trim_int(inst->in_device->number, 0, 256); const char* driver_name = inst->in_driver->text; try { if (my->driver_name == 0 || my->drv == 0 || strcmp(driver_name, my->driver_name) != 0) { delete[] my->driver_name; my->driver_name = strcopy(driver_name); if (my->drv != 0) release_driver(my->drv, my->driver_name, my->device); my->drv = get_driver(my->driver_name, my->device); } assert(my->drv != 0); if (device != my->device || !my->drv->is_open()) { my->device = device; if (my->drv->is_open()) my->drv->close(); assert(!my->drv->is_open()); try { my->drv->open(device); } catch (std::exception& e) { char buf[128]; snprintf(buf, sizeof(buf), "Error while opening: %s", e.what()); s_log(0, buf); throw; } assert(my->drv->is_open()); } assert(my->drv->is_open()); try { static const int MAX_MSG_LEN = 1024; unsigned char buffer[MAX_MSG_LEN]; int len = my->drv->read(buffer, sizeof(buffer)); midi_set_buffer(inst->out_r, buffer, len); } catch (std::exception& e) { char buf[128]; snprintf(buf, sizeof(buf), "Error while reading: %s", e.what()); s_log(0, buf); throw; } } catch (std::exception& e) { midi_set_buffer(inst->out_r, 0, 0); } }
static const apr_crypto_driver_t *get_openssl_driver(abts_case *tc, apr_pool_t *pool) { return get_driver(tc, pool, "openssl", NULL); }
int parse_options(int argc, char ** argv, int * driver, char ** server, int * port, int * connection_type, char ** user, char ** password, int * auth_type, char ** path, char ** cache_directory, char ** flags_directory) { int indx; #if HAVE_GETOPT_LONG static struct option long_options[] = { {"driver", 1, 0, 'd'}, {"server", 1, 0, 's'}, {"port", 1, 0, 'p'}, {"tls", 0, 0, 't'}, {"starttls", 0, 0, 'x'}, {"user", 1, 0, 'u'}, {"password", 1, 0, 'v'}, {"path", 1, 0, 'l'}, {"apop", 0, 0, 'a'}, {"cache", 1, 0, 'c'}, {"flags", 1, 0, 'f'}, {"debug-stream", 0, 0, 'D'}, }; #endif int r; char location[PATH_MAX]; char * env_user; indx = 0; * driver = MBOX_STORAGE; * server = NULL; * port = 0; * connection_type = CONNECTION_TYPE_PLAIN; * user = NULL; * password = NULL; * auth_type = POP3_AUTH_TYPE_PLAIN; env_user = getenv("USER"); if (env_user != NULL) { snprintf(location, PATH_MAX, "/var/mail/%s", env_user); * path = strdup(location); } else * path = NULL; * cache_directory = NULL; * flags_directory = NULL; while (1) { #if HAVE_GETOPT_LONG r = getopt_long(argc, argv, "d:s:p:txu:v:l:ac:f:D", long_options, &indx); #else r = getopt(argc, argv, "d:s:p:txu:v:l:ac:f:D"); #endif if (r == -1) break; switch (r) { case 'd': * driver = get_driver(optarg); break; case 's': if (* server != NULL) free(* server); * server = strdup(optarg); break; case 'p': * port = strtoul(optarg, NULL, 10); break; case 't': * connection_type = CONNECTION_TYPE_TLS; break; case 'x': * connection_type = CONNECTION_TYPE_STARTTLS; break; case 'u': if (* user != NULL) free(* user); * user = strdup(optarg); break; case 'v': if (* password != NULL) free(* password); * password = strdup(optarg); break; case 'l': if (* path != NULL) free(* path); * path = strdup(optarg); break; case 'a': * auth_type = POP3_AUTH_TYPE_APOP; break; case 'c': if (* cache_directory != NULL) free(* cache_directory); * cache_directory = strdup(optarg); break; case 'f': if (* flags_directory != NULL) free(* flags_directory); * flags_directory = strdup(optarg); break; case 'D': mailstream_debug = 1; break; } } return 0; }
static void do_meta_request(kdev_t device) { struct ud_driver *driver = get_driver(major); struct ud_request *udr; struct request *req; char *buff; int major = MAJOR(device); printk("do_meta_request %d %x\n", major, blk_dev[major].current_request); if (NULL == driver) { end_request(0, req->rq_dev); return; } printk("1"); while (1) { req = blk_dev[major].current_request; printk("2"); if (!req || req->rq_dev < 0 || req->rq_sector == -1) return; printk("5"); udr = new_request(); udr->udr_type = UDR_BLK + req->rq_cmd; udr->udr_ptr = req->rq_sector; udr->udr_minor = MINOR(req->rq_dev); printk("6"); post_request(driver, udr); printk("7"); /* Should really check here whether we have a request */ if (req->rq_cmd == WRITE) { /* Can't do this, copies to the wrong task */ #if 0 verified_memcpy_tofs(driver->udd_data, buff, BLOCK_SIZE); /* FIXME FIXME */ fmemcpy(driver->udd_task->mm.dseg, driver->udd_data, get_ds(), buff, 1024); #endif } printk("8"); /* Wake up the driver so it can deal with the request */ wake_up(&driver->udd_wait); printk("request init: wake driver, sleeping\n"); sleep_on(&udr->udr_wait); printk("request continue\n"); /* REQUEST HAS BEEN RETURNED BY USER PROGRAM */ /* request must be dealt with and ended */ if (udr->udr_status == 1) { end_request(0, req->rq_dev); udr->udr_status = 0; continue; } udr->udr_status = 0; buff = req->rq_buffer; if (req->rq_cmd == READ) { /* Can't do this, copies from the wrong task */ #if 0 verified_memcpy_fromfs(buff, driver->udd_data, BLOCK_SIZE); /* FIXME FIXME */ fmemcpy(get_ds(), buff, driver->udd_task->mm.dseg, driver->udd_data, 1024); #endif } end_request(1, req->rq_dev); wake_up(&udr->udr_wait); } }
bool server_base::clear() { get_driver()->clear(); return true; }
static void HPRescanUsbBus(struct udev *udev) { int i, j; struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; /* all reader are marked absent */ for (i=0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++) readerTracker[i].status = READER_ABSENT; /* Create a list of the devices in the 'usb' subsystem. */ enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(enumerate, "usb"); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); /* For each item enumerated */ udev_list_entry_foreach(dev_list_entry, devices) { const char *devpath; struct udev_device *dev, *parent; struct _driverTracker *driver, *classdriver; int newreader; int bInterfaceNumber; const char *interface; /* Get the filename of the /sys entry for the device and create a udev_device object (dev) representing it */ devpath = udev_list_entry_get_name(dev_list_entry); dev = udev_device_new_from_syspath(udev, devpath); /* The device pointed to by dev contains information about the interface. In order to get information about the USB device, get the parent device with the subsystem/devtype pair of "usb"/"usb_device". This will be several levels up the tree, but the function will find it.*/ parent = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device"); if (!parent) continue; devpath = udev_device_get_devnode(parent); if (!devpath) { /* the device disapeared? */ Log1(PCSC_LOG_ERROR, "udev_device_get_devnode() failed"); continue; } driver = get_driver(parent, devpath, &classdriver); if (NULL == driver) /* no driver known for this device */ continue; #ifdef DEBUG_HOTPLUG Log2(PCSC_LOG_DEBUG, "Found matching USB device: %s", devpath); #endif newreader = TRUE; bInterfaceNumber = 0; interface = udev_device_get_sysattr_value(dev, "bInterfaceNumber"); if (interface) bInterfaceNumber = atoi(interface); /* Check if the reader is a new one */ for (j=0; j<PCSCLITE_MAX_READERS_CONTEXTS; j++) { if (readerTracker[j].devpath && (strcmp(readerTracker[j].devpath, devpath) == 0) && (bInterfaceNumber == readerTracker[j].bInterfaceNumber)) { /* The reader is already known */ readerTracker[j].status = READER_PRESENT; newreader = FALSE; #ifdef DEBUG_HOTPLUG Log2(PCSC_LOG_DEBUG, "Refresh USB device: %s", devpath); #endif break; } } /* New reader found */ if (newreader) HPAddDevice(dev, parent, devpath); /* free device */ udev_device_unref(dev); } /* Free the enumerator object */ udev_enumerate_unref(enumerate); /* check if all the previously found readers are still present */ for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++) { if ((READER_ABSENT == readerTracker[i].status) && (readerTracker[i].fullName != NULL)) { pthread_mutex_lock(&usbNotifierMutex); Log3(PCSC_LOG_INFO, "Removing USB device[%d]: %s", i, readerTracker[i].devpath); RFRemoveReader(readerTracker[i].fullName, PCSCLITE_HP_BASE_PORT + i); readerTracker[i].status = READER_ABSENT; free(readerTracker[i].devpath); readerTracker[i].devpath = NULL; free(readerTracker[i].fullName); readerTracker[i].fullName = NULL; pthread_mutex_unlock(&usbNotifierMutex); } } }
static void HPAddDevice(struct udev_device *dev, struct udev_device *parent, const char *devpath) { int i; char deviceName[MAX_DEVICENAME]; char fullname[MAX_READERNAME]; struct _driverTracker *driver, *classdriver; const char *sSerialNumber = NULL, *sInterfaceName = NULL; LONG ret; int bInterfaceNumber; driver = get_driver(parent, devpath, &classdriver); if (NULL == driver) { /* not a smart card reader */ #ifdef DEBUG_HOTPLUG Log2(PCSC_LOG_DEBUG, "%s is not a supported smart card reader", devpath); #endif return; } Log2(PCSC_LOG_INFO, "Adding USB device: %s", driver->readerName); bInterfaceNumber = atoi(udev_device_get_sysattr_value(dev, "bInterfaceNumber")); (void)snprintf(deviceName, sizeof(deviceName), "usb:%04x/%04x:libudev:%d:%s", driver->manuID, driver->productID, bInterfaceNumber, devpath); deviceName[sizeof(deviceName) -1] = '\0'; (void)pthread_mutex_lock(&usbNotifierMutex); /* find a free entry */ for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++) { if (NULL == readerTracker[i].fullName) break; } if (PCSCLITE_MAX_READERS_CONTEXTS == i) { Log2(PCSC_LOG_ERROR, "Not enough reader entries. Already found %d readers", i); (void)pthread_mutex_unlock(&usbNotifierMutex); return; } #ifdef ADD_INTERFACE_NAME sInterfaceName = udev_device_get_sysattr_value(dev, "interface"); #endif #ifdef ADD_SERIAL_NUMBER sSerialNumber = udev_device_get_sysattr_value(parent, "serial"); #endif /* name from the Info.plist file */ strlcpy(fullname, driver->readerName, sizeof(fullname)); /* interface name from the device (if any) */ if (sInterfaceName) { strlcat(fullname, " [", sizeof(fullname)); strlcat(fullname, sInterfaceName, sizeof(fullname)); strlcat(fullname, "]", sizeof(fullname)); } /* serial number from the device (if any) */ if (sSerialNumber) { /* only add the serial number if it is not already present in the * interface name */ if (!sInterfaceName || NULL == strstr(sInterfaceName, sSerialNumber)) { strlcat(fullname, " (", sizeof(fullname)); strlcat(fullname, sSerialNumber, sizeof(fullname)); strlcat(fullname, ")", sizeof(fullname)); } } readerTracker[i].fullName = strdup(fullname); readerTracker[i].devpath = strdup(devpath); readerTracker[i].status = READER_PRESENT; readerTracker[i].bInterfaceNumber = bInterfaceNumber; ret = RFAddReader(fullname, PCSCLITE_HP_BASE_PORT + i, driver->libraryPath, deviceName); if ((SCARD_S_SUCCESS != ret) && (SCARD_E_UNKNOWN_READER != ret)) { Log2(PCSC_LOG_ERROR, "Failed adding USB device: %s", driver->readerName); if (classdriver && driver != classdriver) { /* the reader can also be used by the a class driver */ ret = RFAddReader(fullname, PCSCLITE_HP_BASE_PORT + i, classdriver->libraryPath, deviceName); if ((SCARD_S_SUCCESS != ret) && (SCARD_E_UNKNOWN_READER != ret)) { Log2(PCSC_LOG_ERROR, "Failed adding USB device: %s", driver->readerName); readerTracker[i].status = READER_FAILED; (void)CheckForOpenCT(); } } else { readerTracker[i].status = READER_FAILED; (void)CheckForOpenCT(); } } (void)pthread_mutex_unlock(&usbNotifierMutex); } /* HPAddDevice */
int getComList(char *ttylist) { int retval = 0; struct dirent **namelist; struct serial_struct serinfo; char devicedir[1024]; char devfile[256]; char driver[64]; int n = 0, nn, fd; ttylist[0] = '\0'; if ((nn = scandir(SYSDIR, &namelist, NULL, NULL)) > 0) { while (n < nn) { if (strcmp(namelist[n]->d_name,"..") && strcmp(namelist[n]->d_name,".")) { // Construct full absolute file path sprintf(devicedir, "%s%s", SYSDIR, namelist[n]->d_name); // Get the device driver get_driver(devicedir, driver); if (strlen(driver) > 0) { // Non empty drivers might be ok //printf("Device: /dev/%s, Driver: %s\n", namelist[n]->d_name, driver); sprintf(devfile, "/dev/%s", namelist[n]->d_name); if (strstr(driver, "8250") != NULL) { // Check serial8250-devices separeately if ((fd = open(devfile, O_RDWR | O_NONBLOCK | O_NOCTTY)) >= 0) { // If device open if (ioctl(fd, TIOCGSERIAL, &serinfo) == 0) { // If can get get serial_info if (serinfo.type != PORT_UNKNOWN) { // If device type is no PORT_UNKNOWN we accept the port //printf("Device 8250 has port, accepted\n"); strcat(ttylist, "|"); strcat(ttylist, devfile); } } close(fd); } } else { // whatever has a driver and is not serial8250 is sure good strcat(ttylist, "|"); strcat(ttylist, devfile); } } } free(namelist[n]); n++; } free(namelist); } return (retval); }