int notify(NotifyNotification **notification, int red, int min, int max) { if (*notification == NULL) notifyInit(notification); unsigned int value = 100 * (red - min) / (max - min); if (text[0] != '\0') { if (value > 100) value = 100; sprintf(text, "%3u%% ", value); const unsigned int top = 5 + (sizeof(text) - 5 - 1) * value / 100; for (unsigned int i = 5; i < top; i++) text[i] = '|'; text[top] = '\0'; value = 0; } notify_notification_update(*notification, "Red", text, red == max ? icon_off : icon_on); notify_notification_set_hint_uint32(*notification, "value", value); GError *error = NULL; notify_notification_show(*notification, &error); if (error) { g_printerr("ERROR: %s\n", error->message); g_error_free(error); return -1; } return 0; }
void dbProcessNotify(processNotify *ppn) { struct dbChannel *chan = ppn->chan; dbCommon *precord = dbChannelRecord(chan); short dbfType = dbChannelFieldType(chan); notifyPvt *pnotifyPvt; /* Must handle DBF_XXXLINKs as special case. * Only dbPutField will change link fields. * Also the record is not processed as a result */ ppn->status = notifyOK; ppn->wasProcessed = 0; if (dbfType>=DBF_INLINK && dbfType<=DBF_FWDLINK) { if (ppn->requestType == putProcessRequest || ppn->requestType == putProcessGetRequest) { /* Check if puts disabled */ if (precord->disp && (dbChannelField(ppn->chan) != (void *) &precord->disp)) { ppn->putCallback(ppn, putDisabledType); } else { ppn->putCallback(ppn, putFieldType); } } if (ppn->requestType == processGetRequest || ppn->requestType == putProcessGetRequest) { ppn->getCallback(ppn, getFieldType); } ppn->doneCallback(ppn); return; } dbScanLock(precord); epicsMutexMustLock(pnotifyGlobal->lock); pnotifyPvt = (notifyPvt *) ppn->pnotifyPvt; if (pnotifyPvt && (pnotifyPvt->magic != MAGIC)) { printf("dbPutNotify:pnotifyPvt was not initialized\n"); pnotifyPvt = 0; } if (pnotifyPvt) { assert(pnotifyPvt->state == notifyUserCallbackActive); pnotifyPvt->userCallbackWait = 1; epicsMutexUnlock(pnotifyGlobal->lock); dbScanUnlock(precord); epicsEventWait(pnotifyPvt->userCallbackEvent); dbScanLock(precord); epicsMutexMustLock(pnotifyGlobal->lock); notifyCleanup(ppn); } pnotifyPvt = (notifyPvt *) ppn->pnotifyPvt; assert(!pnotifyPvt); notifyInit(ppn); pnotifyPvt = (notifyPvt *) ppn->pnotifyPvt; if (!precord->ppnr) { /* make sure record has a processNotifyRecord*/ precord->ppnr = dbCalloc(1, sizeof(processNotifyRecord)); precord->ppnr->precord = precord; ellInit(&precord->ppnr->restartList); } processNotifyCommon(ppn, precord); }
int main(int argc, char **argv) { PFWatchdogRegister (argc, argv, EPFWD_MODE_REBOOT, 30); notifyInit(); configEventInit(); configInit(PFCONFIG_NAME); run(); configEventExit(); notifyExit(); configUpdate(1); PFWatchdogUnregister (); return 0; }
void processMessages(int sock) { const int sz = strlen(command) + BUFFER_SIZE; struct sockaddr_in cli_addr; char buffer[sz]; char arg[BUFFER_SIZE]; int red = RED_MAX; NotifyNotification *notification = NULL; while(1) { socklen_t clilen = sizeof(cli_addr); int newsock = accept(sock, (struct sockaddr *)&cli_addr, &clilen); if (newsock < 0) die("Cannot accept connection"); int n = read(newsock, arg, BUFFER_SIZE); if (n < 0) die("Cannot read from socket"); else if (n == 0) break; arg[n] = '\0'; int num = getRed(arg, red, RED_MIN, RED_MAX); if (snprintf(buffer, sz, command, num) > 0) { red = num; system(buffer); // FIXME: Sometimes gives error: // GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name :1.167 was not provided by any .service files if (notify(¬ification, red, RED_MIN, RED_MAX) == -1) { notifyUninit(¬ification); notifyInit(¬ification); notify(¬ification, red, RED_MIN, RED_MAX); } } close(newsock); }; notifyUninit(¬ification); }