int compat_50_netbsd32_ntp_gettime(struct lwp *l, const struct compat_50_netbsd32_ntp_gettime_args *uap, register_t *retval) { /* { syscallarg(netbsd32_ntptimeval50p_t) ntvp; } */ struct netbsd32_ntptimeval50 ntv32; struct ntptimeval ntv; int error = 0; if (SCARG_P32(uap, ntvp)) { ntp_gettime(&ntv); ntv32.time.tv_sec = (int32_t)ntv.time.tv_sec; ntv32.time.tv_nsec = ntv.time.tv_nsec; ntv32.maxerror = (netbsd32_long)ntv.maxerror; ntv32.esterror = (netbsd32_long)ntv.esterror; ntv32.tai = (netbsd32_long)ntv.tai; ntv32.time_state = ntv.time_state; error = copyout(&ntv32, SCARG_P32(uap, ntvp), sizeof(ntv32)); } if (!error) { *retval = ntp_timestatus(); } return (error); }
int main(int argc, char **argv) { struct timeval tv; gettimeofday(&tv, NULL); struct ntptimeval ntptv; ntp_gettime(&ntptv); printf("gettimeofday: tv_sec = %ld, tv_usec = %ld\n", tv.tv_sec, tv.tv_usec); printf("ntp_gettime: tv_sec = %ld, tv_usec = %ld\n", ntptv.time.tv_sec, ntptv.time.tv_usec); }
static void current_ntp_clock_values (double *second, int *leap_second_indicator) { struct ntptimeval ntv; int status = ntp_gettime(&ntv); if (ntp_resolution != 0 && ( status == TIME_OK || status == TIME_INS || status == TIME_DEL || status == TIME_OOP || status == TIME_WAIT)) { if (ntp_resolution == 1e-6) { struct timeval *tv = (struct timeval *) &ntv.time; *second = tv->tv_sec + ntp_resolution * tv->tv_usec; } else { struct timespec *ts = (struct timespec *) &ntv.time; *second = ts->tv_sec + ntp_resolution * ts->tv_nsec; } *leap_second_indicator = (status == TIME_OOP); } else { *second = current_clock_second(); *leap_second_indicator = 0; } }
/* Some field mappings may be controversal, thus I give the reason * why this specific mapping was used: * APP-NAME <-- tag * Some may argue that "logger" is a better fit, but we think * this is better inline of what other implementations do. In * rsyslog, for example, the TAG value is populated from APP-NAME. * PROCID <-- pid * This is a relatively straightforward interpretation from * RFC5424, sect. 6.2.6. * MSGID <-- msgid (from --msgid) * One may argue that the string "logger" would be better suited * here so that a receiver can identify the sender process. * However, this does not sound like a good match to RFC5424, * sect. 6.2.7. * Note that appendix A.1 of RFC5424 does not provide clear guidance * of how these fields should be used. This is the case because the * IETF working group couldn't arrive at a clear agreement when we * specified RFC5424. The rest of the field mappings should be * pretty clear from RFC5424. -- Rainer Gerhards, 2015-03-10 */ static void syslog_rfc5424_header(struct logger_ctl *const ctl) { char *time; char *hostname; char *const app_name = ctl->tag; char *procid; char *const msgid = xstrdup(ctl->msgid ? ctl->msgid : NILVALUE); char *structured_data; if (ctl->fd < 0) return; if (ctl->rfc5424_time) { struct timeval tv; struct tm *tm; logger_gettimeofday(&tv, NULL); if ((tm = localtime(&tv.tv_sec)) != NULL) { char fmt[64]; const size_t i = strftime(fmt, sizeof(fmt), "%Y-%m-%dT%H:%M:%S.%%06u%z ", tm); /* patch TZ info to comply with RFC3339 (we left SP at end) */ fmt[i - 1] = fmt[i - 2]; fmt[i - 2] = fmt[i - 3]; fmt[i - 3] = ':'; xasprintf(&time, fmt, tv.tv_usec); } else err(EXIT_FAILURE, _("localtime() failed")); } else time = xstrdup(NILVALUE); if (ctl->rfc5424_host) { if (!(hostname = logger_xgethostname())) hostname = xstrdup(NILVALUE); /* Arbitrary looking 'if (var < strlen()) checks originate from * RFC 5424 - 6 Syslog Message Format definition. */ if (255 < strlen(hostname)) errx(EXIT_FAILURE, _("hostname '%s' is too long"), hostname); } else hostname = xstrdup(NILVALUE); if (48 < strlen(ctl->tag)) errx(EXIT_FAILURE, _("tag '%s' is too long"), ctl->tag); if (ctl->pid) xasprintf(&procid, "%d", ctl->pid); else procid = xstrdup(NILVALUE); if (ctl->rfc5424_tq) { #ifdef HAVE_NTP_GETTIME struct ntptimeval ntptv; if (ntp_gettime(&ntptv) == TIME_OK) xasprintf(&structured_data, "[timeQuality tzKnown=\"1\" isSynced=\"1\" syncAccuracy=\"%ld\"]", ntptv.maxerror); else #endif xasprintf(&structured_data, "[timeQuality tzKnown=\"1\" isSynced=\"0\"]"); } else structured_data = xstrdup(NILVALUE); xasprintf(&ctl->hdr, "<%d>1 %s %s %s %s %s %s ", ctl->pri, time, hostname, app_name, procid, msgid, structured_data); free(time); free(hostname); /* app_name points to ctl->tag, do NOT free! */ free(procid); free(msgid); free(structured_data); }
static void syslog_rfc5424(const struct logger_ctl *ctl, const char *msg) { char *buf, *tag = NULL, *hostname = NULL; char pid[32], time[64], timeq[80]; struct ntptimeval ntptv; struct timeval tv; struct tm *tm; int len; *pid = *time = *timeq = '\0'; if (ctl->fd < 0) return; if (ctl->rfc5424_time) { gettimeofday(&tv, NULL); if ((tm = localtime(&tv.tv_sec)) != NULL) { char fmt[64]; strftime(fmt, sizeof(fmt), " %Y-%m-%dT%H:%M:%S.%%06u%z", tm); snprintf(time, sizeof(time), fmt, tv.tv_usec); } else err(EXIT_FAILURE, _("localtime() failed")); } if (ctl->rfc5424_host) { hostname = xgethostname(); /* Arbitrary looking 'if (var < strlen()) checks originate from * RFC 5424 - 6 Syslog Message Format definition. */ if (255 < strlen(hostname)) errx(EXIT_FAILURE, _("hostname '%s' is too long"), hostname); } tag = ctl->tag ? ctl->tag : xgetlogin(); if (48 < strlen(tag)) errx(EXIT_FAILURE, _("tag '%s' is too long"), tag); if (ctl->pid) snprintf(pid, sizeof(pid), " %d", ctl->pid); if (ctl->rfc5424_tq) { if (ntp_gettime(&ntptv) == TIME_OK) snprintf(timeq, sizeof(timeq), " [timeQuality tzKnown=\"1\" isSynced=\"1\" syncAccuracy=\"%ld\"]", ntptv.maxerror); else snprintf(timeq, sizeof(timeq), " [timeQuality tzKnown=\"1\" isSynced=\"0\"]"); } len = xasprintf(&buf, "<%d>1%s%s%s %s -%s%s %s", ctl->pri, time, hostname ? " " : "", hostname ? hostname : "", tag, pid, timeq, msg); if (write_all(ctl->fd, buf, len) < 0) warn(_("write failed")); if (ctl->stderr_printout) fprintf(stderr, "%s\n", buf); free(hostname); free(buf); }
Image_show::Image_show(wxString sciezka, wxImage &obraz, wxString window_name, char metoda, wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size) { //(*Initialize(Image_show) wxStaticBoxSizer* StaticBoxSizer2; wxFlexGridSizer* FlexGridSizer4; wxFlexGridSizer* FlexGridSizer3; wxFlexGridSizer* FlexGridSizer5; wxFlexGridSizer* FlexGridSizer2; wxBoxSizer* BoxSizer1; wxStaticBoxSizer* StaticBoxSizer1; wxFlexGridSizer* FlexGridSizer1; Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY")); BoxSizer1 = new wxBoxSizer(wxHORIZONTAL); ScrolledWindow1 = new wxScrolledWindow(this, ID_SCROLLEDWINDOW1, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL|wxFULL_REPAINT_ON_RESIZE, _T("ID_SCROLLEDWINDOW1")); FlexGridSizer1 = new wxFlexGridSizer(3, 1, 0, 0); FlexGridSizer1->AddGrowableCol(0); FlexGridSizer1->AddGrowableRow(0); FlexGridSizer1->AddGrowableRow(1); FlexGridSizer4 = new wxFlexGridSizer(0, 3, 0, 0); FlexGridSizer4->AddGrowableCol(0); FlexGridSizer4->AddGrowableCol(1); FlexGridSizer4->AddGrowableCol(2); FlexGridSizer4->AddGrowableCol(3); FlexGridSizer4->AddGrowableRow(0); Obraz_po = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP5, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP5")); Obraz_po->SetMinSize(wxSize(250,250)); FlexGridSizer4->Add(Obraz_po, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, ScrolledWindow1, _("Histogram po")); FlexGridSizer5 = new wxFlexGridSizer(0, 3, 0, 0); FlexGridSizer5->AddGrowableCol(0); FlexGridSizer5->AddGrowableCol(1); FlexGridSizer5->AddGrowableCol(2); FlexGridSizer5->AddGrowableRow(0); Hist_po_R = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP6, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP6")); Hist_po_R->SetMinSize(wxSize(256,256)); FlexGridSizer5->Add(Hist_po_R, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); Hist_po_G = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP7, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP7")); FlexGridSizer5->Add(Hist_po_G, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); Hist_po_B = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP8, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP8")); FlexGridSizer5->Add(Hist_po_B, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); StaticBoxSizer2->Add(FlexGridSizer5, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer4->Add(StaticBoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer1->Add(FlexGridSizer4, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer2 = new wxFlexGridSizer(0, 3, 0, 0); FlexGridSizer2->AddGrowableCol(0); FlexGridSizer2->AddGrowableCol(1); FlexGridSizer2->AddGrowableCol(2); FlexGridSizer2->AddGrowableCol(3); FlexGridSizer2->AddGrowableRow(0); Obraz_bmp = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP1, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP1")); Obraz_bmp->SetMinSize(wxSize(250,250)); FlexGridSizer2->Add(Obraz_bmp, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, ScrolledWindow1, _("Histogram oryginalny")); FlexGridSizer3 = new wxFlexGridSizer(0, 3, 0, 0); FlexGridSizer3->AddGrowableCol(0); FlexGridSizer3->AddGrowableCol(1); FlexGridSizer3->AddGrowableCol(2); FlexGridSizer3->AddGrowableRow(0); Hist_R = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP2, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP2")); Hist_R->SetMinSize(wxSize(256,256)); FlexGridSizer3->Add(Hist_R, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); Hist_G = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP3, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP3")); FlexGridSizer3->Add(Hist_G, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); Hist_B = new wxStaticBitmap(ScrolledWindow1, ID_STATICBITMAP4, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP4")); FlexGridSizer3->Add(Hist_B, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); StaticBoxSizer1->Add(FlexGridSizer3, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer2->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer1->Add(FlexGridSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); czas_wczyt = new wxStaticText(ScrolledWindow1, ID_STATICTEXT2, _("Czas wczytywania: "), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2")); FlexGridSizer1->Add(czas_wczyt, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); czas = new wxStaticText(ScrolledWindow1, ID_STATICTEXT1, _("Czas wykonywania: "), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1")); FlexGridSizer1->Add(czas, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); Button1 = new wxButton(ScrolledWindow1, ID_BUTTON1, _("Zapisz Zmieniony obraz do pliku"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1")); FlexGridSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); ScrolledWindow1->SetSizer(FlexGridSizer1); FlexGridSizer1->Fit(ScrolledWindow1); FlexGridSizer1->SetSizeHints(ScrolledWindow1); BoxSizer1->Add(ScrolledWindow1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); SetSizer(BoxSizer1); FileDialog1 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, wxFileSelectorDefaultWildcardStr, wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog")); BoxSizer1->Fit(this); BoxSizer1->SetSizeHints(this); Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Image_show::OnButton1Click); //*) SetTitle(window_name); /*if (obraz2!=NULL) { obraz2->DrawHistogram(Hist_R, Hist_G, Hist_B); //obraz2->DrawDystrybuanta(Dyst_R, Dyst_G, Dyst_B); if (obraz2->GetWidth()>250 || obraz2->GetHeight()>250) { float scale; if (obraz2->GetWidth()/250>obraz2->GetHeight()/250) { scale=obraz2->GetWidth()/250; } else { scale=obraz2->GetHeight()/250; } scaled=obraz2->Scale(obraz2->GetWidth()/scale,obraz2->GetHeight()/scale); Obraz_bmp->SetBitmap(scaled); } else { Obraz_bmp->SetBitmap(obraz); } } else {*/ struct ntptimeval start; struct ntptimeval stop; wxString temp; ntp_gettime(&start); Obraz_bmp->SetBitmap(obraz); obrazek=new IMG(sciezka); obrazek->DrawHistogram(Hist_R, Hist_G, Hist_B); ntp_gettime(&stop); temp.Clear(); temp<<_("Czas Wczytywania obazu: "); temp<<double(((stop.time.tv_sec * 1000000)+stop.time.tv_usec) - ((start.time.tv_sec * 1000000 + -start.time.tv_usec)))/double(1000000); temp<<_(" s"); czas_wczyt->SetLabel(temp); ntp_gettime(&start); if(metoda==1) obrazek_po=obrazek->HistogramEqualisation_1(); else if(metoda==2) obrazek_po=obrazek->HistogramEqualisation_2(); else if(metoda==3) obrazek_po=obrazek->HistogramEqualisation_3(); else obrazek_po=obrazek->HistogramEqualisation_wlasna(); obrazek_po->DrawHistogram(Hist_po_R, Hist_po_G, Hist_po_B); if (obrazek_po->GetWidth()>250 || obrazek_po->GetHeight()>250) { float scale; if (obrazek_po->GetWidth()/250>obrazek_po->GetHeight()/250) { scale=obrazek_po->GetWidth()/250; } else { scale=obrazek_po->GetHeight()/250; } scaled_po=obrazek_po->Scale(obrazek_po->GetWidth()/scale,obrazek_po->GetHeight()/scale); Obraz_po->SetBitmap(scaled_po); } else { Obraz_po->SetBitmap(*obrazek_po); } ntp_gettime(&stop); temp.Clear(); temp<<_("Czas wykonywania obliczeń: "); temp<<double(((stop.time.tv_sec * 1000000)+stop.time.tv_usec) - ((start.time.tv_sec * 1000000 + -start.time.tv_usec)))/double(1000000); temp<<_(" s"); czas->SetLabel(temp); //DEBUG_lut *temp=new DEBUG_lut(obrazek->GetLut(),window_name); //temp->Show(); }