void is_indicator_set_primary_sensor_path(IsIndicator *self, const gchar *path) { IsIndicatorPrivate *priv; g_return_if_fail(IS_IS_INDICATOR(self)); priv = self->priv; if (g_strcmp0(priv->primary_sensor_path, path) != 0 && g_strcmp0(path, "") != 0) { IsSensor *sensor; is_debug("indicator", "new primary sensor path %s (previously %s)", path, priv->primary_sensor_path); /* uncheck current primary sensor label - may be NULL as is * already disabled */ if (priv->primary) { GtkCheckMenuItem *item; item = (GtkCheckMenuItem *)(g_object_get_data(G_OBJECT(priv->primary), "menu-item")); if (item) { gtk_check_menu_item_set_active(item, FALSE); } g_object_unref(priv->primary); } g_free(priv->primary_sensor_path); priv->primary_sensor_path = g_strdup(path); is_debug("indicator", "Setting primary sensor path to: %s", path); /* try and activate this sensor if it exists */ sensor = is_manager_get_sensor(is_application_get_manager(priv->application), priv->primary_sensor_path); if (sensor) { GtkCheckMenuItem *item = (GtkCheckMenuItem *)(g_object_get_data(G_OBJECT(sensor), "menu-item")); /* take reference from manager */ priv->primary = sensor; if (item) { gtk_check_menu_item_set_active(item, TRUE); update_sensor_menu_item_label(self, sensor, GTK_MENU_ITEM(item)); } } g_object_notify_by_pspec(G_OBJECT(self), properties[PROP_PRIMARY_SENSOR_PATH]); } }
static void is_max_plugin_deactivate(PeasActivatable *activatable) { IsMaxPlugin *self = IS_MAX_PLUGIN(activatable); IsMaxPluginPrivate *priv = self->priv; IsManager *manager; GSList *sensors, *_list; is_debug("max", "dettaching from signals"); manager = is_application_get_manager(priv->application); is_manager_remove_path(manager, MAX_SENSOR_PATH); sensors = is_manager_get_enabled_sensors_list(manager); for (_list = sensors; _list != NULL; _list = _list->next) { IsSensor *sensor = IS_SENSOR(_list->data); on_sensor_disabled(manager, sensor, self); g_object_unref(sensor); } g_slist_free(sensors); g_signal_handlers_disconnect_by_func(manager, G_CALLBACK(on_sensor_enabled), self); g_signal_handlers_disconnect_by_func(manager, G_CALLBACK(on_sensor_disabled), self); }
void build_search_table(symtab_t *symtab) { int i; for (i = 0; i < symtab->num_symbols; i++) { DBT key, value; key.data = symtab->symbols[i].name; key.size = strlen(key.data) + 1; value.data = &(symtab->symbols[i]); value.size = sizeof(symtab_symbol); (*symtab->hash_table->put)(symtab->hash_table, &key, &value, 0); // check result if (is_debug()) { DBT rkey, rvalue; char* tmp = (char *)malloc(strlen(symtab->symbols[i].name) + 1); strcpy(tmp, symtab->symbols[i].name); rkey.data = tmp; rkey.size = strlen(tmp) + 1; (*symtab->hash_table->get)(symtab->hash_table, &rkey, &rvalue, 0); // we may get a copy back so compare contents symtab_symbol *res = (symtab_symbol *)rvalue.data; if (strcmp(res->name, symtab->symbols[i].name) || res->offset != symtab->symbols[i].offset || res->size != symtab->symbols[i].size) { print_debug("error to get hash_table value!\n"); } free(tmp); } } }
static void on_extension_removed(PeasExtensionSet *set, PeasPluginInfo *info, PeasExtension *exten, IsApplication *application) { is_debug("main", "Deactivating plugin: %s", peas_plugin_info_get_name(info)); peas_extension_call(exten, "deactivate", application); }
long __declspec(dllexport) WINAPI _is_debug(lprec *lp) { long ret; if (lp != NULL) { freebuferror(); ret = is_debug(lp); } else ret = 0; return(ret); }
static void is_max_plugin_activate(PeasActivatable *activatable) { IsMaxPlugin *self = IS_MAX_PLUGIN(activatable); IsMaxPluginPrivate *priv = self->priv; IsManager *manager; GSList *sensors, *_list; int i = 0; manager = is_application_get_manager(priv->application); // create our virtual sensor which mimics the current highest value sensor's // value and label is_debug("max", "creating virtual sensor"); priv->sensor = is_sensor_new(MAX_SENSOR_PATH); is_sensor_set_label(priv->sensor, "Δ"); is_sensor_set_icon(priv->sensor, IS_STOCK_CHIP); is_sensor_set_value(priv->sensor, 0.0); is_sensor_set_units(priv->sensor, ""); is_sensor_set_digits(priv->sensor, 1); is_manager_add_sensor(manager, priv->sensor); is_debug("max", "attaching to signals"); sensors = is_manager_get_enabled_sensors_list(manager); for (_list = sensors; _list != NULL; _list = _list->next) { IsSensor *sensor = IS_SENSOR(_list->data); on_sensor_enabled(manager, sensor, i, self); g_object_unref(sensor); i++; } g_slist_free(sensors); g_signal_connect(manager, "sensor-enabled", G_CALLBACK(on_sensor_enabled), self); g_signal_connect(manager, "sensor-disabled", G_CALLBACK(on_sensor_disabled), self); }
array<string> compiler_arguments() { array<string> result; //mode if(is_debug()) result.push("-g"); else if(is_release()) { //strip result.push("-s"); //optimisation result.push("-O3"); //architecture //result.push("-march=native"); } else stop(); //tool if(is_asan()) result.push("-fsanitize=address"); else if(is_profiler()) result.push("-lprofiler"); //defines for(int i=0;i<_defines.count();i++) { result.push(concat("-D",_defines[i])); } //warnings //result.push("-pedantic"); result.push("-Wall"); result.push("-Wno-strict-overflow"); return result; }
static void on_sensor_enabled(IsManager *manager, IsSensor *sensor, gint index, gpointer data) { IsMaxPlugin *self = (IsMaxPlugin *)data; // don't bother monitoring non-temperature sensors if (IS_IS_TEMPERATURE_SENSOR(sensor)) { is_debug("max", "sensor enabled: %s", is_sensor_get_label(sensor)); on_sensor_value_notify(sensor, NULL, self); g_signal_connect(sensor, "notify::value", G_CALLBACK(on_sensor_value_notify), self); } }
static void on_sensor_disabled(IsManager *manager, IsSensor *sensor, gpointer data) { IsMaxPlugin *self = (IsMaxPlugin *)data; IsMaxPluginPrivate *priv = self->priv; // don't bother monitoring non-temperature sensors if (IS_IS_TEMPERATURE_SENSOR(sensor)) { is_debug("max", "sensor disabled: %s", is_sensor_get_label(sensor)); g_signal_handlers_disconnect_by_func(sensor, G_CALLBACK(on_sensor_value_notify), self); if (priv->max == sensor) { // get all sensors and find the one with the maximum value and switch to // this GSList *sensors, *_list; priv->max = NULL; priv->max_value = 0.0; is_sensor_set_label(priv->sensor, "Δ"); is_sensor_set_icon(priv->sensor, IS_STOCK_CHIP); is_sensor_set_value(priv->sensor, 0.0); is_sensor_set_units(priv->sensor, ""); is_sensor_set_digits(priv->sensor, 1); sensors = is_manager_get_enabled_sensors_list(manager); for (_list = sensors; _list != NULL; _list = _list->next) { if (IS_IS_TEMPERATURE_SENSOR(_list->data)) { on_sensor_value_notify(IS_SENSOR(_list->data), NULL, self); } } } } }
static void sensor_menu_item_toggled(GtkMenuItem *menu_item, IsIndicator *self) { IsSensor *sensor; gboolean active = FALSE; g_return_if_fail(IS_IS_INDICATOR(self)); /* only set as primary if was toggled to active state since we may have * untoggled it instead */ active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item)); if (active) { sensor = IS_SENSOR(g_object_get_data(G_OBJECT(menu_item), "sensor")); is_debug("indicator", "Sensor %s menu-item toggled to active - setting as primary sensor", is_sensor_get_path(sensor)); is_indicator_set_primary_sensor_path(self, is_sensor_get_path(sensor)); } }
static void on_sensor_value_notify(IsSensor *sensor, GParamSpec *pspec, gpointer user_data) { IsMaxPlugin *self; IsMaxPluginPrivate *priv; gdouble value; self = IS_MAX_PLUGIN(user_data); priv = self->priv; value = is_sensor_get_value(sensor); if (value - IS_SENSOR_VALUE_UNSET <= DBL_EPSILON) { is_debug("max", "sensor value for sensor %s is unset - ignoring", is_sensor_get_label(sensor)); goto exit; } if (value > priv->max_value && sensor != priv->max) { // let's see if we can get away without taking a reference on sensor priv->max = sensor; is_message("max", "New highest value sensor: %s (value %f)", is_sensor_get_label(sensor), value); } if (sensor == priv->max) { priv->max_value = value; update_sensor_from_max(self); } exit: return; }
static void _sensor_disabled(IsSensor *sensor, IsIndicator *self) { IsIndicatorPrivate *priv = self->priv; GtkWidget *menu_item; is_debug("indicator", "disabling sensor %s", is_sensor_get_path(sensor)); /* destroy menu item */ menu_item = GTK_WIDGET(g_object_get_data(G_OBJECT(sensor), "menu-item")); priv->menu_items = g_slist_remove(priv->menu_items, menu_item); gtk_container_remove(GTK_CONTAINER(is_indicator_get_menu(self)), menu_item); g_object_set_data(G_OBJECT(sensor), "menu-item", NULL); g_signal_handlers_disconnect_by_func(sensor, sensor_notify, self); }
int main(int argc,char **argv) { (void)argc; (void)argv; assert(libusb_init(NULL)==0); libusb_set_debug(NULL,3); libusb_device **device_list; ssize_t list_size=libusb_get_device_list(NULL,&device_list); assert(list_size>=0); libusb_device *found = NULL; for(ssize_t i=0;i<list_size;i++) { if(is_debug(device_list[i])) found=device_list[i]; } if(found) { libusb_device_handle *handle; int err = libusb_open(found,&handle); assert(err==0); main_loop(handle); libusb_close(handle); } libusb_free_device_list(device_list,1); libusb_exit(NULL); return 0; }
// we sort map_info by starting virtual address so that we can do // binary search to read from an address. static bool sort_map_array(struct ps_prochandle* ph) { size_t num_maps = ph->core->num_maps; map_info* map = ph->core->maps; int i = 0; // allocate map_array map_info** array; if ( (array = (map_info**) malloc(sizeof(map_info*) * num_maps)) == NULL) { print_debug("can't allocate memory for map array\n"); return false; } // add maps to array while (map) { array[i] = map; i++; map = map->next; } // sort is called twice. If this is second time, clear map array if (ph->core->map_array) free(ph->core->map_array); ph->core->map_array = array; // sort the map_info array by base virtual address. qsort(ph->core->map_array, ph->core->num_maps, sizeof (map_info*), core_cmp_mapping); // print map if (is_debug()) { int j = 0; print_debug("---- sorted virtual address map ----\n"); for (j = 0; j < ph->core->num_maps; j++) { print_debug("base = 0x%lx\tsize = %zu\n", ph->core->map_array[j]->vaddr, ph->core->map_array[j]->memsz); } } return true; }
void Simulator::Process(NMEAInfo &basic) { if (!is_simulator()) return; basic.UpdateClock(); basic.connected.Update(basic.clock); basic.gps.satellites_used = -1; basic.gps.simulator = true; basic.gps.real = false; #ifdef ANDROID basic.gps.android_internal_gps = false; #endif basic.location = FindLatitudeLongitude(basic.location, basic.track, basic.ground_speed); basic.location_available.Update(basic.clock); basic.gps_altitude_available.Update(basic.clock); basic.track_available.Update(basic.clock); basic.ground_speed_available.Update(basic.clock); basic.time_available.Update(basic.clock); basic.time += fixed_one; (BrokenTime &)basic.date_time_utc = BrokenTime::FromSecondOfDayChecked((unsigned)basic.time); // use this to test FLARM parsing/display if (is_debug() && !is_altair()) GenerateFLARMTraffic(basic); // clear Airspeed as it is not available in simulation mode basic.airspeed_available.Clear(); basic.airspeed_real = false; }
void NTAPI check_debug(PVOID DllHandle, DWORD Reason, PVOID Reserved) { is_debug(); }
static void is_udisks_plugin_activate(PeasActivatable *activatable) { IsUdisksPlugin *self = IS_UDISKS_PLUGIN(activatable); IsUdisksPluginPrivate *priv = self->priv; GDBusProxy *proxy; GError *error = NULL; GVariant *container, *paths; GVariantIter iter; gchar *path; priv->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (!priv->connection) { is_warning("udisks", "Failed to open connection to system dbus: %s", error->message); g_error_free(error); goto out; } /* This is the proxy which is only used once during the enumeration of * the device object paths */ proxy = g_dbus_proxy_new_sync(priv->connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, UDISKS_BUS_NAME, UDISKS_OBJECT_PATH, UDISKS_INTERFACE_NAME, NULL, &error); if (!proxy) { is_warning("udisks", "Error getting proxy to udisks on system bus: %s", error->message); g_error_free(error); goto out; } /* The object paths of the disks are enumerated and placed in an array * of object paths */ container = g_dbus_proxy_call_sync(proxy, "EnumerateDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!container) { is_warning("udisks", "Failed to enumerate disk devices: %s", error->message); g_error_free(error); g_object_unref(proxy); goto out; } paths = g_variant_get_child_value(container, 0); g_variant_unref(container); g_variant_iter_init(&iter, paths); while (g_variant_iter_loop(&iter, "o", &path)) { /* This proxy is used to get the required data in order to build * up the list of sensors */ GDBusProxy *sensor_proxy; GVariant *model, *smart_available; IsSensor *sensor; gchar *name, *sensor_path; sensor_proxy = g_dbus_proxy_new_sync(priv->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, UDISKS_BUS_NAME, path, UDISKS_DEVICE_INTERFACE_NAME, NULL, &error); if (!sensor_proxy) { is_debug("udisks", "error getting sensor proxy for disk %s: %s", path, error->message); g_clear_error(&error); g_object_unref(sensor_proxy); continue; } smart_available = g_dbus_proxy_get_cached_property(sensor_proxy, "DriveAtaSmartIsAvailable"); if (!smart_available) { is_debug("udisks", "error getting smart status for disk %s", path); g_object_unref(sensor_proxy); continue; } if (!g_variant_get_boolean(smart_available)) { is_debug("udisks", "drive %s does not support SMART monitoring, ignoring...", path); g_variant_unref(smart_available); g_object_unref(sensor_proxy); continue; } g_variant_unref(smart_available); model = g_dbus_proxy_get_cached_property(sensor_proxy, "DriveModel"); if (!model) { is_debug("udisks", "error getting drive model for disk %s", path); g_clear_error(&error); g_object_unref(sensor_proxy); continue; } name = g_path_get_basename(path); sensor_path = g_strdup_printf("udisks/%s", name); sensor = is_temperature_sensor_new(sensor_path); is_sensor_set_label(sensor, g_variant_get_string(model, NULL)); is_sensor_set_digits(sensor, 0); is_sensor_set_icon(sensor, IS_STOCK_DISK); /* only update every minute to avoid waking disk too much */ is_sensor_set_update_interval(sensor, 60); g_signal_connect(sensor, "update-value", G_CALLBACK(update_sensor_value), self); is_manager_add_sensor(is_application_get_manager(priv->application), sensor); g_free(sensor_path); g_free(name); g_object_unref(sensor); g_object_unref(sensor_proxy); } g_variant_unref(paths); g_object_unref(proxy); out: return; }
static void update_sensor_value(IsTemperatureSensor *sensor, IsUdisksPlugin *self) { IsUdisksPluginPrivate *priv; gchar *device, *path; GDBusProxy *proxy; GVariant *var; GError *error = NULL; SkDisk *sk_disk; const gchar *blob; gsize len; guint64 temperature; gdouble value; priv = self->priv; device = g_path_get_basename(is_sensor_get_path(IS_SENSOR(sensor))); path = g_strdup_printf("%s/devices/%s", UDISKS_OBJECT_PATH, device); proxy = g_dbus_proxy_new_sync(priv->connection, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, UDISKS_BUS_NAME, path, UDISKS_DEVICE_INTERFACE_NAME, NULL, &error); g_free(path); g_free(device); if (!proxy) { g_prefix_error(&error, _("Error reading new SMART data for sensor %s"), is_sensor_get_path(IS_SENSOR(sensor))); is_sensor_emit_error(IS_SENSOR(sensor), error); g_error_free(error); goto out; } /* update smart data */ var = g_variant_new_strv(NULL, 0); var = g_dbus_proxy_call_sync(proxy, "DriveAtaSmartRefreshData", g_variant_new_tuple(&var, 1), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!var) { g_prefix_error(&error, _("Error refreshing SMART data for sensor %s"), is_sensor_get_path(IS_SENSOR(sensor))); is_sensor_emit_error(IS_SENSOR(sensor), error); g_error_free(error); g_object_unref(proxy); goto out; } g_variant_unref(var); var = g_dbus_proxy_get_cached_property(proxy, "DriveAtaSmartBlob"); if (!var) { is_debug("udisks", "unable to get atasmartblob for sensor %s", is_sensor_get_path(IS_SENSOR(sensor))); g_object_unref(proxy); goto out; } g_object_unref(proxy); /* can't unref var until done with blob */ blob = g_variant_get_fixed_array(var, &len, sizeof(gchar)); if (!blob) { /* this can occur if udisks doesn't update immediately, * ignore */ g_variant_unref(var); goto out; } sk_disk_open(NULL, &sk_disk); sk_disk_set_blob(sk_disk, blob, len); if (sk_disk_smart_get_temperature(sk_disk, &temperature) < 0) { is_debug("udisks", "Error getting temperature from AtaSmartBlob for sensor %s", is_sensor_get_path(IS_SENSOR(sensor))); sk_disk_free(sk_disk); g_variant_unref(var); /* TODO: emit error */ goto out; } sk_disk_free(sk_disk); g_variant_unref(var); /* Temperature is in mK, so convert it to K first */ temperature /= 1000; value = (gdouble)temperature - 273.15; is_temperature_sensor_set_celsius_value(sensor, value); out: return; }
// read regs and create thread from NT_PRSTATUS entries from core file static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size_t nbytes) { // we have to read prstatus_t from buf // assert(nbytes == sizeof(prstaus_t), "size mismatch on prstatus_t"); prstatus_t* prstat = (prstatus_t*) buf; thread_info* newthr; print_debug("got integer regset for lwp %d\n", prstat->pr_pid); // we set pthread_t to -1 for core dump if((newthr = add_thread_info(ph, (pthread_t) -1, prstat->pr_pid)) == NULL) return false; // copy regs memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct)); if (is_debug()) { print_debug("integer regset\n"); #ifdef i386 // print the regset print_debug("\teax = 0x%x\n", newthr->regs.eax); print_debug("\tebx = 0x%x\n", newthr->regs.ebx); print_debug("\tecx = 0x%x\n", newthr->regs.ecx); print_debug("\tedx = 0x%x\n", newthr->regs.edx); print_debug("\tesp = 0x%x\n", newthr->regs.esp); print_debug("\tebp = 0x%x\n", newthr->regs.ebp); print_debug("\tesi = 0x%x\n", newthr->regs.esi); print_debug("\tedi = 0x%x\n", newthr->regs.edi); print_debug("\teip = 0x%x\n", newthr->regs.eip); #endif #if defined(amd64) || defined(x86_64) // print the regset print_debug("\tr15 = 0x%lx\n", newthr->regs.r15); print_debug("\tr14 = 0x%lx\n", newthr->regs.r14); print_debug("\tr13 = 0x%lx\n", newthr->regs.r13); print_debug("\tr12 = 0x%lx\n", newthr->regs.r12); print_debug("\trbp = 0x%lx\n", newthr->regs.rbp); print_debug("\trbx = 0x%lx\n", newthr->regs.rbx); print_debug("\tr11 = 0x%lx\n", newthr->regs.r11); print_debug("\tr10 = 0x%lx\n", newthr->regs.r10); print_debug("\tr9 = 0x%lx\n", newthr->regs.r9); print_debug("\tr8 = 0x%lx\n", newthr->regs.r8); print_debug("\trax = 0x%lx\n", newthr->regs.rax); print_debug("\trcx = 0x%lx\n", newthr->regs.rcx); print_debug("\trdx = 0x%lx\n", newthr->regs.rdx); print_debug("\trsi = 0x%lx\n", newthr->regs.rsi); print_debug("\trdi = 0x%lx\n", newthr->regs.rdi); print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax); print_debug("\trip = 0x%lx\n", newthr->regs.rip); print_debug("\tcs = 0x%lx\n", newthr->regs.cs); print_debug("\teflags = 0x%lx\n", newthr->regs.eflags); print_debug("\trsp = 0x%lx\n", newthr->regs.rsp); print_debug("\tss = 0x%lx\n", newthr->regs.ss); print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base); print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base); print_debug("\tds = 0x%lx\n", newthr->regs.ds); print_debug("\tes = 0x%lx\n", newthr->regs.es); print_debug("\tfs = 0x%lx\n", newthr->regs.fs); print_debug("\tgs = 0x%lx\n", newthr->regs.gs); #endif } return true; }
static void is_aticonfig_plugin_activate(PeasActivatable *activatable) { IsATIConfigPlugin *self = IS_ATICONFIG_PLUGIN(activatable); IsManager *manager; gchar *output = NULL; GError *error = NULL; GRegex *regex = NULL; GMatchInfo *match = NULL; gboolean ret; manager = is_application_get_manager(self->priv->application); /* search for sensors and add them to manager */ is_debug("aticonfig", "searching for sensors"); /* call aticonfig with --list-adapters to get available adapters, * then test if each can do temperature and fan speed - if so add * appropriate sensors */ ret = g_spawn_command_line_sync("aticonfig --list-adapters", &output, NULL, NULL, &error); if (!ret) { is_warning("aticonfig", "Error calling aticonfig to detect available sensors: %s", error->message); g_error_free(error); goto out; } regex = g_regex_new("^.*([0-9]+)\\. ([0-9][0-9]:[0-9][0-9]\\.[0-9])\\s*(.*?)\\s*$", G_REGEX_MULTILINE, 0, &error); if (!regex) { is_warning("aticonfig", "Error compiling regex to detect listed sensors: %s", error->message); g_error_free(error); goto out; } ret = g_regex_match(regex, output, 0, &match); if (!ret) { is_warning("aticonfig", "No sensors found in aticonfig output: %s", output); goto out; } while (g_match_info_matches(match)) { gint i; gchar *idx, *pci, *name; gdouble value; gchar *path; IsSensor *sensor; idx = g_match_info_fetch(match, 1); pci = g_match_info_fetch(match, 2); name = g_match_info_fetch(match, 3); i = g_ascii_strtoull(idx, NULL, 10); /* we have an adapter - see if we can get its temperature and fanspeed */ ret = aticonfig_get_temperature(self, i, &value, &error); if (!ret) { is_warning("aticonfig", "Error getting temperature for adapter %d: %s", i, error->message); g_clear_error(&error); } else { path = g_strdup_printf("%s%d%s", ATICONFIG_PATH_PREFIX, i, _("Temperature")); sensor = is_temperature_sensor_new(path); is_sensor_set_label(sensor, name); is_sensor_set_icon(sensor, IS_STOCK_GPU); g_signal_connect(sensor, "update-value", G_CALLBACK(update_sensor_value), self); is_manager_add_sensor(manager, sensor); g_object_unref(sensor); g_free(path); } ret = aticonfig_get_fanspeed(self, i, &value, &error); if (!ret) { is_warning("aticonfig", "Error getting fanpeed for adapter %d: %s", i, error->message); g_clear_error(&error); } else { path = g_strdup_printf("%s%d%s", ATICONFIG_PATH_PREFIX, i, _("Fan")); sensor = is_sensor_new(path); is_sensor_set_label(sensor, name); /* fan sensors are given as a percentage from 0 to 100 */ is_sensor_set_units(sensor, "%"); is_sensor_set_low_value(sensor, 0.0); is_sensor_set_high_value(sensor, 100.0); is_sensor_set_digits(sensor, 0); is_sensor_set_icon(sensor, IS_STOCK_FAN); g_signal_connect(sensor, "update-value", G_CALLBACK(update_sensor_value), self); is_manager_add_sensor(manager, sensor); g_object_unref(sensor); g_free(path); } g_free(idx); g_free(pci); g_free(name); g_match_info_next(match, &error); } out: g_match_info_free(match); if (regex) { g_regex_unref(regex); } g_free(output); return; }
static void sensor_enabled(IsManager *manager, IsSensor *sensor, gint position, IsIndicator *self) { IsIndicatorPrivate *priv = self->priv; /* make sure we haven't seen this sensor before - if sensor has a * menu-item then ignore it */ if (!g_object_get_data(G_OBJECT(sensor), "menu-item")) { GtkMenu *menu; GtkWidget *menu_item; is_debug("indicator", "Creating menu item for newly enabled sensor %s", is_sensor_get_path(sensor)); g_signal_connect(sensor, "notify::value", G_CALLBACK(sensor_notify), self); g_signal_connect(sensor, "notify::label", G_CALLBACK(sensor_notify), self); g_signal_connect(sensor, "notify::alarmed", G_CALLBACK(sensor_notify), self); g_signal_connect(sensor, "notify::low-value", G_CALLBACK(sensor_notify), self); g_signal_connect(sensor, "notify::high-value", G_CALLBACK(sensor_notify), self); /* add a menu entry for this sensor */ menu = is_indicator_get_menu(self); menu_item = gtk_check_menu_item_new(); gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(menu_item), TRUE); g_object_set_data(G_OBJECT(sensor), "menu-item", menu_item); g_object_set_data(G_OBJECT(menu_item), "sensor", sensor); priv->menu_items = g_slist_insert(priv->menu_items, menu_item, position); /* if we haven't seen our primary sensor yet or if this is the * primary sensor, display this as primary anyway */ if (!priv->primary || g_strcmp0(is_sensor_get_path(sensor), priv->primary_sensor_path) == 0) { is_debug("indicator", "Using sensor with path %s as primary", is_sensor_get_path(sensor)); if (priv->primary) { GtkCheckMenuItem *item; /* uncheck menu item if exists for this * existing primary sensor */ item = (GtkCheckMenuItem *)(g_object_get_data(G_OBJECT(priv->primary), "menu-item")); if (item) { is_debug("indicator", "Unchecking current primary sensor item"); gtk_check_menu_item_set_active(item, FALSE); } g_object_unref(priv->primary); } priv->primary = g_object_ref(sensor); is_debug("indicator", "Checking new primary sensor item"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), TRUE); update_sensor_menu_item_label(self, sensor, GTK_MENU_ITEM(menu_item)); } /* connect to toggled signal now - if we connect to it earlier * we may interpret the above menu_item_set_active as a user * initiated setting of the primary sensor rather than us just * picking the first available sensor */ g_signal_connect(menu_item, "toggled", G_CALLBACK(sensor_menu_item_toggled), self); gtk_widget_show_all(menu_item); update_sensor_menu_item_label(self, sensor, GTK_MENU_ITEM(menu_item)); gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menu_item, position); } else { is_debug("indicator", "Newly enabled sensor %s already has a menu-item, ignoring...", is_sensor_get_path(sensor)); } }
static void on_sensor_value_notify(IsSensor *sensor, GParamSpec *pspec, gpointer user_data) { IsDynamicPlugin *self; IsDynamicPluginPrivate *priv; RateData *data; gdouble value, dv, dt, rate; gint64 now; self = IS_DYNAMIC_PLUGIN(user_data); priv = self->priv; value = is_sensor_get_value(sensor); if (value - IS_SENSOR_VALUE_UNSET <= DBL_EPSILON) { is_debug("dynamic", "sensor value for sensor %s is unset - ignoring", is_sensor_get_label(sensor)); goto exit; } now = g_get_monotonic_time(); data = g_object_get_data(G_OBJECT(sensor), DYNAMIC_RATE_DATA_KEY); if (data == NULL) { is_debug("dynamic", "Creating new dynamic rate data for sensor: %s", is_sensor_get_label(sensor)); // allocate data data = g_malloc0(sizeof(*data)); data->rate = 0.0f; data->last_value = value; data->last_time = now; g_object_set_data_full(G_OBJECT(sensor), DYNAMIC_RATE_DATA_KEY, data, g_free); goto exit; } is_debug("dynamic", "Got existing rate data for sensor: %s - rate: %f, last_value %f, last_time %"PRId64"", is_sensor_get_label(sensor), data->rate, data->last_value, data->last_time); dv = value - data->last_value; dt = ((double)(now - data->last_time) / (double)G_USEC_PER_SEC); // convert rate to units per second rate = fabs(dv / dt); is_debug("dynamic", "abs rate of change of sensor %s: %f (t0: %f, t-1: %f, dv: %f, dt: %f)", is_sensor_get_label(sensor), rate, value, data->last_value, dv, dt); // calculate exponentially weighted moving average of rate rate = (EWMA_ALPHA * rate) + ((1 - EWMA_ALPHA) * data->rate); data->rate = rate; data->last_value = value; data->last_time = now; is_debug("dynamic", "EWMA abs rate of change of sensor %s: %f", is_sensor_get_label(sensor), rate); if (rate > priv->max_rate && sensor != priv->max) { // let's see if we can get away without taking a reference on sensor priv->max = sensor; is_message("dynamic", "New highest EWMA rate sensor: %s (rate %f)", is_sensor_get_label(sensor), rate); } if (sensor == priv->max) { priv->max_rate = rate; update_sensor_from_max(self); } exit: return; }
static void is_nvidia_plugin_activate(PeasActivatable *activatable) { IsNvidiaPlugin *self = IS_NVIDIA_PLUGIN(activatable); IsNvidiaPluginPrivate *priv = self->priv; Bool ret; int event_base, error_base; gint n; int i; /* search for sensors and add them to manager */ if (!priv->inited) { is_warning("nvidia", "not inited, unable to find sensors"); goto out; } is_debug("nvidia", "searching for sensors"); /* check if the NV-CONTROL extension is available on this X * server */ ret = XNVCTRLQueryExtension(priv->display, &event_base, &error_base); if (!ret) { goto out; } /* get number of GPUs, then for each GPU get any thermal_sensors and coolers used by it */ ret = XNVCTRLQueryTargetCount(priv->display, NV_CTRL_TARGET_TYPE_GPU, &n); if (!ret) { goto out; } for (i = 0; i < n; i++) { guint j; char *label = NULL; ret = XNVCTRLQueryTargetStringAttribute(priv->display, NV_CTRL_TARGET_TYPE_GPU, i, 0, NV_CTRL_STRING_PRODUCT_NAME, &label); for (j = 0; j < G_N_ELEMENTS(map); j++) { int32_t *data; int len; int k; ret = XNVCTRLQueryTargetBinaryData(priv->display, NV_CTRL_TARGET_TYPE_GPU, i, 0, map[j].gpu_attribute, (unsigned char **)&data, &len); if (!ret) { continue; } /* data[0] contains number of sensors, and each sensor indice follows */ for (k = 1; k <= data[0]; k++) { int idx = data[k]; gint value; IsSensor *sensor; gchar *path; ret = XNVCTRLQueryTargetAttribute(priv->display, map[j].target, idx, 0, map[j].attribute, &value); if (!ret) { continue; } path = g_strdup_printf("nvidia/%s%d", map[j].description, idx); if (map[j].target == NV_CTRL_TARGET_TYPE_COOLER) { /* fan sensors are given as a percentage from 0 to 100 */ sensor = is_sensor_new(path); is_sensor_set_icon(sensor, IS_STOCK_FAN); is_sensor_set_units(sensor, "%"); is_sensor_set_low_value(sensor, 0.0); is_sensor_set_high_value(sensor, 100.0); } else { sensor = is_temperature_sensor_new(path); is_sensor_set_icon(sensor, IS_STOCK_GPU); } /* no decimal places to display */ is_sensor_set_digits(sensor, 0); is_sensor_set_label(sensor, label); /* connect to update-value signal */ g_signal_connect(sensor, "update-value", G_CALLBACK(update_sensor_value), self); is_manager_add_sensor(is_application_get_manager(priv->application), sensor); g_free(path); } free(data); } free(label); } out: return; }
gboolean is_store_add_sensor(IsStore *self, IsSensor *sensor, GtkTreeIter *iter) { IsStorePrivate *priv; GSequence *entries; IsStoreEntry *entry = NULL; GSequenceIter *parent = NULL; gchar **names = NULL; int i; GtkTreePath *path; GtkTreeIter _iter; gboolean ret = FALSE; g_return_val_if_fail(IS_IS_STORE(self), FALSE); g_return_val_if_fail(IS_IS_SENSOR(sensor), FALSE); priv = self->priv; entry = find_entry(self, is_sensor_get_path(sensor)); if (entry) { is_warning("store", "sensor %s already exists in store, not adding duplicate", is_sensor_get_path(sensor)); goto out; } entries = priv->entries; names = g_strsplit(is_sensor_get_path(sensor), "/", 0); /* otherwise iterate through to create the entry */ for (i = 0; names[i] != NULL; i++) { GSequenceIter *seq_iter; gchar *name = names[i]; entry = NULL; for (seq_iter = g_sequence_get_begin_iter(entries); !g_sequence_iter_is_end(seq_iter); seq_iter = g_sequence_iter_next(seq_iter)) { entry = (IsStoreEntry *)g_sequence_get(seq_iter); if (g_strcmp0(entry->name, name) == 0) { entries = entry->entries; parent = seq_iter; break; } entry = NULL; } if (!entry) { /* create entry for this name component */ entry = entry_new(name); entry->iter = g_sequence_append(entries, entry); entry->parent = parent; entries = entry->entries; _iter.stamp = priv->stamp; _iter.user_data = entry->iter; path = gtk_tree_model_get_path(GTK_TREE_MODEL(self), &_iter); gtk_tree_model_row_inserted(GTK_TREE_MODEL(self), path, &_iter); gtk_tree_path_free(path); /* parent of the next entry we create will be this * entry */ parent = entry->iter; } } g_strfreev(names); g_assert(entry); g_assert(find_entry(self, is_sensor_get_path(sensor)) == entry); is_debug("store", "inserted sensor %s with label %s", is_sensor_get_path(sensor), is_sensor_get_label(sensor)); entry->sensor = g_object_ref(sensor); _iter.stamp = priv->stamp; _iter.user_data = entry->iter; path = gtk_tree_model_get_path(GTK_TREE_MODEL(self), &_iter); gtk_tree_model_row_changed(GTK_TREE_MODEL(self), path, &_iter); gtk_tree_path_free(path); /* return a copy of iter */ if (iter != NULL) { iter->stamp = priv->stamp; iter->user_data = entry->iter; } ret = TRUE; out: return ret; }