int dm_event_set_timeout(const char *device_path, uint32_t timeout) { struct dm_event_daemon_message msg = { 0, 0, NULL }; if (!device_exists(device_path)) return -ENODEV; return _do_event(DM_EVENT_CMD_SET_TIMEOUT, &msg, NULL, device_path, 0, timeout); }
evdi_device_status evdi_check_device(int device) { evdi_device_status status = NOT_PRESENT; int fd = device_exists(device) ? open_device(device) : -1; if (fd > 0) { status = is_evdi(fd) ? AVAILABLE : UNRECOGNIZED; close(fd); } return status; }
/* * Creates peudo DEV:DFx files. */ void initpseudodevices(void) { ULONG lock; int i; pseudo_dev_created = 0; pseudo_dev_assigned = 0; for(i=0;i<4;++i) dfx_done[i]=0; /* check if dev: already exists */ set_req(0);lock = Lock(amiga_dev_path,SHARED_LOCK);set_req(1); if(!lock) { char name[80]; set_req(0);lock = Lock(pseudo_dev_path,SHARED_LOCK);set_req(1); if(!lock) { /* create it */ lock = CreateDir(pseudo_dev_path); if(!lock) goto fail; UnLock(lock);lock = Lock(pseudo_dev_path,SHARED_LOCK); pseudo_dev_created = 1; } strcpy(name,amiga_dev_path); if(*name && name[strlen(name)-1]==':') name[strlen(name)-1]='\0'; if(!AssignLock(name,lock)) {UnLock(lock);goto fail;} /* the lock is the assign now */ pseudo_dev_assigned = 1; } else UnLock(lock); /* Create the dev:DFi entry */ for(i=0;i<4;++i) if(device_exists("trackdisk.device",i)) { ULONG fd; char name[80]; sprintf(name,"%sDF%d",amiga_dev_path,i); fd = Open(name,MODE_NEWFILE); if(fd) {Close(fd);dfx_done[i]=1;} } return; fail: fprintf(stderr,"Failed to create pseudo dev: entry!\n"); }
int dm_event_get_timeout(const char *device_path, uint32_t *timeout) { int ret; struct dm_event_daemon_message msg = { 0, 0, NULL }; if (!device_exists(device_path)) return -ENODEV; if (!(ret = _do_event(DM_EVENT_CMD_GET_TIMEOUT, &msg, NULL, device_path, 0, 0))) { char *p = _skip_string(msg.data, ' '); if (!p) { log_error("malformed reply from dmeventd '%s'\n", msg.data); return -EIO; } *timeout = atoi(p); } if (msg.data) dm_free(msg.data); return ret; }
/* * Copy one raw disk to a file. */ int readdevice(char *name, char *dst) { /* erhm, I must admit this code is long and ugly! */ FILE *f = NULL; char *device_name; int device_unit; int retstatus = 0; #ifdef HAVE_SIGACTION struct sigaction sa, oldsa; int oldsa_valid; /* disable break */ sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptymask(&sa.sa_mask); oldsa_valid = (0==sigaction(SIGINT, &sa, &oldsa)); #endif /* get device name & unit */ extract_dev_unit(name, &device_name, &device_unit); if(device_name) { /* if no destination then just check if the device exists */ if(dst == NULL) retstatus = device_exists(device_name, device_unit); else { /* open dest file */ if((f = fopen(dst,"wb"))) { retstatus = raw_copy(device_name, device_unit, f); fclose(f); } } free(device_name); } #ifdef HAVE_SIGACTION /* enable break */ if(oldsa_valid) sigaction(SIGINT, &oldsa, NULL); #endif return retstatus; }
/* * Copy one raw disk to a file. */ int readdevice(char *name, char *dst) { /* erhm, I must admit this code is long and ugly! */ FILE *f = NULL; char *device_name; int device_unit; int retstatus = 0; #ifdef HAVE_SIGACTION struct sigaction oldsa; int oldsa_valid; /* disable break */ oldsa_valid = (0==sigaction(SIGINT, NULL, &oldsa)); signal(SIGINT, SIG_IGN); /* <--- gcc complains about something */ /* in there but I don't know why. */ #endif /* get device name & unit */ extract_dev_unit(name, &device_name, &device_unit); if(device_name) { /* if no destination then just check if the device exists */ if(dst == NULL) retstatus = device_exists(device_name, device_unit); else { /* open dest file */ if((f = fopen(dst,"wb"))) { retstatus = raw_copy(device_name, device_unit, f); fclose(f); } } free(device_name); } #ifdef HAVE_SIGACTION /* enable break */ if(oldsa_valid) sigaction(SIGINT, &oldsa, NULL); #endif return retstatus; }
static bool vibra_exists() { return device_exists(THE_DEVICE); }
void processTCPSockets (fd_set readySocks) { int size; // Loop through the descriptors and process for (int sock = 0; sock <= maxDesc; sock++) { if (!FD_ISSET(sock, &readySocks)) continue; char* inBuffer = new char[BUFFERSIZE]; char* outBuffer = new char[BUFFERSIZE]; memset(inBuffer, 0, BUFFERSIZE); memset(outBuffer, 0, BUFFERSIZE); #if DEBUG cout << "PS: ProcessTCPSockets(" << sock << ")" << endl << endl; #endif // Receive data from the client receiveData(sock, inBuffer, size); //cout << "PS: " << size << " bytes received from socket " << sock << endl; int processed; int pos; int test_uid; int outBufferLen = 0; if(inBuffer[0] == '<' && inBuffer[1] == 'x') {// xml data std::stringstream ss; ss << inBuffer; pugi::xml_document doc; doc.load(ss); test_uid = atoi(doc.first_child().child("uid").child_value()); pos = device_exists(test_uid); // add new device if necessary if(pos == -1) { devices.push_back(Device()); std::cout << std::endl << "Devices: " << std::endl << std::endl; pos = devices.size()-1; std::cout << "Added new device " << std::endl << std::endl; devices[pos].set_state(WORKING); } processed = devices[pos].process_readings_xml(doc); } else { // raw data test_uid = (inBuffer[0] | (inBuffer[1] << 8) \ | (inBuffer[2] << 16) | (inBuffer[3] << 24)); pos = device_exists(test_uid); // add new device if necessary if(pos == -1) { devices.push_back(Device()); std::cout << std::endl << "Devices: " << std::endl << std::endl; pos = devices.size()-1; std::cout << "Added new device " << std::endl << std::endl; devices[pos].set_state(WORKING); devices[pos].set_battery(100); } processed = devices[pos].process_readings_raw(inBuffer); } if(devices[pos].get_battery() <= LOW_BATTERY) devices[pos].set_state(SHUTDOWN); else if((devices[pos].get_state() == SHUTDOWN) \ && (devices[pos].get_battery() > LOW_BATTERY)) devices[pos].set_state(WORKING); if(inBuffer[0] == '<' && inBuffer[1] == 'x') { // xml data std::stringstream ss; pugi::xml_document doc; ss.str(std::string()); devices[pos].create_confirm_xml(doc, processed); doc.print(ss); strcpy(outBuffer, ss.str().c_str()); outBufferLen = strlen(outBuffer); } else { // raw data outBufferLen = devices[pos].create_confirm_raw(outBuffer, processed); outBufferLen = outBufferLen*4+6; } sendData(sock, outBuffer, outBufferLen); devices[pos].save_readings(); delete[] inBuffer; delete[] outBuffer; devices[pos].print(); } }