static APTR OS4DevExpunge(struct Interface *self) { struct DevBase *base; APTR seg_list; base = (APTR)self->Data.LibBase; if(base->device.dd_Library.lib_OpenCnt == 0) { seg_list = base->seg_list; Remove((APTR)base); DeleteDevice(base); } else { base->device.dd_Library.lib_Flags |= LIBF_DELEXP; seg_list = NULL; } return seg_list; }
uint8_t RecvCommand() { uint8_t Cmd; char Username[32]; uint8_t TargetUser = MAX_USERS+1; uint8_t DeviceType; uint16_t DeviceId; uint16_t AlarmId; uint8_t NewDevice; uint8_t UserId; // Read in the one-byte command if (!ReadBytes((unsigned char *)&Cmd, 1)) { return(0); } switch (Cmd) { case CMD_POWER_OFF: SendResp(RESP_SUCCESS, NULL); return(0); break; case CMD_ADD_USER: if (!AddUser()) { SendResp(RESP_ADD_USER_FAILED, NULL); return(1); } SendResp(RESP_SUCCESS, NULL); break; case CMD_DEL_USER: if (!DelUser()) { SendResp(RESP_DEL_USER_FAILED, NULL); return(1); } SendResp(RESP_SUCCESS, NULL); break; case CMD_ADD_DEVICE: // Read in the device type if (!ReadBytes((unsigned char *)&DeviceType, 1)) { return(0); } // Find the next available device slot if ((NewDevice = FindAvailableDevice()) >= MAX_DEVICES) { SendResp(RESP_INVALID_CMD, NULL); return(0); } switch (DeviceType) { case DEVICE_KEYPAD: if (!(DeviceId = NewGenericDevice(DeviceType, NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(0); } break; case DEVICE_SWIPE: if (!(DeviceId = NewGenericDevice(DeviceType, NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(0); } break; case DEVICE_CONTACT: if (!(DeviceId = NewContact(NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(0); } break; case DEVICE_MOTION: if (!(DeviceId = NewMotion(NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(0); } break; case DEVICE_HEAT: if (!(DeviceId = NewHeat(NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(0); } break; case DEVICE_SMOKE: if (!(DeviceId = NewSmoke(NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(0); } break; case DEVICE_ALARM: if (!(DeviceId = NewGenericDevice(DeviceType, NewDevice))) { SendResp(RESP_ADD_DEVICE_FAILED, NULL); return(1); } break; default: SendResp(RESP_ADD_DEVICE_FAILED, NULL); break; } // Send success along with the generated DeviceId SendResp(RESP_SUCCESS, (unsigned char *)&DeviceId); break; case CMD_DEL_DEVICE: // Read in the device id if (!ReadBytes((unsigned char *)&DeviceId, 2)) { return(0); } if (!DeleteDevice(DeviceId)) { SendResp(RESP_DEL_DEVICE_FAILED, NULL); return(1); } SendResp(RESP_SUCCESS, NULL); break; case CMD_GRANT_ACCESS: // Read in the device id if (!ReadBytes((unsigned char *)&DeviceId, 2)) { return(0); } // Read in the user id if (!ReadBytes((unsigned char *)&UserId, 1)) { return(0); } if (!GrantAccess(DeviceId, UserId)) { SendResp(RESP_GRANT_FAILED, NULL); return(1); } SendResp(RESP_SUCCESS, NULL); break; case CMD_UPDATE_DEVICE: // Read in the device id if (!ReadBytes((unsigned char *)&DeviceId, 2)) { return(0); } if (!UpdateDevice(DeviceId)) { SendResp(RESP_UPDATE_DEVICE_FAILED, NULL); return(1); } SendResp(RESP_SUCCESS, NULL); break; case CMD_ADD_DEVICE_TO_ALARM: // Read in the device id if (!ReadBytes((unsigned char *)&DeviceId, 2)) { return(0); } // Read in the alarm id if (!ReadBytes((unsigned char *)&AlarmId, 2)) { return(0); } if (!AddDeviceToAlarm(DeviceId, AlarmId)) { SendResp(RESP_ADD_DEVICE_TO_ALARM_FAILED, NULL); return(0); } SendResp(RESP_SUCCESS, NULL); break; case CMD_LIST_ALARM_CODES: // Read in the device id if (!ReadBytes((unsigned char *)&DeviceId, 2)) { return(0); } if (!ListValidAlarmCodes(DeviceId)) { SendResp(RESP_INVALID_CMD, NULL); return(0); } break; default: SendResp(RESP_INVALID_CMD, NULL); return(1); break; } return(1); }
/* Edit_Button() * ======================================================================== * Handle Edit Devices Tree Buttons... */ int Edit_Button( int button, WORD *msg ) { int quit = FALSE; if( ( button != -1 ) && ( button & 0x8000 ) ) button &= 0x7FFF; switch( button ) { case EEXIT: Deselect( EEXIT ); RestoreMainTree(); break; case EDELETE: DeleteDevice(); break; case EADD: AddDevice(); break; case CURUP: case CURDOWN: CurDeviceUpDown( button ); break; case CURNAME: DoCurDrivers(); break; case CURROM: case CURRES: DoCurROMRES( button ); break; case AUP: case ADOWN: ADeviceUpDown( button ); break; case ANAME: DoADrivers(); break; case AROM: case ARES: DoAROMRES( button ); break; default: if( button == -1 ) { switch( msg[0] ) { case WM_REDRAW: break; case AC_CLOSE: quit = TRUE; break; case WM_CLOSED: quit = TRUE; CloseWindow(); break; case CT_KEY: break; default: break; } } break; } return( quit ); }
MODULE_FINI() { DeleteDevice(devRandom); kprintf("Unloaded mod_random\n"); return 0; };