ambit_object_t * libambit_new_from_pathname(const char* pathname) { ambit_object_t *object = NULL; ambit_device_info_t *info; ambit_device_info_t *current; if (!pathname) { LOG_ERROR("%s", strerror(EINVAL)); return NULL; } info = libambit_enumerate(); current = info; while (!object && current) { if (0 == strcmp(pathname, current->path)) { object = libambit_new(current); } current = current->next; } libambit_free_enumeration(info); return object; }
void DeviceManager::detect() { int res = -1; mutex.lock(); if (this->deviceObject != NULL) { libambit_close(this->deviceObject); this->deviceObject = NULL; emit deviceRemoved(); } ambit_device_info_t *devinfo = libambit_enumerate(); if (devinfo) { this->currentDeviceInfo = *devinfo; emit deviceDetected(this->currentDeviceInfo); this->deviceObject = libambit_new(devinfo); } libambit_free_enumeration(devinfo); mutex.unlock(); if (res == 0) { chargeTimerHit(); } }