// ignore parameters in this sample service void CSpacService :: Run(DWORD, LPTSTR *) { if (g_SingleInstanceObj.IsAnotherInstanceRunning()){ utils_error("Another PMCSpac Daemon instance is already running.\n"); return; } // report to the SCM that we're about to start utils_trace("Starting PMC Serial Port Access Coordinator Version 1.0...\n"); ReportStatus(SERVICE_START_PENDING); m_hStop = ::CreateEvent(0, FALSE, FALSE, 0); SECURITY_ATTRIBUTES sd; ZeroMemory(&sd, sizeof(sd)); sd.nLength = sizeof(sd); m_hRestart = ::CreateEvent(&sd, FALSE, FALSE, SPAC_RESET_EVENT); HANDLE handles[2]; handles[0] = m_hStop; handles[1] = m_hRestart; // You might do some more initialization here. // Parameter processing for instance ... utils_trace("PMC Serial Port Access Coordinator Version 1.0 started...\n"); init(); // enter main-loop // If the Stop() method sets the event, then we will break out of // this loop. // report SERVICE_RUNNING immediately before you enter the main-loop // DON'T FORGET THIS! ReportStatus(SERVICE_RUNNING); bool bStop = false; while(!bStop){ switch(MsgWaitForMultipleObjects(2,handles,false,INFINITE,QS_ALLEVENTS) ){ case WAIT_OBJECT_0: bStop = true; break; case WAIT_OBJECT_0 + 1: _restart(); break; case WAIT_OBJECT_0 + 2: MSG msg; while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); break; } } } if( m_hStop ) ::CloseHandle(m_hStop); uninit(); ReportStatus(SERVICE_STOPPED); }
bool MDNSResponder::begin(const char* hostname) { size_t n = strlen(hostname); if (n > 63) { // max size for a single label. return false; } // Copy in hostname characters as lowercase _hostName = hostname; _hostName.toLowerCase(); // If instance name is not already set copy hostname to instance name if (_instanceName.equals("")) _instanceName = hostname; _gotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& event) { _restart(); }); _disconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& event) { _restart(); }); return _listen(); }
/* Disable interrupts Load new values into the interrupt vector memory space Jump to address 0 */ void reboot() { int i; /* Disable all interrupts */ /* Disable ethmac_int interrupt */ /* Disable timer 0 interrupt in interrupt controller */ *(unsigned int *) ( ADR_AMBER_IC_IRQ0_ENABLECLR ) = 0x120; for(i=0;i<MEM_BUF_ENTRIES;i++) if (elf_mem0_g->entry[i].valid) *(char *)(i) = elf_mem0_g->entry[i].data; if (udp_file_g->linux_boot) _jump_to_program(LINUX_JUMP_ADR); else _restart(); }
void CPlaybackTaskGroup::_update( long internalTicks) { CEvent ev; switch (syncType) { case SyncType_FreeRunning: case SyncType_SongInternal: { if (flags & Clock_Halted) { // Push back origin so that real.time stays the same origin = internalTicks - real.time; return; } else { // Compute new values for real and metered time. real.time = internalTicks - origin; metered.time = tempo.ConvertRealToMetered(real.time); } break; } case SyncType_SongMTC: { // I think this is where the external sync code would go... break; } case SyncType_SongMidiClocks: { // I think this is where the external sync code would go... break; } } // If we are not in the middle of locating, then go ahead and // play some events. if (ClockRunning()) { // Record what time our track is positioned to. real.seekTime = real.time; metered.seekTime = metered.time; // Pop events off of the stack which are ready to go while (real.stack.Pop(ev, real.seekTime)) _executeEvent(ev, real); while (metered.stack.Pop(ev, metered.seekTime)) _executeEvent(ev, metered); long next; bool done = true; // Compute next event time as min of all track times if (real.stack.NextTime(&next)) { done = false; if (IsTimeGreater(next, nextEventTime)) nextEventTime = next; } // Same computation for metered stack, but with a conversion // to real time if (metered.stack.NextTime(&next)) { done = false; next = tempo.ConvertMeteredToReal(next); if (IsTimeGreater(next, nextEventTime)) nextEventTime = next; } // Looping options for entire task! if (pbOptions & PB_Loop) { if (done) { if (real.end < 0) real.end = real.seekTime; _restart(); nextEventTime = real.time; } } else { // If both stacks are empty, then stop if (done && !(flags & Clock_Continuous)) { flags |= Clock_Stopped; // Notify the UI that we've changed state. BMessage message(Player_ChangeTransportState); be_app->PostMessage(&message); } } } }
static int task_main(int argc, char *argv[]) { work_q_item_t *work; /* Initialize global variables */ g_key_offsets[0] = 0; for (unsigned i = 0; i < (DM_KEY_NUM_KEYS - 1); i++) { g_key_offsets[i + 1] = g_key_offsets[i] + (g_per_item_max_index[i] * k_sector_size); } unsigned max_offset = g_key_offsets[DM_KEY_NUM_KEYS - 1] + (g_per_item_max_index[DM_KEY_NUM_KEYS - 1] * k_sector_size); for (unsigned i = 0; i < dm_number_of_funcs; i++) { g_func_counts[i] = 0; } /* Initialize the item type locks, for now only DM_KEY_MISSION_STATE supports locking */ px4_sem_init(&g_sys_state_mutex, 1, 1); /* Initially unlocked */ for (unsigned i = 0; i < DM_KEY_NUM_KEYS; i++) { g_item_locks[i] = NULL; } g_item_locks[DM_KEY_MISSION_STATE] = &g_sys_state_mutex; g_task_should_exit = false; init_q(&g_work_q); init_q(&g_free_q); px4_sem_init(&g_work_queued_sema, 1, 0); /* See if the data manage file exists and is a multiple of the sector size */ g_task_fd = open(k_data_manager_device_path, O_RDONLY | O_BINARY); if (g_task_fd >= 0) { #ifndef __PX4_POSIX // XXX on Mac OS and Linux the file is not a multiple of the sector sizes // this might need further inspection. /* File exists, check its size */ int file_size = lseek(g_task_fd, 0, SEEK_END); if ((file_size % k_sector_size) != 0) { PX4_WARN("Incompatible data manager file %s, resetting it", k_data_manager_device_path); PX4_WARN("Size: %u, sector size: %d", file_size, k_sector_size); close(g_task_fd); unlink(k_data_manager_device_path); } #else close(g_task_fd); #endif } /* Open or create the data manager file */ g_task_fd = open(k_data_manager_device_path, O_RDWR | O_CREAT | O_BINARY, PX4_O_MODE_666); if (g_task_fd < 0) { PX4_WARN("Could not open data manager file %s", k_data_manager_device_path); px4_sem_post(&g_init_sema); /* Don't want to hang startup */ return -1; } if ((unsigned)lseek(g_task_fd, max_offset, SEEK_SET) != max_offset) { close(g_task_fd); PX4_WARN("Could not seek data manager file %s", k_data_manager_device_path); px4_sem_post(&g_init_sema); /* Don't want to hang startup */ return -1; } fsync(g_task_fd); /* see if we need to erase any items based on restart type */ int sys_restart_val; const char *restart_type_str = "Unkown restart"; if (param_get(param_find("SYS_RESTART_TYPE"), &sys_restart_val) == OK) { if (sys_restart_val == DM_INIT_REASON_POWER_ON) { restart_type_str = "Power on restart"; _restart(DM_INIT_REASON_POWER_ON); } else if (sys_restart_val == DM_INIT_REASON_IN_FLIGHT) { restart_type_str = "In flight restart"; _restart(DM_INIT_REASON_IN_FLIGHT); } } /* We use two file descriptors, one for the caller context and one for the worker thread */ /* They are actually the same but we need to some way to reject caller request while the */ /* worker thread is shutting down but still processing requests */ g_fd = g_task_fd; PX4_INFO("%s, data manager file '%s' size is %d bytes", restart_type_str, k_data_manager_device_path, max_offset); /* Tell startup that the worker thread has completed its initialization */ px4_sem_post(&g_init_sema); /* Start the endless loop, waiting for then processing work requests */ while (true) { /* do we need to exit ??? */ if ((g_task_should_exit) && (g_fd >= 0)) { /* Close the file handle to stop further queuing */ g_fd = -1; } if (!g_task_should_exit) { /* wait for work */ px4_sem_wait(&g_work_queued_sema); } /* Empty the work queue */ while ((work = dequeue_work_item())) { /* handle each work item with the appropriate handler */ switch (work->func) { case dm_write_func: g_func_counts[dm_write_func]++; work->result = _write(work->write_params.item, work->write_params.index, work->write_params.persistence, work->write_params.buf, work->write_params.count); break; case dm_read_func: g_func_counts[dm_read_func]++; work->result = _read(work->read_params.item, work->read_params.index, work->read_params.buf, work->read_params.count); break; case dm_clear_func: g_func_counts[dm_clear_func]++; work->result = _clear(work->clear_params.item); break; case dm_restart_func: g_func_counts[dm_restart_func]++; work->result = _restart(work->restart_params.reason); break; default: /* should never happen */ work->result = -1; break; } /* Inform the caller that work is done */ px4_sem_post(&work->wait_sem); } /* time to go???? */ if ((g_task_should_exit) && (g_fd < 0)) { break; } } close(g_task_fd); g_task_fd = -1; /* The work queue is now empty, empty the free queue */ for (;;) { if ((work = (work_q_item_t *)sq_remfirst(&(g_free_q.q))) == NULL) { break; } if (work->first) { free(work); } } destroy_q(&g_work_q); destroy_q(&g_free_q); px4_sem_destroy(&g_work_queued_sema); px4_sem_destroy(&g_sys_state_mutex); return 0; }
/* Main entry point */ int main(int argc, char **argv) { XfdashboardApplication *app=NULL; gint status; #ifdef ENABLE_NLS /* Set up localization */ xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); #endif #if !GLIB_CHECK_VERSION(2, 36, 0) /* Initialize GObject type system */ g_type_init(); #endif #if CLUTTER_CHECK_VERSION(1, 16, 0) /* Enforce X11 backend in Clutter. This function must be called before any * other Clutter API function. */ clutter_set_windowing_backend("x11"); #endif /* Tell clutter to try to initialize an RGBA visual */ clutter_x11_set_use_argb_visual(TRUE); /* Initialize GTK+ and Clutter */ gtk_init(&argc, &argv); if(!clutter_init(&argc, &argv)) { g_error(_("Initializing clutter failed!")); return(1); } /* Notify that application has started and main loop will be entered */ gdk_notify_startup_complete(); /* Start application as primary or remote instace */ app=xfdashboard_application_get_default(); if(!app) { g_warning(_("Failed to create application instance")); return(XFDASHBOARD_APPLICATION_ERROR_FAILED); } status=g_application_run(G_APPLICATION(app), argc, argv); if(status==XFDASHBOARD_APPLICATION_ERROR_RESTART && g_application_get_is_remote(G_APPLICATION(app))) { /* Wait for existing primary instance to quit */ if(_restart(app)) { g_debug("Reached clean state to restart application"); /* Destroy remote instance application object for restart */ g_object_unref(app); app=NULL; /* Create new application instance which should become * the new primary instance. */ app=xfdashboard_application_get_default(); if(!app) { g_warning(_("Failed to create application instance")); return(XFDASHBOARD_APPLICATION_ERROR_FAILED); } g_debug("Starting new primary instance"); status=g_application_run(G_APPLICATION(app), argc, argv); } else { g_warning(_("Could not restart application because existing instance seems still to be running.")); } } /* Clean up, release allocated resources */ g_object_unref(app); return(status); }
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); }
void LLMNRResponder::notify_ap_change() { _restart(); }