std::auto_ptr<const parameter_reader_t> parameter_reader_t::get_child(const std::string& path) const { std::string name; std::string subpath; boost::tie(name, subpath) = split_path(path); if( path.empty() ) { PRX_FATAL_S("Calling get child with empty path"); } else if( subpath.empty() ) // No slash found { return std::auto_ptr<const parameter_reader_t > (get_subreader(path)); } else { if( !has_element(name) ) PRX_WARN_S("Can't follow path \"" << path << "\" from " << trace()); const parameter_reader_t* subreader = get_subreader(name); std::auto_ptr<const parameter_reader_t> child_reader = subreader->get_child(subpath); delete subreader; return child_reader; } }
std::string srvlib::ConfigReader::get_element(const std::string &key) const { if (!has_element(key)){ throw std::runtime_error("Couldn't find key!"); } else{ std::map<std::string, std::string>::const_iterator it = config_.find(key); return it->second; } }
static void fill_set_table(char *arg) { char *p = strtok(arg, ", "); psetid_t id; if (p == NULL) Die(gettext("invalid argument for -C\n")); if ((id = Atoi(p)) == 0) id = PS_NONE; add_element(&set_tbl, id); while (p = strtok(NULL, ", ")) { if ((id = Atoi(p)) == 0) id = PS_NONE; if (!has_element(&set_tbl, id)) add_element(&set_tbl, id); } }
std::vector<const parameter_reader_t*> parameter_reader_t::get_list(const std::string& path) const { std::string name; std::string subpath; boost::tie(name, subpath) = split_path(path); if( subpath.empty() ) // No slash found { return get_subreaders(path); } else { if( !has_element(name) ) PRX_WARN_S("Can't follow path \"" << path << "\" from " << trace()); const parameter_reader_t* subreader = get_subreader(name); std::vector<const parameter_reader_t*> subreaders = subreader->get_list(subpath); delete subreader; return subreaders; } }
void joypad::add_hid_element(IOHIDElementRef p_element) { const CFTypeID elementTypeID = p_element ? CFGetTypeID(p_element) : 0; if (p_element && (elementTypeID == IOHIDElementGetTypeID())) { const IOHIDElementCookie cookie = IOHIDElementGetCookie(p_element); const uint32_t usagePage = IOHIDElementGetUsagePage(p_element); const uint32_t usage = IOHIDElementGetUsage(p_element); Vector<rec_element> *list = NULL; switch (IOHIDElementGetType(p_element)) { case kIOHIDElementTypeInput_Misc: case kIOHIDElementTypeInput_Button: case kIOHIDElementTypeInput_Axis: { switch (usagePage) { case kHIDPage_GenericDesktop: switch (usage) { case kHIDUsage_GD_X: case kHIDUsage_GD_Y: case kHIDUsage_GD_Z: case kHIDUsage_GD_Rx: case kHIDUsage_GD_Ry: case kHIDUsage_GD_Rz: case kHIDUsage_GD_Slider: case kHIDUsage_GD_Dial: case kHIDUsage_GD_Wheel: if (!has_element(cookie, &axis_elements)) { list = &axis_elements; } break; case kHIDUsage_GD_Hatswitch: if (!has_element(cookie, &hat_elements)) { list = &hat_elements; } break; case kHIDUsage_GD_DPadUp: case kHIDUsage_GD_DPadDown: case kHIDUsage_GD_DPadRight: case kHIDUsage_GD_DPadLeft: case kHIDUsage_GD_Start: case kHIDUsage_GD_Select: if (!has_element(cookie, &button_elements)) { list = &button_elements; } break; } break; case kHIDPage_Simulation: switch (usage) { case kHIDUsage_Sim_Rudder: case kHIDUsage_Sim_Throttle: if (!has_element(cookie, &axis_elements)) { list = &axis_elements; } break; default: break; } break; case kHIDPage_Button: case kHIDPage_Consumer: if (!has_element(cookie, &button_elements)) { list = &button_elements; } break; default: break; } } break; case kIOHIDElementTypeCollection: { CFArrayRef array = IOHIDElementGetChildren(p_element); if (array) { add_hid_elements(array); } } break; default: break; } if (list) { /* add to list */ rec_element element; element.ref = p_element; element.usage = usage; element.min = (SInt32)IOHIDElementGetLogicalMin(p_element); element.max = (SInt32)IOHIDElementGetLogicalMax(p_element); element.cookie = IOHIDElementGetCookie(p_element); list->push_back(element); list->sort_custom<rec_element::Comparator>(); } } }
static void prstat_scandir(DIR *procdir) { char *pidstr; pid_t pid; id_t lwpid; size_t entsz; long nlwps, nent, i; char *buf, *ptr; fds_t *fds; lwp_info_t *lwp; dirent_t *direntp; prheader_t header; psinfo_t psinfo; prusage_t usage; lwpsinfo_t *lwpsinfo; prusage_t *lwpusage; total_procs = 0; total_lwps = 0; total_cpu = 0; total_mem = 0; convert_zone(&zone_tbl); for (rewinddir(procdir); (direntp = readdir(procdir)); ) { pidstr = direntp->d_name; if (pidstr[0] == '.') /* skip "." and ".." */ continue; pid = atoi(pidstr); if (pid == 0 || pid == 2 || pid == 3) continue; /* skip sched, pageout and fsflush */ if (has_element(&pid_tbl, pid) == 0) continue; /* check if we really want this pid */ fds = fds_get(pid); /* get ptr to file descriptors */ if (read_procfile(&fds->fds_psinfo, pidstr, "psinfo", &psinfo, sizeof (psinfo_t)) != 0) continue; if (!has_uid(&ruid_tbl, psinfo.pr_uid) || !has_uid(&euid_tbl, psinfo.pr_euid) || !has_element(&prj_tbl, psinfo.pr_projid) || !has_element(&tsk_tbl, psinfo.pr_taskid) || !has_zone(&zone_tbl, psinfo.pr_zoneid)) { fd_close(fds->fds_psinfo); continue; } nlwps = psinfo.pr_nlwp + psinfo.pr_nzomb; if (nlwps > 1 && (opts.o_outpmode & (OPT_LWPS | OPT_PSETS))) { int rep_lwp = 0; if (read_procfile(&fds->fds_lpsinfo, pidstr, "lpsinfo", &header, sizeof (prheader_t)) != 0) { fd_close(fds->fds_psinfo); continue; } nent = header.pr_nent; entsz = header.pr_entsize * nent; ptr = buf = Malloc(entsz); if (pread(fd_getfd(fds->fds_lpsinfo), buf, entsz, sizeof (struct prheader)) != entsz) { fd_close(fds->fds_lpsinfo); fd_close(fds->fds_psinfo); free(buf); continue; } nlwps = 0; for (i = 0; i < nent; i++, ptr += header.pr_entsize) { /*LINTED ALIGNMENT*/ lwpsinfo = (lwpsinfo_t *)ptr; if (!has_element(&cpu_tbl, lwpsinfo->pr_onpro) || !has_element(&set_tbl, lwpsinfo->pr_bindpset)) continue; nlwps++; if ((opts.o_outpmode & (OPT_PSETS | OPT_LWPS)) == OPT_PSETS) { /* * If one of process's LWPs is bound * to a given processor set, report the * whole process. We may be doing this * a few times but we'll get an accurate * lwp count in return. */ add_proc(&psinfo); } else { if (rep_lwp == 0) { rep_lwp = 1; add_lwp(&psinfo, lwpsinfo, LWP_REPRESENT); } else { add_lwp(&psinfo, lwpsinfo, 0); } } } free(buf); if (nlwps == 0) { fd_close(fds->fds_lpsinfo); fd_close(fds->fds_psinfo); continue; } } else { if (!has_element(&cpu_tbl, psinfo.pr_lwp.pr_onpro) || !has_element(&set_tbl, psinfo.pr_lwp.pr_bindpset)) { fd_close(fds->fds_psinfo); continue; } add_proc(&psinfo); } if (!(opts.o_outpmode & OPT_MSACCT)) { total_procs++; total_lwps += nlwps; continue; } /* * Get more information about processes from /proc/pid/usage. * If process has more than one lwp, then we may have to * also look at the /proc/pid/lusage file. */ if ((opts.o_outpmode & OPT_LWPS) && (nlwps > 1)) { if (read_procfile(&fds->fds_lusage, pidstr, "lusage", &header, sizeof (prheader_t)) != 0) { fd_close(fds->fds_lpsinfo); fd_close(fds->fds_psinfo); continue; } nent = header.pr_nent; entsz = header.pr_entsize * nent; buf = Malloc(entsz); if (pread(fd_getfd(fds->fds_lusage), buf, entsz, sizeof (struct prheader)) != entsz) { fd_close(fds->fds_lusage); fd_close(fds->fds_lpsinfo); fd_close(fds->fds_psinfo); free(buf); continue; } for (i = 1, ptr = buf + header.pr_entsize; i < nent; i++, ptr += header.pr_entsize) { /*LINTED ALIGNMENT*/ lwpusage = (prusage_t *)ptr; lwpid = lwpusage->pr_lwpid; /* * New LWPs created after we read lpsinfo * will be ignored. Don't want to do * everything all over again. */ if ((lwp = lwpid_get(pid, lwpid)) == NULL) continue; lwp_update(lwp, pid, lwpid, lwpusage); } free(buf); } else { if (read_procfile(&fds->fds_usage, pidstr, "usage", &usage, sizeof (prusage_t)) != 0) { fd_close(fds->fds_lpsinfo); fd_close(fds->fds_psinfo); continue; } lwpid = psinfo.pr_lwp.pr_lwpid; if ((lwp = lwpid_get(pid, lwpid)) == NULL) continue; lwp_update(lwp, pid, lwpid, &usage); } total_procs++; total_lwps += nlwps; } fd_update(); }