//----------------------------------------------------------------------------- bool HIDDeviceManager::GetDescriptorFromPath(const char* dev_path, HIDDeviceDesc* desc) { if (!initializeManager()) { return false; } struct hid_device_info *devs, *cur_dev; devs = hid_enumerate(0x0, 0x0); cur_dev = devs; while (cur_dev) { if(strcmp(cur_dev->path,dev_path)==0) { desc->Path = String(cur_dev->path); getFullDesc(cur_dev, desc); } cur_dev = cur_dev->next; } hid_free_enumeration(devs); return true; }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { manager_t* managerPtr; client_t** clients; TIMER_T start; TIMER_T stop; /* Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_params[PARAM_CLIENTS]); managerPtr = initializeManager(); assert(managerPtr != NULL); clients = initializeClients(managerPtr); assert(clients != NULL); long numThread = global_params[PARAM_CLIENTS]; TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); /* Run transactions */ printf("Running clients... "); fflush(stdout); GOTO_SIM(); TIMER_READ(start); #ifdef OTM #pragma omp parallel { client_run(clients); } #else thread_start(client_run, (void*)clients); #endif TIMER_READ(stop); GOTO_REAL(); puts("done."); printf("Time = %0.6lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); checkTables(managerPtr); /* Clean up */ printf("Deallocating memory... "); fflush(stdout); freeClients(clients); /* * TODO: The contents of the manager's table need to be deallocated. */ manager_free(managerPtr); puts("done."); fflush(stdout); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }
bool HIDDeviceManager::Enumerate(HIDEnumerateVisitor* enumVisitor) { if (!initializeManager()) { return false; } CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager); CFIndex deviceCount = CFSetGetCount(deviceSet); // Allocate a block of memory and read the set into it. IOHIDDeviceRef* devices = (IOHIDDeviceRef*) OVR_ALLOC(sizeof(IOHIDDeviceRef) * deviceCount); CFSetGetValues(deviceSet, (const void **) devices); // Iterate over devices. for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { IOHIDDeviceRef hidDev = devices[deviceIndex]; if (!hidDev) { continue; } HIDDeviceDesc devDesc; if (getPath(hidDev, &(devDesc.Path)) && initVendorProductVersion(hidDev, &devDesc) && enumVisitor->MatchVendorProduct(devDesc.VendorId, devDesc.ProductId) && initUsage(hidDev, &devDesc)) { initStrings(hidDev, &devDesc); initSerialNumber(hidDev, &devDesc); // Construct minimal device that the visitor callback can get feature reports from. OSX::HIDDevice device(this, hidDev); enumVisitor->Visit(device, devDesc); } } OVR_FREE(devices); CFRelease(deviceSet); return true; }
//----------------------------------------------------------------------------- bool HIDDeviceManager::Enumerate(HIDEnumerateVisitor* enumVisitor) { if (!initializeManager()) { return false; } // Enumerate and print the HID devices on the system struct hid_device_info *devs, *cur_dev; devs = hid_enumerate(0x0, 0x0); cur_dev = devs; while (cur_dev) { // Check the VID/PID for a match if(enumVisitor->MatchVendorProduct(cur_dev->vendor_id, cur_dev->product_id)) { HIDDeviceDesc devDesc; devDesc.Path = String(cur_dev->path); getFullDesc(cur_dev, &devDesc); // Look for the device to check if it is already opened. Ptr<DeviceCreateDesc> existingDevice = DevManager->FindHIDDevice(devDesc, true); // if device exists and it is opened then most likely the device open() // will fail; therefore, we just set Enumerated to 'true' and continue. if (existingDevice && existingDevice->pDevice) { existingDevice->Enumerated = true; } else { //libusb does not support 'minimal' Linux::HIDDevice device(this); device.openDevice(devDesc.Path.ToCStr()); enumVisitor->Visit(device, devDesc); device.closeDevice(false); } } cur_dev = cur_dev->next; } hid_free_enumeration(devs); return true; }
bool HIDDeviceManager::Enumerate(HIDEnumerateVisitor* enumVisitor) { if (!initializeManager()) { return false; } CFSetRef deviceSet = IOHIDManagerCopyDevices(HIDManager); if (!deviceSet) return false; CFIndex deviceCount = CFSetGetCount(deviceSet); // Allocate a block of memory and read the set into it. IOHIDDeviceRef* devices = (IOHIDDeviceRef*) OVR_ALLOC(sizeof(IOHIDDeviceRef) * deviceCount); CFSetGetValues(deviceSet, (const void **) devices); // Iterate over devices. for (CFIndex deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { IOHIDDeviceRef hidDev = devices[deviceIndex]; if (!hidDev) { continue; } HIDDeviceDesc devDesc; if (getPath(hidDev, &(devDesc.Path)) && initVendorProductVersion(hidDev, &devDesc) && enumVisitor->MatchVendorProduct(devDesc.VendorId, devDesc.ProductId) && initUsage(hidDev, &devDesc)) { initStrings(hidDev, &devDesc); initSerialNumber(hidDev, &devDesc); // Look for the device to check if it is already opened. Ptr<DeviceCreateDesc> existingDevice = DevManager->FindHIDDevice(devDesc, true); // if device exists and it is opened then most likely the CreateHIDFile // will fail; therefore, we just set Enumerated to 'true' and continue. if (existingDevice && existingDevice->pDevice) { existingDevice->Enumerated = true; continue; } // open the device temporarily for startup communication if (IOHIDDeviceOpen(hidDev, kIOHIDOptionsTypeSeizeDevice) == kIOReturnSuccess) { // Construct minimal device that the visitor callback can get feature reports from. OSX::HIDDevice device(this, hidDev); enumVisitor->Visit(device, devDesc); IOHIDDeviceClose(hidDev, kIOHIDOptionsTypeSeizeDevice); } } } OVR_FREE(devices); CFRelease(deviceSet); return true; }
static void setup_signals() { struct sigaction sigact = { .sa_handler = terminate, .sa_flags = 0 }; sigemptyset(&sigact.sa_mask); sigaction(SIGTERM, &sigact, 0); sigaction(SIGINT, &sigact, 0); signal(SIGHUP, SIG_IGN); signal(SIGPIPE,SIG_IGN); } // main function int main() { if (!ensure_singleton(SINGLETON_LOCKFILE)) return 1; if (initialize_log() != 0) { LOGE("Init log failed. uninit\n"); terminate0(); LOGE("Daemon terminated\n"); exit(0); } LOGI("da_started\n"); atexit(terminate0); //for terminal exit setup_signals(); daemon(0, 1); LOGI("--- daemonized (pid %d) ---\n", getpid()); FILE *portfile = fopen(PORTFILE, "w"); if (!portfile) { LOGE("cannot create portfile"); return 1; } int err = initializeManager(portfile); fclose(portfile); if (err) return 1; //init all file descriptors init_system_file_descriptors(); //daemon work //FIX ME remove samplingThread it is only for debug //samplingThread(NULL); daemonLoop(); LOGI("daemon loop finished\n"); stop_all(); finalizeManager(); close_system_file_descriptors(); //DO NOT USE THIS FUNCTION FOR RELEASE IT IS TOO SLOW #ifdef MALLOC_DEBUG_LEVEL msg_swap_free_all_data(&prof_session.user_space_inst); #endif LOGI("main finished\n"); print_malloc_list(NULL, 0); return 0; }