int on_switch(char * v, void *d) { __bool ok = __false; CArgs args; PCRTK_PACKET p = (PCRTK_PACKET)d; parse_arg_ex(v, &args, " "); if(args.argc >= 2){ if(!strcmpi(args.argv[1], "primary")){ ok = switch_to_primary(); }else if(!strcmpi(args.argv[1], "backup")){ ok = switch_to_backup(); } } send_rtk_data_with_guid( vbus_system, &p->src, &p->guid, ok ? PT_System : PT_System | PF_Failed | PF_ACK, 0, 0 ); return 0; }
void CRtkService::Run(__uint, char **) #endif { __uint res; // report to the SCM that we're about to start utils_trace("Starting %s...\n", versionString.c_str()); ReportStatus(SERVICE_START_PENDING); signal(SIGINT, _ctrl_c); try{ if(!_init()){ throw(this); } ReportStatus(SERVICE_RUNNING); __int logCounter = 24*3600*1000/PrimaryCheckInterval; while(!bExit){ res = m_hStop.Wait(PrimaryCheckInterval); switch(res){ case WAIT_OBJECT_0: switch(m_dwStopReason){ case 0: bExit = true; break; case 1: _restart(); ReportStatus(SERVICE_RUNNING); break; case 2: break; } if(get_power_state()==PWR_RUNNING){ notify_active(); } break; case WAIT_TIMEOUT: switch(get_power_state()){ case PWR_RUNNING: notify_active(); break; case PWR_BACKUP: PrimaryWatchDogCounter--; if(PrimaryWatchDogCounter <= 0){ utils_trace("Primary site failed, resuming responsibility.\n"); switch_to_primary(); } break; } logCounter--; if(logCounter <= 0){ close_log(); open_log(); logCounter = 24*3600*1000/PrimaryCheckInterval; } break; } } _uninit(); }catch(CRtkService *){ utils_error("Aborted.\n"); } ReportStatus(SERVICE_STOPPED); }