int agg_init(hsignature_t *sig) { const char *val; val = session_getcfg("AGG_FUNC"); if (!val) { session_error("AGG_FUNC configuration key empty"); return -1; } if (strcasecmp(val, "MIN") == 0) agg_type = AGG_MIN; else if (strcasecmp(val, "MAX") == 0) agg_type = AGG_MAX; else if (strcasecmp(val, "MEAN") == 0) agg_type = AGG_MEAN; else if (strcasecmp(val, "MEDIAN") == 0) agg_type = AGG_MEDIAN; else { session_error("Invalide AGG_FUNC configuration value"); return -1; } val = session_getcfg("AGG_TIMES"); if (!val) { session_error("AGG_TIMES configuration key empty"); return -1; } trial_per_point = atoi(val); if (!trial_per_point) { session_error("Invalid AGG_TIMES configuration value"); return -1; } slist = NULL; slist_len = 0; return add_storage(); }
void twmtp_MtpServer::start() { usePtp = false; MyMtpDatabase* mtpdb = new MyMtpDatabase(); /* Sleep for a bit before we open the MTP USB device because some * devices are not ready due to the kernel not responding to our * sysfs requests right away. */ usleep(800000); #ifdef USB_MTP_DEVICE #define STRINGIFY(x) #x #define EXPAND(x) STRINGIFY(x) const char* mtp_device = EXPAND(USB_MTP_DEVICE); MTPI("Using '%s' for MTP device.\n", EXPAND(USB_MTP_DEVICE)); #else const char* mtp_device = "/dev/mtp_usb"; #endif int fd = open(mtp_device, O_RDWR); if (fd < 0) { MTPE("could not open MTP driver, errno: %d\n", errno); return; } MTPD("fd: %d\n", fd); server = new MtpServer(mtpdb, usePtp, 0, 0664, 0775); refserver = server; MTPI("created new mtpserver object\n"); add_storage(); MTPD("Starting add / remove mtppipe monitor thread\n"); pthread_t thread; ThreadPtr mtpptr = &twmtp_MtpServer::mtppipe_thread; PThreadPtr p = *(PThreadPtr*)&mtpptr; pthread_create(&thread, NULL, p, this); // This loop restarts the MTP process if the device is unplugged and replugged in while (true) { server->run(fd); fd = open(mtp_device, O_RDWR); usleep(800000); } }
int agg_analyze(hflow_t *flow, htrial_t *trial) { int i; store_t *store; for (i = 0; i < slist_len; ++i) { if (slist[i].id == trial->point.id || slist[i].id == -1) break; } if (i == slist_len && add_storage() != 0) return -1; store = &slist[i]; if (store->id == -1) { store->id = trial->point.id; store->count = 0; } if (store->trial[ store->count ] == NULL) store->trial[ store->count ] = hperf_clone(trial->perf); else hperf_copy(store->trial[ store->count ], trial->perf); ++store->count; if (store->count < trial_per_point) { flow->status = HFLOW_RETRY; return 0; } switch (agg_type) { case AGG_MIN: for (i = 0; i < trial_per_point; ++i) if (hperf_cmp(trial->perf, store->trial[i]) > 0) hperf_copy(trial->perf, store->trial[i]); break; case AGG_MAX: for (i = 0; i < trial_per_point; ++i) if (hperf_cmp(trial->perf, store->trial[i]) < 0) hperf_copy(trial->perf, store->trial[i]); break; case AGG_MEAN: perf_mean(trial->perf, store->trial, trial_per_point); break; case AGG_MEDIAN: qsort(store->trial, trial_per_point, sizeof(hperf_t *), perf_sort); i = (trial_per_point - 1) / 2; if (i % 2) hperf_copy(trial->perf, store->trial[i]); else perf_mean(trial->perf, &store->trial[i], 2); break; default: session_error("Internal error: Invalid AGG type"); return -1; } store->id = -1; store->count = 0; flow->status = HFLOW_ACCEPT; return 0; }