/* service control handler */ static VOID WINAPI handler(DWORD control) { switch(control) { case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: set_state1(SERVICE_STOP_PENDING); break; default: set_state(); } }
void EXTI15_10_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line11) != RESET) { set_state0(); //GPIO_ToggleBits(GPIOG, GPIO_Pin_13); // Clear the EXTI line pending bit EXTI_ClearITPendingBit(EXTI_Line11); } else if(EXTI_GetITStatus(EXTI_Line12) != RESET) { set_state1(); //GPIO_ToggleBits(GPIOG, GPIO_Pin_13); EXTI_ClearITPendingBit(EXTI_Line12); } //else if(EXTI_GetITStatus(EXTI_Line13) != RESET) { //GPIO_ToggleBits(GPIOG, GPIO_Pin_13); //EXTI_ClearITPendingBit(EXTI_Line13); //} else if(EXTI_GetITStatus(EXTI_Line14) != RESET) { //GPIO_ToggleBits(GPIOG, GPIO_Pin_13); //EXTI_ClearITPendingBit(EXTI_Line14); //} }
static BOOL set_state() { return set_state1(svc_state); }
/* service_main */ static VOID WINAPI service_main(DWORD argc, LPTSTR *argv) { config_t conf; void* net; void* threads; void* pipe; h_service = RegisterServiceCtrlHandler(LDMSVC_SERVICE_NAME, handler); if(h_service == NULL) { return; } set_state1(SERVICE_START_PENDING); // SERVICE_START_PENDING // open the heap if(!heap_start()) { dout("Failed to create the heap\n"); set_state2(SERVICE_STOPPED, 1); return; } // parse configuration if(!config_parse_args(&conf, argc, argv)) { heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } if(0) { dout(va("PORT: %u\n", conf.port)); dout(va("PIPE: %s\n", conf.pipe)); dout(va("MAXC: %u\n", conf.maxconn)); } // open network if((net = net_start()) == NULL) { heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } // open the pipe if((pipe = pipe_start(conf.pipe)) == NULL) { net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } // connect the pipe if(!pipe_open(pipe)) { pipe_stop(pipe); net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } // start threads if((threads = threads_start(net, pipe, conf.maxconn)) == NULL) { pipe_stop(pipe); net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 1); return; } set_state1(SERVICE_RUNNING); // SERVICE_RUNNING while(svc_state == SERVICE_RUNNING) { if(!net_is_ready(net)) { net_bind(net, NULL, conf.port); } if(!threads_think(threads)) { break; } Sleep(1); } set_state1(SERVICE_STOP_PENDING); // SERVICE_STOP_PENDING // close everything here threads_stop(threads); pipe_stop(pipe); net_stop(net); heap_stop(); set_state2(SERVICE_STOPPED, 0); // SERVICE_STOPPED }