/** * a_layer_defaults_show_window: * @parent: The Window * @layername: The layer * * This displays a Window showing the default parameter values for the selected layer * It allows the parameters to be changed. * * Returns: %TRUE if the window is displayed (because there are parameters to view) */ gboolean a_layer_defaults_show_window ( GtkWindow *parent, const gchar *layername ) { if ( ! loaded ) { // since we can't load the file in a_defaults_init (no params registered yet), // do it once before we display the params. defaults_load_from_file(); loaded = TRUE; } VikLayerTypeEnum layer = vik_layer_type_from_string ( layername ); // Need to know where the params start and they finish for this layer // 1. inspect every registered param - see if it has the layer value required to determine overall size // [they are contiguous from the start index] // 2. copy the these params from the main list into a tmp struct // // Then pass this tmp struct to uibuilder for display guint layer_params_count = 0; gboolean found_first = FALSE; gint index = 0; int i; for ( i = 0; i < paramsVD->len; i++ ) { VikLayerParam *param = (VikLayerParam*)(g_ptr_array_index(paramsVD,i)); if ( param->layer == layer ) { layer_params_count++; if ( !found_first ) { index = i; found_first = TRUE; } } } // Have we any parameters to show! if ( !layer_params_count ) return FALSE; VikLayerParam *params = g_new(VikLayerParam,layer_params_count); for ( i = 0; i < layer_params_count; i++ ) { params[i] = *((VikLayerParam*)(g_ptr_array_index(paramsVD,i+index))); } gchar *title = g_strconcat ( layername, ": ", _("Layer Defaults"), NULL ); if ( a_uibuilder_properties_factory ( title, parent, params, layer_params_count, vik_layer_get_interface(layer)->params_groups, vik_layer_get_interface(layer)->params_groups_count, (gboolean (*) (gpointer,guint16,VikLayerParamData,gpointer,gboolean)) defaults_run_setparam, GINT_TO_POINTER ( index ), params, defaults_run_getparam, GINT_TO_POINTER ( index ) ) ) { // Save layer_defaults_save_to_file(); } g_free ( title ); g_free ( params ); return TRUE; }
static gboolean _pygi_closure_set_out_arguments (PyGIInvokeState *state, PyGICallableCache *cache, PyObject *py_retval, void *resp) { gssize i; gssize i_py_retval = 0; gboolean success; if (cache->return_cache->type_tag != GI_TYPE_TAG_VOID) { PyObject *item = py_retval; if (PyTuple_Check (py_retval)) { item = PyTuple_GET_ITEM (py_retval, 0); } success = cache->return_cache->from_py_marshaller (state, cache, cache->return_cache, item, &state->return_arg, &state->args[0].arg_cleanup_data); if (!success) { pygi_marshal_cleanup_args_return_fail (state, cache); return FALSE; } _pygi_closure_assign_pyobj_to_retval (resp, &state->return_arg, cache->return_cache); i_py_retval++; } for (i = 0; i < _pygi_callable_cache_args_len (cache); i++) { PyGIArgCache *arg_cache = g_ptr_array_index (cache->args_cache, i); if (arg_cache->direction & PYGI_DIRECTION_FROM_PYTHON) { PyObject *item = py_retval; if (arg_cache->type_tag == GI_TYPE_TAG_ERROR) { * (GError **) state->args[i].arg_pointer.v_pointer = NULL; continue; } if (PyTuple_Check (py_retval)) { item = PyTuple_GET_ITEM (py_retval, i_py_retval); } else if (i_py_retval != 0) { pygi_marshal_cleanup_args_to_py_parameter_fail (state, cache, i_py_retval); return FALSE; } success = arg_cache->from_py_marshaller (state, cache, arg_cache, item, &state->args[i].arg_value, &state->args[i_py_retval].arg_cleanup_data); if (!success) { pygi_marshal_cleanup_args_to_py_parameter_fail (state, cache, i_py_retval); return FALSE; } _pygi_closure_assign_pyobj_to_out_argument (state->args[i].arg_pointer.v_pointer, &state->args[i].arg_value, arg_cache); i_py_retval++; } } return TRUE; }
static void ensure_cleanedup (void) { if (status == STATUS_NOT_INITIALIZED && InterlockedCompareExchange (&status, STATUS_CLEANED_UP, STATUS_NOT_INITIALIZED) == STATUS_NOT_INITIALIZED) return; if (status == STATUS_INITIALIZING) { while (status == STATUS_INITIALIZING) mono_thread_info_yield (); } if (status == STATUS_CLEANED_UP) return; if (status == STATUS_CLEANING_UP || InterlockedCompareExchange (&status, STATUS_CLEANING_UP, STATUS_INITIALIZED) != STATUS_INITIALIZED) { while (status == STATUS_CLEANING_UP) mono_thread_info_yield (); g_assert (status == STATUS_CLEANED_UP); return; } /* we make the assumption along the code that we are * cleaning up only if the runtime is shutting down */ g_assert (mono_runtime_is_shutting_down ()); /* Unpark all worker threads */ mono_mutex_lock (&threadpool->parked_threads_lock); for (;;) { guint i; ThreadPoolCounter counter = COUNTER_READ (); if (counter._.active == 0 && counter._.parked == 0) break; if (counter._.active == 1) { MonoInternalThread *thread = mono_thread_internal_current (); if (thread->threadpool_thread) { /* if there is only one active thread * left and it's the current one */ break; } } for (i = 0; i < threadpool->parked_threads->len; ++i) { mono_cond_t *cond = (mono_cond_t*) g_ptr_array_index (threadpool->parked_threads, i); mono_cond_signal (cond); } mono_mutex_unlock (&threadpool->parked_threads_lock); usleep (1000); mono_mutex_lock (&threadpool->parked_threads_lock); } mono_mutex_unlock (&threadpool->parked_threads_lock); while (monitor_status != MONITOR_STATUS_NOT_RUNNING) usleep (1000); g_ptr_array_free (threadpool->domains, TRUE); mono_mutex_destroy (&threadpool->domains_lock); g_ptr_array_free (threadpool->parked_threads, TRUE); mono_mutex_destroy (&threadpool->parked_threads_lock); g_ptr_array_free (threadpool->working_threads, TRUE); mono_mutex_destroy (&threadpool->working_threads_lock); mono_mutex_destroy (&threadpool->heuristic_lock); g_free (threadpool->heuristic_hill_climbing.samples); g_free (threadpool->heuristic_hill_climbing.thread_counts); rand_free (threadpool->heuristic_hill_climbing.random_interval_generator); g_free (threadpool->cpu_usage_state); g_assert (threadpool); g_free (threadpool); threadpool = NULL; g_assert (!threadpool); status = STATUS_CLEANED_UP; }
static void admin_print_all_backend_cons( chassis* srv ) { GPtrArray* cons; guint i; network_mysqld_con* con; guint invalid_cnt = 0; guint valid_cnt = 0; gchar* state_str[] = { "CON_STATE_INIT", "CON_STATE_CONNECT_SERVER", "CON_STATE_READ_HANDSHAKE", "CON_STATE_SEND_HANDSHAKE", "CON_STATE_READ_AUTH", "CON_STATE_SEND_AUTH", "CON_STATE_READ_AUTH_RESULT", "CON_STATE_SEND_AUTH_RESULT", "CON_STATE_READ_AUTH_OLD_PASSWORD", "CON_STATE_SEND_AUTH_OLD_PASSWORD", "CON_STATE_READ_QUERY", "CON_STATE_SEND_QUERY", "CON_STATE_READ_QUERY_RESULT", "CON_STATE_SEND_QUERY_RESULT", "CON_STATE_CLOSE_CLIENT", "CON_STATE_SEND_ERROR", "CON_STATE_ERROR", "CON_STATE_CLOSE_SERVER = 17", "CON_STATE_READ_LOCAL_INFILE_DATA", "CON_STATE_SEND_LOCAL_INFILE_DATA", "CON_STATE_READ_LOCAL_INFILE_RESULT", "CON_STATE_SEND_LOCAL_INFILE_RESULT", }; cons = srv->priv->cons; g_message("admin_print_all_backend_cons start..."); g_mutex_lock(srv->priv->cons_mutex); for (i = 0; i < cons->len; ++i) { con = g_ptr_array_index(cons, i); if (con->server && con->server->backend_idx != -1) { if (con->server->disconnect_flag) { invalid_cnt ++; g_message("invalid connection: server: %s/%d, client : %s/%d, state : %s", con->server->dst->name->str, con->server->fd, con->client->src->name->str, con->client->fd, state_str[con->state]); } else { valid_cnt ++; g_message("valid connection: server: %s/%d, client : %s/%d, state : %s", con->server->dst->name->str, con->server->fd, con->client->src->name->str, con->client->fd, state_str[con->state]); } } } g_message("admin_print_all_backend_cons end... connections cnt : %d, invalid cnt : %d, valid cnt %d", cons->len, invalid_cnt, valid_cnt); g_mutex_unlock(srv->priv->cons_mutex); }
static void _pygi_closure_convert_ffi_arguments (PyGIInvokeArgState *state, PyGICallableCache *cache, void **args) { gint i; for (i = 0; i < _pygi_callable_cache_args_len (cache); i++) { PyGIArgCache *arg_cache = g_ptr_array_index (cache->args_cache, i); if (arg_cache->direction & PYGI_DIRECTION_FROM_PYTHON) { state[i].arg_value.v_pointer = * (gpointer *) args[i]; if (state[i].arg_value.v_pointer == NULL) continue; state[i].arg_pointer.v_pointer = state[i].arg_value.v_pointer; state[i].arg_value = *(GIArgument *) state[i].arg_value.v_pointer; continue; } switch (arg_cache->type_tag) { case GI_TYPE_TAG_BOOLEAN: state[i].arg_value.v_boolean = * (gboolean *) args[i]; break; case GI_TYPE_TAG_INT8: state[i].arg_value.v_int8 = * (gint8 *) args[i]; break; case GI_TYPE_TAG_UINT8: state[i].arg_value.v_uint8 = * (guint8 *) args[i]; break; case GI_TYPE_TAG_INT16: state[i].arg_value.v_int16 = * (gint16 *) args[i]; break; case GI_TYPE_TAG_UINT16: state[i].arg_value.v_uint16 = * (guint16 *) args[i]; break; case GI_TYPE_TAG_INT32: state[i].arg_value.v_int32 = * (gint32 *) args[i]; break; case GI_TYPE_TAG_UINT32: state[i].arg_value.v_uint32 = * (guint32 *) args[i]; break; case GI_TYPE_TAG_INT64: state[i].arg_value.v_int64 = * (glong *) args[i]; break; case GI_TYPE_TAG_UINT64: state[i].arg_value.v_uint64 = * (glong *) args[i]; break; case GI_TYPE_TAG_FLOAT: state[i].arg_value.v_float = * (gfloat *) args[i]; break; case GI_TYPE_TAG_DOUBLE: state[i].arg_value.v_double = * (gdouble *) args[i]; break; case GI_TYPE_TAG_UTF8: state[i].arg_value.v_string = * (gchar **) args[i]; break; case GI_TYPE_TAG_INTERFACE: { GIBaseInfo *interface; GIInfoType interface_type; interface = ((PyGIInterfaceCache *) arg_cache)->interface_info; interface_type = g_base_info_get_type (interface); if (interface_type == GI_INFO_TYPE_ENUM) { state[i].arg_value.v_int = * (gint *) args[i]; } else if (interface_type == GI_INFO_TYPE_FLAGS) { state[i].arg_value.v_uint = * (guint *) args[i]; } else { state[i].arg_value.v_pointer = * (gpointer *) args[i]; } break; } case GI_TYPE_TAG_ERROR: case GI_TYPE_TAG_GHASH: case GI_TYPE_TAG_GLIST: case GI_TYPE_TAG_GSLIST: case GI_TYPE_TAG_ARRAY: case GI_TYPE_TAG_VOID: state[i].arg_value.v_pointer = * (gpointer *) args[i]; break; default: g_warning ("Unhandled type tag %s", g_type_tag_to_string (arg_cache->type_tag)); state[i].arg_value.v_pointer = 0; } } if (cache->throws) { gssize error_index = _pygi_callable_cache_args_len (cache); state[error_index].arg_value.v_pointer = * (gpointer *) args[error_index]; } }
void stf_preview_set_lines (RenderData_t *renderdata, GStringChunk *lines_chunk, GPtrArray *lines) { unsigned int i; int colcount = 1; GnumericLazyList *ll; gboolean hidden; g_return_if_fail (renderdata != NULL); /* Empty the table. */ gtk_tree_view_set_model (renderdata->tree_view, NULL); if (renderdata->lines != lines) { if (renderdata->lines) stf_parse_general_free (renderdata->lines); renderdata->lines = lines; } if (renderdata->lines_chunk != lines_chunk) { if (renderdata->lines_chunk) g_string_chunk_free (renderdata->lines_chunk); renderdata->lines_chunk = lines_chunk; } if (lines == NULL) return; for (i = 0; i < lines->len; i++) { GPtrArray *line = g_ptr_array_index (lines, i); colcount = MAX (colcount, (int)line->len); } /* * If we are making large changes we need to hide the treeview * because performance otherwise suffers a lot. */ hidden = gtk_widget_get_visible (GTK_WIDGET (renderdata->tree_view)) && (colcount < renderdata->colcount - 1 || colcount > renderdata->colcount + 10); if (hidden) gtk_widget_hide (GTK_WIDGET (renderdata->tree_view)); while (renderdata->colcount > colcount) gtk_tree_view_remove_column (renderdata->tree_view, gtk_tree_view_get_column (renderdata->tree_view, --(renderdata->colcount))); while (renderdata->colcount < colcount) { char *text = g_strdup_printf (_(COLUMN_CAPTION), renderdata->colcount + 1); GtkCellRenderer *cell = gtk_cell_renderer_text_new (); GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes (text, cell, "text", renderdata->colcount, NULL); g_object_set (cell, "single_paragraph_mode", TRUE, NULL); gtk_tree_view_append_column (renderdata->tree_view, column); g_free (text); renderdata->colcount++; } ll = gnumeric_lazy_list_new (render_get_value, renderdata, MIN (lines->len, LINE_DISPLAY_LIMIT), 0); gnumeric_lazy_list_add_column (ll, colcount, G_TYPE_STRING); gtk_tree_view_set_model (renderdata->tree_view, GTK_TREE_MODEL (ll)); g_object_unref (ll); if (hidden) gtk_widget_show (GTK_WIDGET (renderdata->tree_view)); }
void dfvm_dump(FILE *f, dfilter_t *df) { int id, length; dfvm_insn_t *insn; dfvm_value_t *arg1; dfvm_value_t *arg2; dfvm_value_t *arg3; dfvm_value_t *arg4; char *value_str; GSList *range_list; drange_node *range_item; /* First dump the constant initializations */ fprintf(f, "Constants:\n"); length = df->consts->len; for (id = 0; id < length; id++) { insn = (dfvm_insn_t *)g_ptr_array_index(df->consts, id); arg1 = insn->arg1; arg2 = insn->arg2; switch (insn->op) { case PUT_FVALUE: value_str = fvalue_to_string_repr(arg1->value.fvalue, FTREPR_DFILTER, NULL); fprintf(f, "%05d PUT_FVALUE\t%s <%s> -> reg#%u\n", id, value_str, fvalue_type_name(arg1->value.fvalue), arg2->value.numeric); g_free(value_str); break; case CHECK_EXISTS: case READ_TREE: case CALL_FUNCTION: case MK_RANGE: case ANY_EQ: case ANY_NE: case ANY_GT: case ANY_GE: case ANY_LT: case ANY_LE: case ANY_BITWISE_AND: case ANY_CONTAINS: case ANY_MATCHES: case NOT: case RETURN: case IF_TRUE_GOTO: case IF_FALSE_GOTO: default: g_assert_not_reached(); break; } } fprintf(f, "\nInstructions:\n"); /* Now dump the operations */ length = df->insns->len; for (id = 0; id < length; id++) { insn = (dfvm_insn_t *)g_ptr_array_index(df->insns, id); arg1 = insn->arg1; arg2 = insn->arg2; arg3 = insn->arg3; arg4 = insn->arg4; switch (insn->op) { case CHECK_EXISTS: fprintf(f, "%05d CHECK_EXISTS\t%s\n", id, arg1->value.hfinfo->abbrev); break; case READ_TREE: fprintf(f, "%05d READ_TREE\t\t%s -> reg#%u\n", id, arg1->value.hfinfo->abbrev, arg2->value.numeric); break; case CALL_FUNCTION: fprintf(f, "%05d CALL_FUNCTION\t%s (", id, arg1->value.funcdef->name); if (arg3) { fprintf(f, "reg#%u", arg3->value.numeric); } if (arg4) { fprintf(f, ", reg#%u", arg4->value.numeric); } fprintf(f, ") --> reg#%u\n", arg2->value.numeric); break; case PUT_FVALUE: /* We already dumped these */ g_assert_not_reached(); break; case MK_RANGE: arg3 = insn->arg3; fprintf(f, "%05d MK_RANGE\t\treg#%u[", id, arg1->value.numeric); for (range_list = arg3->value.drange->range_list; range_list != NULL; range_list = range_list->next) { range_item = (drange_node *)range_list->data; switch (range_item->ending) { case DRANGE_NODE_END_T_UNINITIALIZED: fprintf(f, "?"); break; case DRANGE_NODE_END_T_LENGTH: fprintf(f, "%d:%d", range_item->start_offset, range_item->length); break; case DRANGE_NODE_END_T_OFFSET: fprintf(f, "%d-%d", range_item->start_offset, range_item->end_offset); break; case DRANGE_NODE_END_T_TO_THE_END: fprintf(f, "%d:", range_item->start_offset); break; } if (range_list->next != NULL) fprintf(f, ","); } fprintf(f, "] -> reg#%u\n", arg2->value.numeric); break; case ANY_EQ: fprintf(f, "%05d ANY_EQ\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_NE: fprintf(f, "%05d ANY_NE\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_GT: fprintf(f, "%05d ANY_GT\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_GE: fprintf(f, "%05d ANY_GE\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_LT: fprintf(f, "%05d ANY_LT\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_LE: fprintf(f, "%05d ANY_LE\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_BITWISE_AND: fprintf(f, "%05d ANY_BITWISE_AND\t\treg#%u == reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_CONTAINS: fprintf(f, "%05d ANY_CONTAINS\treg#%u contains reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case ANY_MATCHES: fprintf(f, "%05d ANY_MATCHES\treg#%u matches reg#%u\n", id, arg1->value.numeric, arg2->value.numeric); break; case NOT: fprintf(f, "%05d NOT\n", id); break; case RETURN: fprintf(f, "%05d RETURN\n", id); break; case IF_TRUE_GOTO: fprintf(f, "%05d IF-TRUE-GOTO\t%d\n", id, arg1->value.numeric); break; case IF_FALSE_GOTO: fprintf(f, "%05d IF-FALSE-GOTO\t%d\n", id, arg1->value.numeric); break; default: g_assert_not_reached(); break; } } }
void sim_debug_print_backlogs_data (GPtrArray * backlogs, GIOChannel *channel) { guint i; SimDirective *backlog; gchar * timestamp, *buff; SimRule *rule; for (i = 0; i < backlogs->len; i++) { backlog = (SimDirective*) g_ptr_array_index (backlogs, i); g_io_channel_write_chars(channel,"===========================================================\n",-1,NULL,NULL); buff = g_strdup_printf("Directive_id=%d\n", sim_directive_get_id(backlog)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("Backlog_id=%s\n", sim_directive_get_backlog_id_str(backlog)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("Directive Name=%s\n", sim_directive_get_name(backlog)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("Priority=%d\n", sim_directive_get_priority(backlog)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("Matched=%d\n", sim_directive_backlog_get_matched(backlog)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("Is time out=%d\n", sim_directive_backlog_time_out(backlog)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); timestamp = g_new0 (gchar, 26); time_t backlog_timelast = sim_directive_get_time_last(backlog); strftime (timestamp, TIMEBUF_SIZE, "%Y-%m-%d %H:%M:%S", localtime ((time_t*)&backlog_timelast)); buff = g_strdup_printf("time_last=%s\n", timestamp); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(timestamp); g_free(buff); timestamp = g_new0 (gchar, 26); time_t backlog_timeout = backlog_timelast + sim_directive_get_time_out(backlog); strftime (timestamp, TIMEBUF_SIZE, "%Y-%m-%d %H:%M:%S", localtime ((time_t*)&backlog_timeout)); buff = g_strdup_printf("time_out=%s\n", timestamp); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(timestamp); g_free(buff); rule = sim_directive_get_root_rule (backlog); if(rule) { g_io_channel_write_chars(channel,"Current Rule:\n",-1,NULL,NULL); buff = g_strdup_printf("\t name=%s\n", sim_rule_get_name(rule)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("\t level=%d\n", sim_rule_get_level(rule)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("\t reliability=%d\n", sim_rule_get_reliability(rule)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); timestamp = g_new0 (gchar, 26); time_t rule_timelast = sim_rule_get_time_last(rule); strftime (timestamp, TIMEBUF_SIZE, "%Y-%m-%d %H:%M:%S", localtime ((time_t*)&rule_timelast)); buff = g_strdup_printf("\ttime_last=%s\n", timestamp); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(timestamp); g_free(buff); timestamp = g_new0 (gchar, 26); time_t rule_timeout = rule_timelast + sim_rule_get_time_out(rule); strftime (timestamp, TIMEBUF_SIZE, "%Y-%m-%d %H:%M:%S", localtime ((time_t*)&rule_timeout)); buff = g_strdup_printf("\ttime_out=%s\n", timestamp); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(timestamp); g_free(buff); buff = g_strdup_printf("\toccurence=%d\n", sim_rule_get_occurrence(rule)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); buff = g_strdup_printf("\tplugins_sid=%d\n", sim_rule_get_plugin_sid(rule)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); // TODO: with taxonomy we can have multiple plugin ids or ANY buff = g_strdup_printf("\tplugind_id=%d\n", sim_rule_get_plugin_id(rule)); g_io_channel_write_chars(channel,buff,-1,NULL,NULL); g_free(buff); } } }
/** * pk_debuginfo_install_add_deps: **/ static gboolean pk_debuginfo_install_add_deps (PkDebuginfoInstallPrivate *priv, GPtrArray *packages_search, GPtrArray *packages_results, GError **error) { gboolean ret = TRUE; PkResults *results = NULL; PkPackage *item; gchar *package_id = NULL; GPtrArray *list = NULL; GError *error_local = NULL; gchar **package_ids = NULL; gchar *name_debuginfo; guint i; gchar **split; PkError *error_code = NULL; /* get depends for them all, not adding dup's */ package_ids = pk_ptr_array_to_strv (packages_search); results = pk_client_get_depends (priv->client, pk_bitfield_value (PK_FILTER_ENUM_NONE), package_ids, TRUE, NULL, NULL, NULL, &error_local); if (results == NULL) { *error = g_error_new (1, 0, "failed to get_depends: %s", error_local->message); g_error_free (error_local); ret = FALSE; goto out; } /* check error code */ error_code = pk_results_get_error_code (results); if (error_code != NULL) { *error = g_error_new (1, 0, "failed to get depends: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code)); ret = FALSE; goto out; } /* add dependent packages */ list = pk_results_get_package_array (results); for (i=0; i<list->len; i++) { item = g_ptr_array_index (list, i); split = pk_package_id_split (pk_package_get_id (item)); /* add -debuginfo */ name_debuginfo = pk_debuginfo_install_name_to_debuginfo (split[PK_PACKAGE_ID_NAME]); g_strfreev (split); /* resolve name */ g_debug ("resolving: %s", name_debuginfo); package_id = pk_debuginfo_install_resolve_name_to_id (priv, name_debuginfo, &error_local); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the package name, non-fatal */ g_print (_("Failed to find the package %s, or already installed: %s"), name_debuginfo, error_local->message); g_print ("\n"); g_error_free (error_local); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL && !g_str_has_suffix (package_id, "installed")) { g_debug ("going to try to install (for deps): %s", package_id); g_ptr_array_add (packages_results, g_strdup (package_id)); } g_free (package_id); g_free (name_debuginfo); } out: if (error_code != NULL) g_object_unref (error_code); if (results != NULL) g_object_unref (results); if (list != NULL) g_ptr_array_unref (list); g_strfreev (package_ids); return ret; }
void ecNode(FILE* f) { fprintf(f, "%s", "node system("); for (int i = 0; i < intab->len; i++) { input *it = GET_INPUT(intab, i); fprintf(f, "%s : bool;\n", it->name); } fseek(f, -2, SEEK_CUR); fprintf(f, "%s", ") returns ("); for (int i = 0; i < outtab->len; i++) { output *ot = GET_OUTPUT(outtab, i); fprintf(f, "%s : bool;\n", ot->name); } for (int i = 0; i < partab->len; i++) { automaton *at = GET_PAR(partab, i); for (int j = 0; j < at->sttab->len; j++) { state *st = GET_STATE(at->sttab, j); fprintf(f, "suiv_%s : bool;\n", st->name); } } for (int i = 0; i < outtab->len; i++) { output *ot = GET_OUTPUT(outtab, i); fprintf(f, "suiv_memoire_de_%s : bool;\n", ot->name); } fseek(f, -2, SEEK_CUR); fprintf(f, "%s", ");\n"); fprintf(f, "%s", "var\n"); for (int i = 0; i < partab->len; i++) { automaton *at = GET_PAR(partab, i); for (int j = 0; j < at->sttab->len; j++) { state *st = GET_STATE(at->sttab, j); fprintf(f, " %s_Choix : bool;\n", st->name); } for (int j = 0; j < at->trtab->len; j++) { tran *tt = GET_TRAN(at->trtab, j); fprintf(f, " %s : bool;\n", tt->name); } } for (int i = 0; i < partab->len; i++) { automaton *at = GET_PAR(partab, i); for (int j = 0; j < at->sttab->len; j++) { state *st = GET_STATE(at->sttab, j); fprintf(f, " %s : bool;\n", st->name); } } for (int i = 0; i < outtab->len; i++) { output *ot = GET_OUTPUT(outtab, i); fprintf(f, " memoire_de_%s : bool;\n", ot->name); } /* let */ fprintf(f, "\nlet\n"); for (int i = 0; i < partab->len; i++) { automaton *at = GET_PAR(partab, i); for (int j = 0; j < at->sttab->len; j++) { state *st = GET_STATE(at->sttab, j); fprintf(f, " %s_Choix=%s;\n", st->name, st->init ? "true":"false"); } for (int j = 0; j < at->trtab->len; j++) { tran *tt = GET_TRAN(at->trtab, j); fprintf(f, " %s=if (%s) then (%s) else false;\n", tt->name, tt->from->name, tt->expr); } } for (int i = 0; i < partab->len; i++) { automaton *at = GET_PAR(partab, i); for (int j = 0; j < at->sttab->len; j++) { state *st = GET_STATE(at->sttab, j); fprintf(f, " %s=%s->pre(suiv_%s);\n", st->name, st->init ? "true":"false", st->name); } } for (int i = 0; i < outtab->len; i++) { output *ot = (output *)g_ptr_array_index(outtab, i); fprintf(f, " %s=", ot->name); for (int j = 0; j < ot->exprs->len; j++) //for (int j = ot->exprs->len-1; j >= 0; j--) { subout *sot=(subout *)g_ptr_array_index(ot->exprs, j); fprintf(f, "if (%s) then ", sot->s->name); if (!strcmp(sot->expr, "1")) { fprintf(f, "%s", "true"); } else if (!strcmp(sot->expr, "-1")) { fprintf(f, "%s", "false"); } else { fprintf(f, "(%s)", sot->expr); } fprintf(f, " else "); } fprintf(f, "memoire_de_%s", ot->name); fprintf(f, ";\n"); } /* suiv_ */ for (int i = 0; i < partab->len; i++) { automaton *at = GET_PAR(partab, i); for (int j = 0; j < at->sttab->len; j++) { state *st1 = GET_STATE(at->sttab, j); fprintf(f, " suiv_%s=", st1->name); GPtrArray *lien = g_ptr_array_new(); for (int k = 0; k < at->sttab->len; k++) { state *st2 = (state *)g_ptr_array_index(at->sttab, k); if (st1 == st2) { char *strtmp = (char *)calloc(30000, 1); int numor = 0; for (int l = 0; l < at->trtab->len; l++) { tran *tt = (tran *)g_ptr_array_index(at->trtab, l); if((tt->to != st1) && (tt->from == st1)) // there's a tran from state2 to state1 { numor++; if (numor > 1) { strtmp = strcat(strtmp, " or "); } strtmp = strcat(strtmp, tt->name); } } if (strcmp(strtmp, "")) { gchar *tmp = g_strconcat("(not (", strtmp, "))", NULL); g_ptr_array_add(lien, (gpointer)tmp); } else g_ptr_array_add(lien, NULL); free(strtmp); } else // st1 != st2 { char *strtmp = (char *)calloc(30000, 1); for (int l = 0; l < at->trtab->len; l++) { tran *tt = (tran *)g_ptr_array_index(at->trtab, l); if((tt->to == st1) && (tt->from == st2)) // there's a tran from state2 to state1 { strtmp = strcat(strtmp, tt->name); } } if (strcmp(strtmp, "")) { gchar *tmp = g_strconcat("(", strtmp, ")", NULL); g_ptr_array_add(lien, (gpointer)tmp); } else g_ptr_array_add(lien, NULL); free(strtmp); } } /* construct output string */ // char *gstr = (char *)calloc(300000, 1); // sprintf(gstr, "%s", st1->name); for (int i = 0; i < lien->len; i++) { char *stmp = (char *)g_ptr_array_index(lien, i); if (stmp != NULL) { state *st = (state *)g_ptr_array_index(at->sttab, i); fprintf(f, "if (%s) then %s else ", st->name, stmp); } fprintf(f, "%s,\n", st1->name); g_ptr_array_free(lien, TRUE); } } } /* suiv_memoire_ */ for (int i = 0; i < outtab->len; i++) { output *ot = GET_OUTPUT(outtab, i); fprintf(f, " suiv_memoire_de_%s=%s;\n", ot->name, ot->name); } /* memoire_ */ for (int i = 0; i < outtab->len; i++) { output *ot = GET_OUTPUT(outtab, i); fprintf(f, " memoire_de_%s=%s->pre(suiv_memoire_de_%s);\n", ot->name, ot->def_val ? "true":"false", ot->name); } /* tel; */ fprintf(f, "\ntel;\n\n"); }
GPtrArray *mdb_read_columns(MdbTableDef *table) { MdbHandle *mdb = table->entry->mdb; MdbFormatConstants *fmt = mdb->fmt; MdbColumn *pcol; unsigned char *col; unsigned int i; int cur_pos; size_t name_sz; table->columns = g_ptr_array_new(); col = (unsigned char *) g_malloc(fmt->tab_col_entry_size); cur_pos = fmt->tab_cols_start_offset + (table->num_real_idxs * fmt->tab_ridx_entry_size); /* new code based on patch submitted by Tim Nelson 2000.09.27 */ /* ** column attributes */ for (i=0;i<table->num_cols;i++) { #ifdef MDB_DEBUG /* printf("column %d\n", i); buffer_dump(mdb->pg_buf, cur_pos, fmt->tab_col_entry_size); */ #endif read_pg_if_n(mdb, col, &cur_pos, fmt->tab_col_entry_size); pcol = (MdbColumn *) g_malloc0(sizeof(MdbColumn)); pcol->col_type = col[0]; pcol->col_num = col[fmt->col_num_offset]; pcol->var_col_num = mdb_get_int16(col, fmt->tab_col_offset_var); pcol->row_col_num = mdb_get_int16(col, fmt->tab_row_col_num_offset); /* FIXME: can this be right in Jet3 and Jet4? */ if (pcol->col_type == MDB_NUMERIC) { pcol->col_prec = col[11]; pcol->col_scale = col[12]; } pcol->is_fixed = col[fmt->col_fixed_offset] & 0x01 ? 1 : 0; pcol->fixed_offset = mdb_get_int16(col, fmt->tab_col_offset_fixed); if (pcol->col_type != MDB_BOOL) { pcol->col_size = mdb_get_int16(col, fmt->col_size_offset); } else { pcol->col_size=0; } g_ptr_array_add(table->columns, pcol); } g_free (col); /* ** column names - ordered the same as the column attributes table */ for (i=0;i<table->num_cols;i++) { char *tmp_buf; pcol = g_ptr_array_index(table->columns, i); if (IS_JET4(mdb)) { name_sz = read_pg_if_16(mdb, &cur_pos); } else if (IS_JET3(mdb)) { name_sz = read_pg_if_8(mdb, &cur_pos); } else { fprintf(stderr,"Unknown MDB version\n"); continue; } tmp_buf = (char *) g_malloc(name_sz); read_pg_if_n(mdb, tmp_buf, &cur_pos, name_sz); mdb_unicode2ascii(mdb, tmp_buf, name_sz, pcol->name, MDB_MAX_OBJ_NAME); g_free(tmp_buf); } /* Sort the columns by col_num */ g_ptr_array_sort(table->columns, (GCompareFunc)mdb_col_comparer); table->index_start = cur_pos; return table->columns; }
GHashTable *generate_edges_table(const GPtrArray *activation_array, GPtrArray *targets_array) { unsigned int i; /* Create empty hash table */ GHashTable *edges_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_value); for(i = 0; i < activation_array->len; i++) { /* Retrieve the current mapping from the array */ ActivationMapping *mapping = g_ptr_array_index(activation_array, i); /* Retrieve the target property */ Target *target = find_target(targets_array, mapping->target); gchar *target_key = find_target_key(target); /* Generate an edge table key, which consist of Nix store component:targetProperty */ gchar *mapping_key = compose_mapping_key(mapping, target_key); /* Retrieve the dependency array of the mapping from the edges table */ GPtrArray *dependency_array = g_hash_table_lookup(edges_table, mapping_key); /* If the dependency array does not exists, create one and add it to the table */ if(dependency_array == NULL) { unsigned int j; GPtrArray *depends_on = mapping->depends_on; /* Create new dependency array */ dependency_array = g_ptr_array_new(); /* Create a list of mapping values for each dependency */ for(j = 0; j < depends_on->len; j++) { ActivationMapping *actual_mapping; gchar *mapping_value, *target_key; Target *target; /* Retrieve current dependency from the array */ ActivationMappingKey *dependency = g_ptr_array_index(depends_on, j); /* Find the activation mapping in the activation array */ actual_mapping = find_activation_mapping(activation_array, dependency); /* Get the target interface */ target = find_target(targets_array, actual_mapping->target); target_key = find_target_key(target); /* Generate mapping value from the service key and target property */ mapping_value = compose_mapping_key(actual_mapping, target_key); /* Add mapping value to the dependency array */ g_ptr_array_add(dependency_array, mapping_value); } /* Associate the dependency array to the given mapping */ g_hash_table_insert(edges_table, mapping_key, dependency_array); } } /* Return the generated egdes table */ return edges_table; }
/** * clutter_alpha_set_mode: * @alpha: a #ClutterAlpha * @mode: a #ClutterAnimationMode * * Sets the progress function of @alpha using the symbolic value * of @mode, as taken by the #ClutterAnimationMode enumeration or * using the value returned by clutter_alpha_register_func(). * * Since: 1.0 * * Deprecated: 1.12: Use #ClutterTimeline and * clutter_timeline_set_progress_mode() instead */ void clutter_alpha_set_mode (ClutterAlpha *alpha, gulong mode) { ClutterAlphaPrivate *priv; g_return_if_fail (CLUTTER_IS_ALPHA (alpha)); g_return_if_fail (mode != CLUTTER_ANIMATION_LAST); priv = alpha->priv; if (mode == CLUTTER_CUSTOM_MODE) { priv->mode = mode; } else if (mode < CLUTTER_ANIMATION_LAST) { if (priv->mode == mode) return; /* sanity check to avoid getting an out of sync * enum/function mapping */ g_assert (clutter_get_easing_func_for_mode (mode) != NULL); clutter_alpha_set_closure_internal (alpha, NULL); priv->mode = mode; CLUTTER_NOTE (ANIMATION, "New easing mode '%s'[%lu]\n", clutter_get_easing_name_for_mode (priv->mode), priv->mode); priv->func = clutter_alpha_easing_func; priv->user_data = NULL; priv->notify = NULL; } else if (mode > CLUTTER_ANIMATION_LAST) { AlphaData *alpha_data = NULL; gulong real_index = 0; if (priv->mode == mode) return; if (G_UNLIKELY (clutter_alphas == NULL)) { g_warning ("No alpha functions defined for ClutterAlpha to use. " "Use clutter_alpha_register_func() to register an " "alpha function."); return; } real_index = mode - CLUTTER_ANIMATION_LAST - 1; alpha_data = g_ptr_array_index (clutter_alphas, real_index); if (G_UNLIKELY (alpha_data == NULL)) { g_warning ("No alpha function registered for mode %lu.", mode); return; } if (alpha_data->closure_set) clutter_alpha_set_closure (alpha, alpha_data->closure); else { clutter_alpha_set_closure_internal (alpha, NULL); priv->func = alpha_data->func; priv->user_data = alpha_data->data; priv->notify = NULL; } priv->mode = mode; } else g_assert_not_reached (); g_object_notify_by_pspec (G_OBJECT (alpha), obj_props[PROP_MODE]); }
static void cam_thumb_draw (Viewer *viewer, Renderer *renderer) { RendererCamThumb *self = (RendererCamThumb*) renderer->user; GLint viewport[4]; glGetIntegerv (GL_VIEWPORT, viewport); // transform into window coordinates, where <0, 0> is the top left corner // of the window and <viewport[2], viewport[3]> is the bottom right corner // of the window glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, viewport[2], 0, viewport[3]); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(0, viewport[3], 0); glScalef(1, -1, 1); double vp_width = viewport[2] - viewport[0]; double vp_height = viewport[3] - viewport[1]; GPtrArray *crlist = gu_hash_table_get_vals (self->cam_handlers); for (int criter = 0; criter < g_ptr_array_size(crlist); criter++) { cam_renderer_t *cr = g_ptr_array_index(crlist, criter); if (!cr->last_image) continue; double aspect = cr->last_image->width / (double) cr->last_image->height; double thumb_width, thumb_height; if ((vp_width / 3) / aspect > vp_height / 3) { thumb_height = vp_height / 3; thumb_width = thumb_height * aspect; } else { thumb_width = vp_width / 3; thumb_height = thumb_width / aspect; } int rmode = gtku_param_widget_get_enum (cr->pw, PARAM_RENDER_IN); if (rmode == RENDER_IN_WIDGET) continue; point2d_t p1 = { viewport[0], viewport[1] }; switch (rmode) { case RENDER_IN_BOTTOM_RIGHT: p1.x = vp_width - thumb_width; p1.y = vp_height - thumb_height; break; case RENDER_IN_BOTTOM_CENTER: p1.x = vp_width / 3; p1.y = vp_height - thumb_height; break; case RENDER_IN_BOTTOM_LEFT: p1.x = 0; p1.y = vp_height - thumb_height; break; case RENDER_IN_TOP_LEFT: p1.x = 0; p1.y = 0; break; case RENDER_IN_TOP_CENTER: p1.x = vp_width / 3; p1.y = 0; break; case RENDER_IN_TOP_RIGHT: p1.x = vp_width - thumb_width; p1.y = 0; break; default: break; } glPushMatrix (); glTranslatef (p1.x, p1.y, 1); glScalef (thumb_width, thumb_height, 1); cam_renderer_draw (cr); glPopMatrix (); } g_ptr_array_free (crlist, TRUE); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
static gboolean audit_build_model (GtkTreeStore *tree_store, GvaAuditData *data, GError **error) { GtkTreeModel *game_store; GtkTreeIter iter; gboolean iter_valid; game_store = gva_game_store_new_from_query ( SQL_SELECT_BAD_GAMES, error); if (game_store == NULL) return FALSE; gtk_tree_store_clear (tree_store); iter_valid = gtk_tree_model_get_iter_first (game_store, &iter); while (iter_valid) { GtkTreeIter parent; GtkTreeIter child; guint index; gchar *name; gchar *description; gtk_tree_model_get ( game_store, &iter, GVA_GAME_STORE_COLUMN_NAME, &name, GVA_GAME_STORE_COLUMN_DESCRIPTION, &description, -1); gtk_tree_store_append (tree_store, &parent, NULL); gtk_tree_store_set (tree_store, &parent, 0, description, -1); index = GPOINTER_TO_UINT (g_hash_table_lookup ( data->output_index, name)); while (index > 0) { const gchar *line; line = g_ptr_array_index (data->output, --index); if (!g_str_has_prefix (line, name)) break; gtk_tree_store_prepend (tree_store, &child, &parent); gtk_tree_store_set (tree_store, &child, 0, line, -1); } g_free (name); g_free (description); iter_valid = gtk_tree_model_iter_next (game_store, &iter); } gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (tree_store), 0, GTK_SORT_ASCENDING); g_object_unref (game_store); return TRUE; }
/** * main: **/ int main (int argc, char *argv[]) { gboolean ret; GError *error = NULL; GPtrArray *added_repos = NULL; GPtrArray *package_ids_recognised = NULL; GPtrArray *package_ids_to_install = NULL; guint i; guint retval = 0; gchar *package_id; gchar *name; gchar *name_debuginfo; gboolean simulate = FALSE; gboolean no_depends = FALSE; gboolean quiet = FALSE; gboolean noninteractive = FALSE; GOptionContext *context; const gchar *repo_id; gchar *repo_id_debuginfo; PkDebuginfoInstallPrivate *priv = NULL; guint step = 1; const GOptionEntry options[] = { { "simulate", 's', 0, G_OPTION_ARG_NONE, &simulate, /* command line argument, simulate what would be done, but don't actually do it */ _("Don't actually install any packages, only simulate what would be installed"), NULL }, { "no-depends", 'n', 0, G_OPTION_ARG_NONE, &no_depends, /* command line argument, do we skip packages that depend on the ones specified */ _("Do not install dependencies of the core packages"), NULL }, { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, /* command line argument, do we operate quietly */ _("Do not display information or progress"), NULL }, { "noninteractive", 'y', 0, G_OPTION_ARG_NONE, &noninteractive, /* command line argument, do we ask questions */ _("Install the packages without asking for confirmation"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 31) if (! g_thread_supported ()) g_thread_init (NULL); #endif g_type_init (); context = g_option_context_new (NULL); /* TRANSLATORS: tool that gets called when the command is not found */ g_option_context_set_summary (context, _("PackageKit Debuginfo Installer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, pk_debug_get_option_group ()); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* new private struct */ priv = g_new0 (PkDebuginfoInstallPrivate, 1); /* no input */ if (argv[1] == NULL) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: the use needs to specify a list of package names on the command line */ g_print (_("ERROR: Specify package names to install.")); g_print ("\n"); } /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED; goto out; } /* store as strings */ priv->enabled = g_ptr_array_new (); priv->disabled = g_ptr_array_new (); added_repos = g_ptr_array_new (); package_ids_to_install = g_ptr_array_new (); package_ids_recognised = g_ptr_array_new (); /* create #PkClient */ priv->client = PK_CLIENT(pk_task_text_new ()); /* we are not asking questions, so it's pointless simulating */ if (noninteractive) { g_object_set (priv->client, "simulate", FALSE, NULL); } /* use text progressbar */ priv->progress_bar = pk_progress_bar_new (); pk_progress_bar_set_size (priv->progress_bar, 25); pk_progress_bar_set_padding (priv->progress_bar, 60); /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we are getting the list of repositories */ g_print (_("Getting sources list")); g_print ("..."); } /* get all enabled repos */ ret = pk_debuginfo_install_get_repo_list (priv, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: we're failed to enable the sources, detailed error follows */ g_print ("Failed to enable sources list: %s", error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_ENABLE; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user what we found */ g_print (_("Found %i enabled and %i disabled sources."), priv->enabled->len, priv->disabled->len); g_print ("\n"); /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we're finding repositories that match out pattern */ g_print (_("Finding debugging sources")); g_print ("..."); } /* find all debuginfo repos for repos that are enabled */ for (i=0; i<priv->enabled->len; i++) { /* is already a -debuginfo */ repo_id = g_ptr_array_index (priv->enabled, i); if (g_str_has_suffix (repo_id, "-debuginfo")) { g_debug ("already enabled: %s", repo_id); continue; } /* has a debuginfo repo */ repo_id_debuginfo = g_strjoin ("-", repo_id, "debuginfo", NULL); ret = pk_debuginfo_install_in_array (priv->disabled, repo_id_debuginfo); if (ret) { /* add to list to change back at the end */ g_ptr_array_add (added_repos, g_strdup (repo_id_debuginfo)); } else { g_debug ("no debuginfo repo for %s", repo_id_debuginfo); } g_free (repo_id_debuginfo); } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user what we found */ g_print (_("Found %i disabled debuginfo repos."), added_repos->len); g_print ("\n"); /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we're now enabling all the debug sources we found */ g_print (_("Enabling debugging sources")); g_print ("..."); } /* enable all debuginfo repos we found */ ret = pk_debuginfo_install_enable_repos (priv, added_repos, TRUE, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: we're failed to enable the sources, detailed error follows */ g_print ("Failed to enable debugging sources: %s", error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_ENABLE; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user how many we enabled */ g_print (_("Enabled %i debugging sources."), added_repos->len); g_print ("\n"); /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we're now finding packages that match in all the repos */ g_print (_("Finding debugging packages")); g_print ("..."); } /* parse arguments and resolve to packages */ for (i=1; argv[i] != NULL; i++) { name = pk_get_package_name_from_nevra (argv[i]); /* resolve name */ package_id = pk_debuginfo_install_resolve_name_to_id (priv, name, &error); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the package name, non-fatal */ g_print (_("Failed to find the package %s: %s"), name, error->message); g_print ("\n"); g_error_free (error); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL) { g_debug ("going to try to install: %s", package_id); g_ptr_array_add (package_ids_recognised, package_id); } else { goto not_found; } /* convert into basename */ name_debuginfo = pk_debuginfo_install_name_to_debuginfo (name); g_debug ("install %s [%s]", argv[i], name_debuginfo); /* resolve name */ package_id = pk_debuginfo_install_resolve_name_to_id (priv, name_debuginfo, &error); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the debuginfo package name, non-fatal */ g_print (_("Failed to find the debuginfo package %s: %s"), name_debuginfo, error->message); g_print ("\n"); g_error_free (error); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL && !g_str_has_suffix (package_id, "installed")) { g_debug ("going to try to install: %s", package_id); g_ptr_array_add (package_ids_to_install, g_strdup (package_id)); } g_free (name_debuginfo); not_found: g_free (package_id); g_free (name); } /* no packages? */ if (package_ids_to_install->len == 0) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: no debuginfo packages could be found to be installed */ g_print (_("Found no packages to install.")); g_print ("\n"); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_NOTHING_TO_DO; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user we found some packages, and then list them */ g_print (_("Found %i packages:"), package_ids_to_install->len); g_print ("\n"); } /* optional */ if (!no_depends) { /* save for later logic */ i = package_ids_to_install->len; /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: tell the user we are searching for deps */ g_print (_("Finding packages that depend on these packages")); g_print ("..."); } ret = pk_debuginfo_install_add_deps (priv, package_ids_recognised, package_ids_to_install, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: could not install, detailed error follows */ g_print (_("Could not find dependent packages: %s"), error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_FIND_DEPS; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); if (i < package_ids_to_install->len) { /* TRANSLATORS: tell the user we found some more packages */ g_print (_("Found %i extra packages."), package_ids_to_install->len - i); g_print ("\n"); } else { /* TRANSLATORS: tell the user we found some more packages */ g_print (_("No extra packages required.")); g_print ("\n"); } } } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: tell the user we found some packages (and deps), and then list them */ g_print (_("Found %i packages to install:"), package_ids_to_install->len); g_print ("\n"); } /* print list */ if (!quiet) pk_debuginfo_install_print_array (package_ids_to_install); /* simulate mode for testing */ if (simulate) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: simulate mode is a testing mode where we quit before the action */ g_print (_("Not installing packages in simulate mode")); g_print ("\n"); } goto out; } /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we are now installing the debuginfo packages we found earlier */ g_print (_("Installing packages")); g_print ("...\n"); } /* install */ ret = pk_debuginfo_install_packages_install (priv, package_ids_to_install, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: could not install, detailed error follows */ g_print (_("Could not install packages: %s"), error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_INSTALL; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print (_("OK.")); g_print ("\n"); } out: if (package_ids_to_install != NULL) { g_ptr_array_foreach (package_ids_to_install, (GFunc) g_free, NULL); g_ptr_array_free (package_ids_to_install, TRUE); } if (package_ids_recognised != NULL) { g_ptr_array_foreach (package_ids_recognised, (GFunc) g_free, NULL); g_ptr_array_free (package_ids_recognised, TRUE); } if (added_repos != NULL) { /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step); /* TRANSLATORS: we are now disabling all debuginfo repos we previously enabled */ g_print (_("Disabling sources previously enabled")); g_print ("..."); } /* disable all debuginfo repos we previously enabled */ ret = pk_debuginfo_install_enable_repos (priv, added_repos, FALSE, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: no debuginfo packages could be found to be installed, detailed error follows */ g_print (_("Could not disable the debugging sources: %s"), error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_DISABLE; } else { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: we disabled all the debugging repos that we enabled before */ g_print (_("Disabled %i debugging sources."), added_repos->len); g_print ("\n"); } } g_ptr_array_foreach (added_repos, (GFunc) g_free, NULL); g_ptr_array_free (added_repos, TRUE); } if (priv->enabled != NULL) { g_ptr_array_foreach (priv->enabled, (GFunc) g_free, NULL); g_ptr_array_free (priv->enabled, TRUE); } if (priv->disabled != NULL) { g_ptr_array_foreach (priv->disabled, (GFunc) g_free, NULL); g_ptr_array_free (priv->disabled, TRUE); } if (priv->client != NULL) g_object_unref (priv->client); if (priv->progress_bar != NULL) g_object_unref (priv->progress_bar); g_free (priv); return retval; }
/** * dnf_emit_package_list_filter: */ void dnf_emit_package_list_filter (PkBackendJob *job, PkBitfield filters, GPtrArray *pkglist) { DnfPackage *found; DnfPackage *pkg; guint i; g_autoptr(GHashTable) hash_cost = NULL; g_autoptr(GHashTable) hash_installed = NULL; /* if a package exists in multiple repos, show the one with the lowest * cost of downloading */ hash_cost = g_hash_table_new (g_str_hash, g_str_equal); for (i = 0; i < pkglist->len; i++) { pkg = g_ptr_array_index (pkglist, i); if (dnf_package_installed (pkg)) continue; /* if the NEVRA does not already exist in the array, just add */ found = g_hash_table_lookup (hash_cost, dnf_package_get_nevra (pkg)); if (found == NULL) { g_hash_table_insert (hash_cost, (gpointer) dnf_package_get_nevra (pkg), (gpointer) pkg); continue; } /* a lower cost package */ if (dnf_package_get_cost (pkg) < dnf_package_get_cost (found)) { dnf_package_set_info (found, PK_INFO_ENUM_BLOCKED); g_hash_table_replace (hash_cost, (gpointer) dnf_package_get_nevra (pkg), (gpointer) pkg); } else { dnf_package_set_info (pkg, PK_INFO_ENUM_BLOCKED); } } /* add all the installed packages to a hash */ hash_installed = g_hash_table_new (g_str_hash, g_str_equal); for (i = 0; i < pkglist->len; i++) { pkg = g_ptr_array_index (pkglist, i); if (!dnf_package_installed (pkg)) continue; g_hash_table_insert (hash_installed, (gpointer) dnf_package_get_nevra (pkg), (gpointer) pkg); } /* anything remote in metadata-only mode needs to be unavailable */ for (i = 0; i < pkglist->len; i++) { DnfRepo *src; pkg = g_ptr_array_index (pkglist, i); if (dnf_package_installed (pkg)) continue; src = dnf_package_get_repo (pkg); if (src == NULL) continue; if (dnf_repo_get_enabled (src) != DNF_REPO_ENABLED_METADATA) continue; dnf_package_set_info (pkg, PK_INFO_ENUM_UNAVAILABLE); } for (i = 0; i < pkglist->len; i++) { pkg = g_ptr_array_index (pkglist, i); /* blocked */ if ((PkInfoEnum) dnf_package_get_info (pkg) == PK_INFO_ENUM_BLOCKED) continue; /* GUI */ if (pk_bitfield_contain (filters, PK_FILTER_ENUM_GUI) && !dnf_package_is_gui (pkg)) continue; if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_GUI) && dnf_package_is_gui (pkg)) continue; /* DEVELOPMENT */ if (pk_bitfield_contain (filters, PK_FILTER_ENUM_DEVELOPMENT) && !dnf_package_is_devel (pkg)) continue; if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_DEVELOPMENT) && dnf_package_is_devel (pkg)) continue; /* DOWNLOADED */ if (pk_bitfield_contain (filters, PK_FILTER_ENUM_DOWNLOADED) && !dnf_package_is_downloaded (pkg)) continue; if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_DOWNLOADED) && dnf_package_is_downloaded (pkg)) continue; /* if this package is available and the very same NEVRA is * installed, skip this package */ if (!dnf_package_installed (pkg)) { found = g_hash_table_lookup (hash_installed, dnf_package_get_nevra (pkg)); if (found != NULL) continue; } dnf_emit_package (job, PK_INFO_ENUM_UNKNOWN, pkg); } }
static gboolean asb_task_explode_extra_packages (AsbTask *task, GError **error) { AsbTaskPrivate *priv = GET_PRIVATE (task); GPtrArray *deps; const gchar *ignore[] = { "rtld", NULL }; const gchar *tmp; guint i; g_autoptr(GHashTable) hash = NULL; g_autoptr(GPtrArray) array = NULL; g_autoptr(GPtrArray) icon_themes = NULL; /* anything the package requires */ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; ignore[i] != NULL; i++) { g_hash_table_insert (hash, g_strdup (ignore[i]), GINT_TO_POINTER (1)); } array = g_ptr_array_new_with_free_func (g_free); icon_themes = g_ptr_array_new_with_free_func (g_free); deps = asb_package_get_deps (priv->pkg); for (i = 0; i < deps->len; i++) { tmp = g_ptr_array_index (deps, i); if (g_strstr_len (tmp, -1, " ") != NULL) continue; if (g_strstr_len (tmp, -1, ".so") != NULL) continue; if (g_str_has_prefix (tmp, "/")) continue; if (g_hash_table_lookup (hash, tmp) != NULL) continue; if (g_strcmp0 (tmp, asb_package_get_name (priv->pkg)) == 0) continue; /* libreoffice making things complicated */ if (g_strcmp0 (tmp, "libreoffice-core") == 0) g_ptr_array_add (array, g_strdup ("libreoffice-data")); /* if an app depends on kde-runtime, that means the * oxygen icon set is available to them */ if (g_strcmp0 (tmp, "oxygen-icon-theme") == 0 || g_strcmp0 (tmp, "kde-runtime") == 0) { g_hash_table_insert (hash, g_strdup ("oxygen-icon-theme"), GINT_TO_POINTER (1)); g_ptr_array_add (icon_themes, g_strdup ("oxygen-icon-theme")); /* Applications depending on yast2 have an implicit dependency * on yast2-branding-openSUSE, which brings required icons in this case. */ } else if (g_strcmp0 (tmp, "yast2-branding-openSUSE") == 0 || g_strcmp0 (tmp, "yast2") == 0) { g_hash_table_insert (hash, g_strdup ("yast2-branding-openSUSE"), GINT_TO_POINTER (1)); g_ptr_array_add (icon_themes, g_strdup ("yast2-branding-openSUSE")); } else { g_ptr_array_add (array, g_strdup (tmp)); } g_hash_table_insert (hash, g_strdup (tmp), GINT_TO_POINTER (1)); } /* explode any potential packages */ for (i = 0; i < array->len; i++) { tmp = g_ptr_array_index (array, i); if (!asb_task_explode_extra_package (task, tmp, TRUE, error)) return FALSE; } /* explode any icon themes */ for (i = 0; i < icon_themes->len; i++) { tmp = g_ptr_array_index (icon_themes, i); if (!asb_task_explode_extra_package (task, tmp, FALSE, error)) return FALSE; } return TRUE; }
gboolean dfvm_apply(dfilter_t *df, proto_tree *tree) { int id, length; gboolean accum = TRUE; dfvm_insn_t *insn; dfvm_value_t *arg1; dfvm_value_t *arg2; dfvm_value_t *arg3 = NULL; dfvm_value_t *arg4 = NULL; header_field_info *hfinfo; GList *param1; GList *param2; g_assert(tree); length = df->insns->len; for (id = 0; id < length; id++) { AGAIN: insn = (dfvm_insn_t *)g_ptr_array_index(df->insns, id); arg1 = insn->arg1; arg2 = insn->arg2; switch (insn->op) { case CHECK_EXISTS: hfinfo = arg1->value.hfinfo; while(hfinfo) { accum = proto_check_for_protocol_or_field(tree, hfinfo->id); if (accum) { break; } else { hfinfo = hfinfo->same_name_next; } } break; case READ_TREE: accum = read_tree(df, tree, arg1->value.hfinfo, arg2->value.numeric); break; case CALL_FUNCTION: arg3 = insn->arg3; arg4 = insn->arg4; param1 = NULL; param2 = NULL; if (arg3) { param1 = df->registers[arg3->value.numeric]; } if (arg4) { param2 = df->registers[arg4->value.numeric]; } accum = arg1->value.funcdef->function(param1, param2, &df->registers[arg2->value.numeric]); break; case MK_RANGE: arg3 = insn->arg3; mk_range(df, arg1->value.numeric, arg2->value.numeric, arg3->value.drange); break; case ANY_EQ: accum = any_test(df, fvalue_eq, arg1->value.numeric, arg2->value.numeric); break; case ANY_NE: accum = any_test(df, fvalue_ne, arg1->value.numeric, arg2->value.numeric); break; case ANY_GT: accum = any_test(df, fvalue_gt, arg1->value.numeric, arg2->value.numeric); break; case ANY_GE: accum = any_test(df, fvalue_ge, arg1->value.numeric, arg2->value.numeric); break; case ANY_LT: accum = any_test(df, fvalue_lt, arg1->value.numeric, arg2->value.numeric); break; case ANY_LE: accum = any_test(df, fvalue_le, arg1->value.numeric, arg2->value.numeric); break; case ANY_BITWISE_AND: accum = any_test(df, fvalue_bitwise_and, arg1->value.numeric, arg2->value.numeric); break; case ANY_CONTAINS: accum = any_test(df, fvalue_contains, arg1->value.numeric, arg2->value.numeric); break; case ANY_MATCHES: accum = any_test(df, fvalue_matches, arg1->value.numeric, arg2->value.numeric); break; case NOT: accum = !accum; break; case RETURN: free_register_overhead(df); return accum; case IF_TRUE_GOTO: if (accum) { id = arg1->value.numeric; goto AGAIN; } break; case IF_FALSE_GOTO: if (!accum) { id = arg1->value.numeric; goto AGAIN; } break; case PUT_FVALUE: #if 0 /* These were handled in the constants initialization */ accum = put_fvalue(df, arg1->value.fvalue, arg2->value.numeric); break; #endif default: g_assert_not_reached(); break; } } g_assert_not_reached(); return FALSE; /* to appease the compiler */ }
/** * asb_task_process: * @task: A #AsbTask * @error_not_used: A #GError or %NULL * * Processes the task. * * Returns: %TRUE for success, %FALSE otherwise * * Since: 0.1.0 **/ gboolean asb_task_process (AsbTask *task, GError **error_not_used) { AsRelease *release; AsbApp *app; AsbPlugin *plugin = NULL; AsbTaskPrivate *priv = GET_PRIVATE (task); GList *apps = NULL; GList *l; GPtrArray *array; gboolean ret; gchar *cache_id; guint i; guint nr_added = 0; g_autoptr(GError) error = NULL; g_autofree gchar *basename = NULL; /* reset the profile timer */ asb_package_log_start (priv->pkg); /* ensure nevra read */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_NEVRA, error_not_used)) return FALSE; g_debug ("starting: %s", asb_package_get_name (priv->pkg)); /* treat archive as a special case */ if (g_str_has_suffix (priv->filename, ".cab")) { AsApp *app_tmp; GPtrArray *apps_tmp; g_autoptr(AsStore) store = as_store_new (); g_autoptr(GFile) file = g_file_new_for_path (priv->filename); if (!as_store_from_file (store, file, NULL, NULL, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to parse %s: %s", asb_package_get_filename (priv->pkg), error->message); return TRUE; } apps_tmp = as_store_get_apps (store); for (i = 0; i < apps_tmp->len; i++) { g_autoptr(AsbApp) app2 = NULL; app_tmp = AS_APP (g_ptr_array_index (apps_tmp, i)); app2 = asb_app_new (priv->pkg, as_app_get_id (app_tmp)); as_app_subsume (AS_APP (app2), app_tmp); asb_context_add_app (priv->ctx, app2); /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); as_app_add_metadata (AS_APP (app2), "X-CacheID", cache_id); g_free (cache_id); } nr_added++; } g_debug ("added %u apps from archive", apps_tmp->len); goto skip; } /* ensure file list read */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_FILES, error_not_used)) return FALSE; /* did we get a file match on any plugin */ basename = g_path_get_basename (priv->filename); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Getting filename match for %s", basename); asb_task_add_suitable_plugins (task); if (priv->plugins_to_run->len == 0) { asb_context_add_app_ignore (priv->ctx, priv->pkg); goto out; } /* delete old tree if it exists */ ret = asb_utils_ensure_exists_and_empty (priv->tmpdir, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to clear: %s", error->message); goto out; } /* explode tree */ g_debug ("decompressing files: %s", asb_package_get_name (priv->pkg)); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Exploding tree for %s", asb_package_get_name (priv->pkg)); ret = asb_package_explode (priv->pkg, priv->tmpdir, asb_context_get_file_globs (priv->ctx), &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to explode: %s", error->message); g_clear_error (&error); goto skip; } /* add extra packages */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_DEPS | ASB_PACKAGE_ENSURE_SOURCE, error_not_used)) return FALSE; ret = asb_task_explode_extra_packages (task, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to explode extra file: %s", error->message); goto skip; } /* run plugins */ g_debug ("examining: %s", asb_package_get_name (priv->pkg)); for (i = 0; i < priv->plugins_to_run->len; i++) { GList *apps_tmp = NULL; plugin = g_ptr_array_index (priv->plugins_to_run, i); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Processing %s with %s", basename, plugin->name); apps_tmp = asb_plugin_process (plugin, priv->pkg, priv->tmpdir, &error); if (apps_tmp == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process '%s': %s", plugin->name, error->message); g_clear_error (&error); } for (l = apps_tmp; l != NULL; l = l->next) { app = ASB_APP (l->data); asb_plugin_add_app (&apps, AS_APP (app)); } g_list_free_full (apps_tmp, g_object_unref); } if (apps == NULL) goto skip; /* print */ g_debug ("processing: %s", asb_package_get_name (priv->pkg)); for (l = apps; l != NULL; l = l->next) { app = l->data; /* never set */ if (as_app_get_id (AS_APP (app)) == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_INFO, "app id not set for %s", asb_package_get_name (priv->pkg)); continue; } /* copy data from pkg into app */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_LICENSE | ASB_PACKAGE_ENSURE_RELEASES | ASB_PACKAGE_ENSURE_VCS | ASB_PACKAGE_ENSURE_URL, error_not_used)) return FALSE; if (asb_package_get_url (priv->pkg) != NULL && as_app_get_url_item (AS_APP (app), AS_URL_KIND_HOMEPAGE) == NULL) { as_app_add_url (AS_APP (app), AS_URL_KIND_HOMEPAGE, asb_package_get_url (priv->pkg)); } if (asb_package_get_license (priv->pkg) != NULL && as_app_get_project_license (AS_APP (app)) == NULL) { as_app_set_project_license (AS_APP (app), asb_package_get_license (priv->pkg)); } /* add the source name so we can suggest these together */ if (g_strcmp0 (asb_package_get_source_pkgname (priv->pkg), asb_package_get_name (priv->pkg)) != 0) { as_app_set_source_pkgname (AS_APP (app), asb_package_get_source_pkgname (priv->pkg)); } /* set all the releases on the app */ array = asb_package_get_releases (priv->pkg); for (i = 0; i < array->len; i++) { release = g_ptr_array_index (array, i); as_app_add_release (AS_APP (app), release); } /* run each refine plugin on each app */ ret = asb_plugin_loader_process_app (asb_context_get_plugin_loader (priv->ctx), priv->pkg, app, priv->tmpdir, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process on %s: %s", as_app_get_id (AS_APP (app)), error->message); g_clear_error (&error); goto skip; } /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); as_app_add_metadata (AS_APP (app), "X-CacheID", cache_id); g_free (cache_id); } /* set the VCS information into the metadata */ if (asb_package_get_vcs (priv->pkg) != NULL) { as_app_add_metadata (AS_APP (app), "VersionControlSystem", asb_package_get_vcs (priv->pkg)); } /* save any screenshots early */ if (array->len == 0) { if (!asb_app_save_resources (ASB_APP (app), ASB_APP_SAVE_FLAG_SCREENSHOTS, error_not_used)) return FALSE; } /* all okay */ asb_context_add_app (priv->ctx, app); nr_added++; } skip: /* add a dummy element to the AppStream metadata so that we don't keep * parsing this every time */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID) && nr_added == 0) asb_context_add_app_ignore (priv->ctx, priv->pkg); /* delete tree */ g_debug ("deleting temp files: %s", asb_package_get_name (priv->pkg)); if (!asb_utils_rmtree (priv->tmpdir, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to delete tree: %s", error->message); goto out; } /* write log */ g_debug ("writing log: %s", asb_package_get_name (priv->pkg)); if (!asb_package_log_flush (priv->pkg, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to write package log: %s", error->message); goto out; } out: /* clear loaded resources */ asb_package_close (priv->pkg, NULL); asb_package_clear (priv->pkg, ASB_PACKAGE_ENSURE_DEPS | ASB_PACKAGE_ENSURE_FILES); g_list_free_full (apps, (GDestroyNotify) g_object_unref); return TRUE; }
int admin_configure_flush_to_file( chassis* srv ) { GString* new_str = NULL; GString* backends_str = NULL; GString* r_backends_str = NULL; // gint backends_cnt = 0; // gint r_backends_cnt = 0; gchar buf[65535]; gchar plugins_buf[1000]; guint i; chassis_plugin* plugin; chassis_plugin* admin_plugin = NULL; chassis_plugin* proxy_plugin = NULL; // network_backend_t* backend = NULL; // struct chassis_proxy_plugin_config* proxy_config; FILE* ini_file = NULL; int ret; if (!srv->default_file) return EC_ADMIN_RELOAD_NO_CONS_FILE; new_str = g_string_new_len(NULL, 100000); g_string_append(new_str, ini_str_header); g_assert(srv->modules->len <= 2); //find plugins for (i = 0; i < srv->modules->len; ++i) { plugin = g_ptr_array_index(srv->modules, i); if (strcmp(plugin->name, "admin") == 0) admin_plugin = plugin; else if (strcmp(plugin->name, "proxy") == 0) proxy_plugin = plugin; else g_assert(0); if (i == 0) strcpy(plugins_buf, plugin->name); else { strcat(plugins_buf, ", "); strcat(plugins_buf, plugin->name); } } //find_backends // for (i = 0; i < srv->priv->backends->backends->len; ++i) // { // backend = g_ptr_array_index(srv->priv->backends->backends, i); // if (backend->type == BACKEND_TYPE_RW) // { // if (backends_cnt++ == 0) // { // backends_str = g_string_new_len(NULL, 100); // g_string_append(backends_str, backend->addr->name->str); // } // else // { // g_assert(backends_str); // g_string_append(backends_str, ","); // g_string_append(backends_str, backend->addr->name->str); // } // } // else if (backend->type == BACKEND_TYPE_RO) // { // if (r_backends_cnt++ == 0) // { // r_backends_str = g_string_new_len(NULL, 100); // g_string_append(r_backends_str, backend->addr->name->str); // } // else // { // g_assert(r_backends_str); // g_string_append(r_backends_str, ","); // g_string_append(r_backends_str, backend->addr->name->str); // } // } // else // g_assert(0); // } g_assert(proxy_plugin != NULL); ///////////////////admin if (admin_plugin != NULL) { admin_plugin->get_ini_str(buf, 65535, admin_plugin->config, srv); g_string_append(new_str, buf); } ///////////////////proxy if (proxy_plugin != NULL) { proxy_plugin->get_ini_str(buf, 65535, proxy_plugin->config, srv); g_string_append(new_str, buf); } // proxy_config = (struct chassis_proxy_plugin_config*)proxy_plugin->config; // // sprintf(buf, ini_str_proxy1, // proxy_plugin ? "" : "#", proxy_plugin ? proxy_config->address : "0.0.0.0:4040", // proxy_plugin && backends_str ? "" : "#", proxy_plugin && backends_str ? backends_str->str : "ip:port", // proxy_plugin && r_backends_str ? "" : "#", proxy_plugin && r_backends_str ? r_backends_str->str : "ip:port", // proxy_plugin && proxy_config->lua_script ? "" : "#", proxy_plugin && proxy_config->lua_script ? proxy_config->lua_script : "file_name"); // // g_string_append(new_str, buf); // // sprintf(buf, ini_str_proxy2, // proxy_plugin && proxy_config->fix_bug_25371 ? "" : "#", // proxy_plugin && proxy_config->pool_change_user == 0 ? "" : "#", // proxy_plugin && proxy_config->profiling == 0 ? "" : "#", // proxy_plugin && proxy_config->start_proxy == 0 ? "" : "#"); // g_string_append(new_str, buf); ///////////////////app g_assert(srv->event_thread_count > 0); sprintf(buf, ini_str_app1, srv->base_dir_org ? "" : "#", srv->base_dir_org ? srv->base_dir_org : "base_dir_path", "", srv->event_thread_count, srv->log_file_name_org ? "" : "#", srv->log_file_name_org ? srv->log_file_name_org : "log_file_name", "", chassis_log_get_level_name(srv->log->min_lvl), "", plugins_buf, #ifndef _WIN32 srv->auto_restart ? "" : "#", srv->daemon_mode ? "" : "#"); #else "#", "#"); #endif g_string_append(new_str, buf); sprintf(buf, ini_str_app2, srv->max_files_number ? "" : "#", srv->max_files_number ? srv->max_files_number : 0, srv->lua_cpath_org ? "" : "#", srv->lua_cpath_org ? srv->lua_cpath_org : "dir_name", srv->lua_path_org ? "" : "#", srv->lua_path_org ? srv->lua_path_org : "dir_name", srv->invoke_dbg_on_crash ? "" : "#", srv->log->use_syslog ? "" : "#", srv->pid_file_org ? "" : "#", srv->pid_file_org ? srv->pid_file_org : "file_name", srv->plugin_dir_org ? "" : "#", srv->plugin_dir_org ? srv->plugin_dir_org : "dir_name", srv->user ? "" : "#", srv->user ? srv->user : "******"); g_string_append(new_str, buf); // if (backends_str) // g_string_free(backends_str, TRUE); // // if (r_backends_str) // g_string_free(r_backends_str, TRUE); g_assert (srv->default_file); ini_file = fopen(srv->default_file, "w+"); if (NULL == ini_file) { g_string_free(new_str, TRUE); g_critical("%s: Can't open ini file %s", G_STRLOC, srv->default_file); return EC_ADMIN_RELOAD_WIRTE_FILE_FAIL; } if (fprintf(ini_file, new_str->str) < 0) ret = EC_ADMIN_RELOAD_WIRTE_FILE_FAIL; else ret = EC_ADMIN_RELOAD_SUCCESS; fclose(ini_file); g_string_free(new_str, TRUE); return ret; }
static void gmdb_sql_execute_cb(GtkWidget *w, GladeXML *xml) { guint len; gchar *buf; gchar *bound_data[256]; int i; MdbSQLColumn *sqlcol; GtkTextBuffer *txtbuffer; GtkTextIter start, end; GtkWidget *textview, *combobox, *treeview; GtkTreeModel *store; /*GtkWidget *window;*/ GType *gtypes; GtkTreeIter iter; GtkTreeViewColumn *column; long row, maxrow; /* GdkCursor *watch, *pointer; */ /* need to figure out how to clock during the treeview recalc/redraw window = glade_xml_get_widget(xml, "sql_window"); watch = gdk_cursor_new(GDK_WATCH); gdk_window_set_cursor(GTK_WIDGET(window)->window, watch); gdk_cursor_unref(watch); */ /* stuff this query on the history */ textview = glade_xml_get_widget(xml, "sql_textview"); combobox = glade_xml_get_widget(xml, "sql_combo"); txtbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); len = gtk_text_buffer_get_char_count(txtbuffer); gtk_text_buffer_get_iter_at_offset (txtbuffer, &start, 0); gtk_text_buffer_get_iter_at_offset (txtbuffer, &end, len); buf = gtk_text_buffer_get_text(txtbuffer, &start, &end, FALSE); /* add to the history */ gtk_combo_box_prepend_text(GTK_COMBO_BOX(combobox), buf); gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0); /* ok now execute it */ mdb_sql_run_query(sql, buf); if (mdb_sql_has_error(sql)) { GtkWidget* dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (w)), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "%s", mdb_sql_last_error(sql)); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); mdb_sql_reset(sql); return; } treeview = glade_xml_get_widget(xml, "sql_results"); gtypes = g_malloc(sizeof(GType) * sql->num_columns); for (i=0;i<sql->num_columns;i++) gtypes[i]=G_TYPE_STRING; store = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); if (store) { while ((column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0))) { gtk_tree_view_remove_column(GTK_TREE_VIEW(treeview), column); } g_object_unref(store); } store = (GtkTreeModel*)gtk_list_store_newv(sql->num_columns, gtypes); g_free(gtypes); gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), store); GtkCellRenderer *renderer; renderer = gtk_cell_renderer_text_new(); for (i=0;i<sql->num_columns;i++) { bound_data[i] = (char *) g_malloc0(MDB_BIND_SIZE); mdb_sql_bind_column(sql, i+1, bound_data[i], NULL); sqlcol = g_ptr_array_index(sql->columns,i); column = gtk_tree_view_column_new_with_attributes(sqlcol->name, renderer, "text", i, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW (treeview), column); } maxrow = gmdb_prefs_get_maxrows(); row = 0; while(mdb_fetch_row(sql->cur_table) && (!maxrow || (row < maxrow))) { row++; gtk_list_store_append(GTK_LIST_STORE(store), &iter); for (i=0;i<sql->num_columns;i++) { gtk_list_store_set(GTK_LIST_STORE(store), &iter, i, (gchar *) bound_data[i], -1); } } /* free the memory used to bind */ for (i=0;i<sql->num_columns;i++) { g_free(bound_data[i]); } mdb_sql_reset(sql); g_free(buf); /* pointer = gdk_cursor_new(GDK_LEFT_PTR); gdk_window_set_cursor(GTK_WIDGET(window)->window, pointer); gdk_cursor_unref(pointer); */ }
static gint admin_reload_backends( network_mysqld_con* con, GPtrArray* backend_addr_str_array, gint fail_flag ) { chassis* srv; network_backends_t* backends; GPtrArray* cons; gchar* s; gchar* new_backend_addr; guint i; //gchar ip_address[MAX_IP_PORT_STRING_LEN + 1]; admin_network_addr_t* addr; GPtrArray* addr_array; gint ret = EC_ADMIN_RELOAD_SUCCESS; gboolean all_same_flag = 1; guint server_cnt = 0; guint client_cnt = 0; srv = con->srv; backends = srv->priv->backends; cons = srv->priv->cons; //for test if (fail_flag == 1000) { admin_print_all_backend_cons(con->srv); return EC_ADMIN_RELOAD_SUCCESS; } if (backend_addr_str_array->len != backends->backends->len) { g_critical("%s: Number of refresh backends num is not matched, new backends :%d, orignal backends : %d", G_STRLOC, backend_addr_str_array->len , backends->backends->len); return EC_ADMIN_RELOAD_FAIL; } if (fail_flag != 0 && fail_flag != 1) { g_critical("%s: Fail flag of refresh backends must be 0 or 1, but the flag is %d", G_STRLOC, fail_flag); return EC_ADMIN_RELOAD_FAIL; } addr_array = g_ptr_array_new(); /* 1. 测试DR连通性 */ for (i = 0; i < backend_addr_str_array->len; ++i) { new_backend_addr = g_ptr_array_index(backend_addr_str_array, i); addr = g_new0(admin_network_addr_t, 1); g_ptr_array_add(addr_array, addr); s = strchr(new_backend_addr, ':'); if (NULL != s) { gint len; char * port_err = NULL; network_backend_t* backend; backend = g_ptr_array_index(backends->backends, i); //check whether all backends are same //to do check backend:127.0.0.1:3306, addr:ip:3306? if (all_same_flag && g_strcasecmp(new_backend_addr, backend->addr->name->str) != 0 || backend->state == BACKEND_STATE_DOWN) { all_same_flag = 0; } len = s - new_backend_addr; if (len <= MAX_IP_PORT_STRING_LEN) { memcpy(addr->ip_address, new_backend_addr, len); addr->ip_address[len] = '\0'; addr->port = strtoul(s + 1, &port_err, 10); } if (len > MAX_IP_PORT_STRING_LEN || *(s + 1) == '\0') { g_critical("%s: Reload IP-address has to be in the form [<ip>][:<port>], is '%s'. No port number", G_STRLOC, new_backend_addr); ret = EC_ADMIN_RELOAD_FAIL; } else if (*port_err != '\0') { g_critical("%s: Reload IP-address has to be in the form [<ip>][:<port>], is '%s'. Failed to parse the port at '%s'", G_STRLOC, new_backend_addr, port_err); ret = EC_ADMIN_RELOAD_FAIL; } else { addr->addr = network_address_new(); if (network_address_set_address_ip(addr->addr, addr->ip_address, addr->port)) { g_critical("%s: Reload IP-address %s : %d error", G_STRLOC, addr->ip_address, addr->port); ret = EC_ADMIN_RELOAD_FAIL; } //ping the ip address and port; //ret = network_address_set_address_ip(addr, ip_address, port); //to do } } else ret = EC_ADMIN_RELOAD_FAIL; if (EC_ADMIN_RELOAD_FAIL == ret) { g_ptr_array_free_all(addr_array, admin_network_addr_free); return ret; } } //backends are same if (all_same_flag) { g_ptr_array_free_all(addr_array, admin_network_addr_free); return EC_ADMIN_RELOAD_SUCCESS; } /* 2. 置当前所有backends为down */ g_mutex_lock(backends->backends_mutex); for (i = 0; i < backends->backends->len; ++i) { network_backend_t* backend; backend = g_ptr_array_index(backends->backends, i); backend->state = BACKEND_STATE_DOWN; } g_mutex_unlock(backends->backends_mutex); /* 3. 当前backend为新地址 */ g_mutex_lock(backends->backends_mutex); for (i = 0; i < backends->backends->len; ++i) { network_backend_t* backend; backend = g_ptr_array_index(backends->backends, i); addr = g_ptr_array_index(addr_array, i); network_address_copy(backend->addr, addr->addr); // backend->addr->name->len = 0; /* network refresh name */ // // if (network_address_set_address_ip(backend->addr, addr->ip_address, addr->port)) // { // g_critical("%s: Reload IP-address %s : %d error" // G_STRLOC, addr->ip_address, addr->port); // ret = EC_ADMIN_RELOAD_FAIL; // // break; // } } g_mutex_unlock(backends->backends_mutex); /* 4. 关闭proxy当前所有连接 */ g_mutex_lock(srv->priv->cons_mutex); for (i = 0; i < cons->len; ++i) { con = g_ptr_array_index(cons, i); //区分了是否为backends的连接 if (con->server && con->server->backend_idx != -1) { //g_assert(con->server->fd != -1); if (con->server->fd != -1) { //closesocket(con->server->fd); con->server->fd_bak = con->server->fd; /* 后端连接暂不关闭,让其正常处理正在进行的事件 */ con->server->fd = -1; con->server->disconnect_flag = 1; server_cnt++; } //g_assert(con->client && con->client->fd != -1); if (con->client && con->client->fd != -1) { // int c_fd = con->client->fd; // con->client->fd = -1; // closesocket(c_fd); /* 需主动关闭前端fd,防止前端一直等待,但会导致con资源没有释放 */ client_cnt++; } /* 以上操作可能产生一种情况:客户端请求已在DB执行成功,但前端认为连接已断开 */ switch(con->state) { case CON_STATE_CLOSE_CLIENT: case CON_STATE_CLOSE_SERVER: case CON_STATE_SEND_ERROR: case CON_STATE_ERROR: break; case CON_STATE_INIT: case CON_STATE_CONNECT_SERVER: case CON_STATE_READ_HANDSHAKE: case CON_STATE_SEND_HANDSHAKE: case CON_STATE_READ_AUTH: case CON_STATE_SEND_AUTH: case CON_STATE_READ_AUTH_RESULT: case CON_STATE_SEND_AUTH_RESULT: case CON_STATE_READ_AUTH_OLD_PASSWORD: case CON_STATE_SEND_AUTH_OLD_PASSWORD: break; case CON_STATE_READ_QUERY: case CON_STATE_SEND_QUERY: break; case CON_STATE_READ_QUERY_RESULT: case CON_STATE_SEND_QUERY_RESULT: // //需要主动关闭连接 // if (fail_flag == 1) // { // if (con->client->fd != -1) // { // closesocket(con->client->fd); // con->client->fd = -1; // } // } break; case CON_STATE_READ_LOCAL_INFILE_DATA: case CON_STATE_SEND_LOCAL_INFILE_DATA: case CON_STATE_READ_LOCAL_INFILE_RESULT: case CON_STATE_SEND_LOCAL_INFILE_RESULT: break; } } } g_message("%s reload backends: connection count %d, close server count %d, close client count %d", G_STRLOC, srv->priv->cons->len, server_cnt, client_cnt); g_mutex_unlock(srv->priv->cons_mutex); if (ret != EC_ADMIN_RELOAD_SUCCESS) goto destroy_end; /* 5. 再把后端状态置为unknown,接收新连接 */ g_mutex_lock(backends->backends_mutex); for (i = 0; i < backends->backends->len; ++i) { network_backend_t* backend; backend = g_ptr_array_index(backends->backends, i); backend->state = BACKEND_STATE_UNKNOWN; } g_mutex_unlock(backends->backends_mutex); /* 6. 刷新配置 */ ret = admin_configure_flush_to_file(srv); destroy_end: g_ptr_array_free_all(addr_array, admin_network_addr_free); return ret; }
/* callbacks */ static void gmdb_sql_write_rslt_cb(GtkWidget *w, GladeXML *xml) { /* We need to re-run the whole query because some information is not stored * in the TreeStore, such as column types. */ gchar *file_path; GladeXML *sql_xml; GtkWidget *filesel, *dlg; FILE *outfile; int i; int need_headers = 0; gchar delimiter[11]; gchar quotechar[5]; gchar escape_char[5]; int bin_mode; gchar lineterm[5]; guint len; gchar *buf; GtkTextIter start, end; GtkTextBuffer *txtbuffer; GtkWidget *textview; char **bound_values; int *bound_lens; MdbSQLColumn *sqlcol; long row; char *value; size_t length; MdbTableDef *table; MdbColumn *col = NULL; gmdb_export_get_delimiter(xml, delimiter, sizeof(delimiter)); gmdb_export_get_lineterm(xml, lineterm, sizeof(lineterm)); gmdb_export_get_quotechar(xml, quotechar, sizeof(quotechar)); gmdb_export_get_escapechar(xml, escape_char, sizeof(escape_char)); bin_mode = gmdb_export_get_binmode(xml); need_headers = gmdb_export_get_headers(xml); file_path = gmdb_export_get_filepath(xml); if ((outfile=fopen(file_path, "w"))==NULL) { dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (w)), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, _("Unable to open file.")); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); return; } /* Get SQL */ filesel = glade_xml_get_widget (xml, "export_dialog"); sql_xml = g_object_get_data(G_OBJECT(filesel), "sql_xml"); //printf("sql_xml %p\n",sql_xml); textview = glade_xml_get_widget(sql_xml, "sql_textview"); txtbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); len = gtk_text_buffer_get_char_count(txtbuffer); gtk_text_buffer_get_iter_at_offset (txtbuffer, &start, 0); gtk_text_buffer_get_iter_at_offset (txtbuffer, &end, len); buf = gtk_text_buffer_get_text(txtbuffer, &start, &end, FALSE); /* ok now execute it */ mdb_sql_run_query(sql, buf); if (mdb_sql_has_error(sql)) { GtkWidget* dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (w)), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, "%s", mdb_sql_last_error(sql)); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); mdb_sql_reset(sql); fclose(outfile); gtk_widget_destroy(filesel); return; } bound_values = (char **) g_malloc(sql->num_columns * sizeof(char *)); bound_lens = (int *) g_malloc(sql->num_columns * sizeof(int)); for (i=0; i<sql->num_columns; i++) { /* bind columns */ bound_values[i] = (char *) g_malloc0(MDB_BIND_SIZE); mdb_sql_bind_column(sql, i+1, bound_values[i], &bound_lens[i]); /* display column titles */ if (need_headers) { if (i>0) fputs(delimiter, outfile); sqlcol = g_ptr_array_index(sql->columns,i); gmdb_print_col(outfile, sqlcol->name, quotechar[0]!='\0', MDB_TEXT, 0, quotechar, escape_char, bin_mode); } } row = 0; while (mdb_fetch_row(sql->cur_table)) { row++; for (i=0; i<sql->num_columns; i++) { if (i>0) fputs(delimiter, outfile); sqlcol = g_ptr_array_index(sql->columns, i); /* Find col matching sqlcol */ table = sql->cur_table; for (i=0; i<table->num_cols; i++) { col = g_ptr_array_index(table->columns, i); if (!strcasecmp(sqlcol->name, col->name)) break; } /* assert(i!=table->num_cols). Can't happen, already checked. */ /* Don't quote NULLs */ if (bound_lens[i] && sqlcol->bind_type != MDB_OLE) { if (col->col_type == MDB_OLE) { value = mdb_ole_read_full(mdb, col, &length); } else { value = bound_values[i]; length = bound_lens[i]; } gmdb_print_col(outfile, value, quotechar[0]!='\0', col->col_type, length, quotechar, escape_char, bin_mode); if (col->col_type == MDB_OLE) free(value); } } fputs(lineterm, outfile); } /* free the memory used to bind */ for (i=0; i<sql->num_columns; i++) { g_free(bound_values[i]); } mdb_sql_reset(sql); g_free(buf); fclose(outfile); dlg = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (w)), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, _("%ld rows successfully exported."), row); gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); gtk_widget_destroy(filesel); }
static gboolean _pygi_closure_convert_arguments (PyGIInvokeState *state, PyGIClosureCache *closure_cache) { PyGICallableCache *cache = (PyGICallableCache *) closure_cache; gssize n_in_args = 0; gssize i; for (i = 0; i < _pygi_callable_cache_args_len (cache); i++) { PyGIArgCache *arg_cache; arg_cache = g_ptr_array_index (cache->args_cache, i); if (arg_cache->direction & PYGI_DIRECTION_TO_PYTHON) { PyObject *value; if (cache->user_data_index == i) { if (state->user_data == NULL) { /* user_data can be NULL for connect functions which don't accept * user_data or as the default for user_data in the middle of function * arguments. */ Py_INCREF (Py_None); value = Py_None; } else { /* Extend the callbacks args with user_data as variable args. */ gssize j, user_data_len; PyObject *py_user_data = state->user_data; if (!PyTuple_Check (py_user_data)) { PyErr_SetString (PyExc_TypeError, "expected tuple for callback user_data"); return FALSE; } user_data_len = PyTuple_Size (py_user_data); _PyTuple_Resize (&state->py_in_args, state->n_py_in_args + user_data_len - 1); for (j = 0; j < user_data_len; j++, n_in_args++) { value = PyTuple_GetItem (py_user_data, j); Py_INCREF (value); PyTuple_SET_ITEM (state->py_in_args, n_in_args, value); } /* We can assume user_data args are never going to be inout, * so just continue here. */ continue; } } else if (arg_cache->meta_type != PYGI_META_ARG_TYPE_PARENT) { continue; } else { value = arg_cache->to_py_marshaller (state, cache, arg_cache, &state->args[i].arg_value); if (value == NULL) { pygi_marshal_cleanup_args_to_py_parameter_fail (state, cache, i); return FALSE; } } PyTuple_SET_ITEM (state->py_in_args, n_in_args, value); n_in_args++; } } if (_PyTuple_Resize (&state->py_in_args, n_in_args) == -1) return FALSE; return TRUE; }
int bt_ctf_stream_flush(struct bt_ctf_stream *stream) { int ret = 0; size_t i; uint64_t timestamp_begin, timestamp_end, events_discarded; struct bt_ctf_field *integer = NULL; struct ctf_stream_pos packet_context_pos; if (!stream || stream->pos.fd < 0) { /* * Stream does not have an associated fd. It is, * therefore, not a stream being used to write events. */ ret = -1; goto end; } if (!stream->events->len) { goto end; } ret = bt_ctf_field_validate(stream->packet_header); if (ret) { goto end; } /* mmap the next packet */ ctf_packet_seek(&stream->pos.parent, 0, SEEK_CUR); ret = bt_ctf_field_serialize(stream->packet_header, &stream->pos); if (ret) { goto end; } /* Set the default context attributes if present and unset. */ if (!get_event_header_timestamp( ((struct bt_ctf_event *) g_ptr_array_index( stream->events, 0))->event_header, ×tamp_begin)) { ret = set_structure_field_integer(stream->packet_context, "timestamp_begin", timestamp_begin); if (ret) { goto end; } } if (!get_event_header_timestamp( ((struct bt_ctf_event *) g_ptr_array_index( stream->events, stream->events->len - 1))->event_header, ×tamp_end)) { ret = set_structure_field_integer(stream->packet_context, "timestamp_end", timestamp_end); if (ret) { goto end; } } ret = set_structure_field_integer(stream->packet_context, "content_size", UINT64_MAX); if (ret) { goto end; } ret = set_structure_field_integer(stream->packet_context, "packet_size", UINT64_MAX); if (ret) { goto end; } /* Write packet context */ memcpy(&packet_context_pos, &stream->pos, sizeof(struct ctf_stream_pos)); ret = bt_ctf_field_serialize(stream->packet_context, &stream->pos); if (ret) { goto end; } ret = bt_ctf_stream_get_discarded_events_count(stream, &events_discarded); if (ret) { goto end; } /* Unset the packet context's fields. */ ret = bt_ctf_field_reset(stream->packet_context); if (ret) { goto end; } /* Set the previous number of discarded events. */ ret = set_structure_field_integer(stream->packet_context, "events_discarded", events_discarded); if (ret) { goto end; } for (i = 0; i < stream->events->len; i++) { struct bt_ctf_event *event = g_ptr_array_index( stream->events, i); ret = bt_ctf_field_reset(event->event_header); if (ret) { goto end; } /* Write event header */ ret = bt_ctf_field_serialize(event->event_header, &stream->pos); if (ret) { goto end; } /* Write stream event context */ if (event->stream_event_context) { ret = bt_ctf_field_serialize( event->stream_event_context, &stream->pos); if (ret) { goto end; } } /* Write event content */ ret = bt_ctf_event_serialize(event, &stream->pos); if (ret) { goto end; } } /* * Update the packet total size and content size and overwrite the * packet context. * Copy base_mma as the packet may have been remapped (e.g. when a * packet is resized). */ packet_context_pos.base_mma = stream->pos.base_mma; ret = set_structure_field_integer(stream->packet_context, "content_size", stream->pos.offset); if (ret) { goto end; } ret = set_structure_field_integer(stream->packet_context, "packet_size", stream->pos.packet_size); if (ret) { goto end; } ret = bt_ctf_field_serialize(stream->packet_context, &packet_context_pos); if (ret) { goto end; } g_ptr_array_set_size(stream->events, 0); stream->flushed_packet_count++; end: bt_put(integer); return ret; }
int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) { struct trace_collection *tc; int i, ret; if (!iter || !iter_pos) return -EINVAL; switch (iter_pos->type) { case BT_SEEK_RESTORE: if (!iter_pos->u.restore) return -EINVAL; bt_heap_free(iter->stream_heap); ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; for (i = 0; i < iter_pos->u.restore->stream_saved_pos->len; i++) { struct stream_saved_pos *saved_pos; struct ctf_stream_pos *stream_pos; struct ctf_stream_definition *stream; saved_pos = &g_array_index( iter_pos->u.restore->stream_saved_pos, struct stream_saved_pos, i); stream = &saved_pos->file_stream->parent; stream_pos = &saved_pos->file_stream->pos; stream_pos->packet_seek(&stream_pos->parent, saved_pos->cur_index, SEEK_SET); /* * the timestamp needs to be restored after * packet_seek, because this function resets * the timestamp to the beginning of the packet */ stream->real_timestamp = saved_pos->current_real_timestamp; stream->cycles_timestamp = saved_pos->current_cycles_timestamp; stream_pos->offset = saved_pos->offset; stream_pos->last_offset = LAST_OFFSET_POISON; stream->current.real.begin = 0; stream->current.real.end = 0; stream->current.cycles.begin = 0; stream->current.cycles.end = 0; stream->prev.real.begin = 0; stream->prev.real.end = 0; stream->prev.cycles.begin = 0; stream->prev.cycles.end = 0; printf_debug("restored to cur_index = %" PRId64 " and " "offset = %" PRId64 ", timestamp = %" PRIu64 "\n", stream_pos->cur_index, stream_pos->offset, stream->real_timestamp); ret = stream_read_event(saved_pos->file_stream); if (ret != 0) { goto error; } /* Add to heap */ ret = bt_heap_insert(iter->stream_heap, saved_pos->file_stream); if (ret) goto error; } return 0; case BT_SEEK_TIME: tc = iter->ctx->tc; bt_heap_free(iter->stream_heap); ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; /* for each trace in the trace_collection */ for (i = 0; i < tc->array->len; i++) { struct ctf_trace *tin; struct bt_trace_descriptor *td_read; td_read = g_ptr_array_index(tc->array, i); if (!td_read) continue; tin = container_of(td_read, struct ctf_trace, parent); ret = seek_ctf_trace_by_timestamp(tin, iter_pos->u.seek_time, iter->stream_heap); /* * Positive errors are failure. Negative value * is EOF (for which we continue with other * traces). 0 is success. Note: on EOF, it just * means that no stream has been added to the * iterator for that trace, which is fine. */ if (ret != 0 && ret != EOF) goto error; } return 0; case BT_SEEK_BEGIN: tc = iter->ctx->tc; bt_heap_free(iter->stream_heap); ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; for (i = 0; i < tc->array->len; i++) { struct ctf_trace *tin; struct bt_trace_descriptor *td_read; int stream_id; td_read = g_ptr_array_index(tc->array, i); if (!td_read) continue; tin = container_of(td_read, struct ctf_trace, parent); /* Populate heap with each stream */ for (stream_id = 0; stream_id < tin->streams->len; stream_id++) { struct ctf_stream_declaration *stream; int filenr; stream = g_ptr_array_index(tin->streams, stream_id); if (!stream) continue; for (filenr = 0; filenr < stream->streams->len; filenr++) { struct ctf_file_stream *file_stream; file_stream = g_ptr_array_index( stream->streams, filenr); if (!file_stream) continue; ret = babeltrace_filestream_seek( file_stream, iter_pos, stream_id); if (ret != 0 && ret != EOF) { goto error; } if (ret == EOF) { /* Do not add EOF streams */ continue; } ret = bt_heap_insert(iter->stream_heap, file_stream); if (ret) goto error; } } } break; case BT_SEEK_LAST: { struct ctf_file_stream *cfs = NULL; tc = iter->ctx->tc; ret = seek_last_ctf_trace_collection(tc, &cfs); if (ret != 0 || !cfs) goto error; /* remove all streams from the heap */ bt_heap_free(iter->stream_heap); /* Create a new empty heap */ ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error; /* Insert the stream that contains the last event */ ret = bt_heap_insert(iter->stream_heap, cfs); if (ret) goto error; break; } default: /* not implemented */ return -EINVAL; } return 0; error: bt_heap_free(iter->stream_heap); error_heap_init: if (bt_heap_init(iter->stream_heap, 0, stream_compare) < 0) { bt_heap_free(iter->stream_heap); g_free(iter->stream_heap); iter->stream_heap = NULL; ret = -ENOMEM; } return ret; }
void WifiStatusNM::setConnectedAccessPoint(WifiAccessPoint *ap, String psk) { ScopedPointer<StringArray> cmd; for (const auto& listener : listeners) listener->handleWifiBusy(); // disconnect if no ap provided if (ap == nullptr) { NMActiveConnection *conn = nm_device_get_active_connection(nmdevice); removeNMConnection(nmdevice, conn); return; } // try to connect to ap, dispatch events on success and failure else { NMConnection *connection = NULL; NMSettingWireless *s_wifi = NULL; NMSettingWirelessSecurity *s_wsec = NULL; const char *nm_ap_path = NULL; const GPtrArray *ap_list; NMAccessPoint *candidate_ap; //FIXME: expand WifiAccessPoint struct to know which NMAccessPoint it is ap_list = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(nmdevice)); if (ap_list == NULL) return; for (int i = 0; i < ap_list->len; i++) { const char *candidate_hash; candidate_ap = (NMAccessPoint *) g_ptr_array_index(ap_list, i); candidate_hash = utils_hash_ap(nm_access_point_get_ssid(candidate_ap), nm_access_point_get_mode(candidate_ap), nm_access_point_get_flags(candidate_ap), nm_access_point_get_wpa_flags(candidate_ap), nm_access_point_get_rsn_flags(candidate_ap)); if (ap->hash == candidate_hash) { nm_ap_path = nm_object_get_path(NM_OBJECT(candidate_ap)); break; } } if (!nm_ap_path) return; connecting = true; connection = nm_connection_new(); s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); nm_connection_add_setting(connection, NM_SETTING(s_wifi)); g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid(candidate_ap), NM_SETTING_WIRELESS_HIDDEN, false, NULL); if (!psk.isEmpty()) { s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); nm_connection_add_setting(connection, NM_SETTING(s_wsec)); if (nm_access_point_get_wpa_flags(candidate_ap) == NM_802_11_AP_SEC_NONE && nm_access_point_get_rsn_flags(candidate_ap) == NM_802_11_AP_SEC_NONE) { /* WEP */ nm_setting_wireless_security_set_wep_key(s_wsec, 0, psk.toRawUTF8()); if (isValidWEPKeyFormat(psk)) g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_KEY, NULL); else if (isValidWEPPassphraseFormat(psk)) g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_PASSPHRASE, NULL); else DBG("User input invalid WEP Key type, psk.length() = " << psk.length() << ", not in [5,10,13,26]"); } else { g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk.toRawUTF8(), NULL); } } nm_client_add_and_activate_connection(nmclient, connection, nmdevice, nm_ap_path, handle_add_and_activate_finish, this); } }
int main(int argc, char *argv[]) { getopt_t *gopt = getopt_create(); getopt_add_bool (gopt, 'h', "help", 0, "Show this help"); getopt_add_bool (gopt, 't', "tokenize", 0, "Show tokenization"); getopt_add_bool (gopt, 'd', "debug", 0, "Show parsed file"); getopt_add_bool (gopt, 0, "lazy", 0, "Generate output file only if .lcm is newer"); // we only support portable declarations now. // getopt_add_bool (gopt, 0, "warn-unsafe", 1, "Warn about unportable declarations"); getopt_add_spacer(gopt, "**** C options ****"); getopt_add_bool (gopt, 'c', "c", 0, "Emit C code"); setup_c_options(gopt); getopt_add_spacer(gopt, "**** C++ options ****"); getopt_add_bool (gopt, 'x', "cpp", 0, "Emit C++ code"); setup_cpp_options(gopt); getopt_add_spacer(gopt, "**** Java options ****"); getopt_add_bool (gopt, 'j', "java", 0, "Emit Java code"); setup_java_options(gopt); getopt_add_spacer(gopt, "**** Python options ****"); getopt_add_bool (gopt, 'p', "python", 0, "Emit Python code"); setup_python_options(gopt); getopt_add_spacer(gopt, "**** Lua options ****"); getopt_add_bool (gopt, 'l', "lua", 0, "Emit Lua code"); setup_lua_options(gopt); getopt_add_spacer(gopt, "**** C#.NET options ****"); getopt_add_bool (gopt, 0, "csharp", 0, "Emit C#.NET code"); setup_csharp_options(gopt); if (!getopt_parse(gopt, argc, argv, 1) || getopt_get_bool(gopt,"help")) { printf("Usage: %s [options] <input files>\n\n", argv[0]); getopt_do_usage(gopt); return 0; } lcmgen_t *lcm = lcmgen_create(); lcm->gopt = gopt; for (unsigned int i = 0; i < g_ptr_array_size(gopt->extraargs); i++) { char *path = (char *) g_ptr_array_index(gopt->extraargs, i); int res = lcmgen_handle_file(lcm, path); if (res) return -1; } int did_something = 0; // if they requested tokenizing (debug) output, we've done that now. Exit. if (getopt_get_bool(gopt, "tokenize")) { did_something = 1; return 0; } if (getopt_get_bool(gopt, "debug")) { did_something = 1; lcmgen_dump(lcm); } if (getopt_get_bool(gopt, "c")) { did_something = 1; if (emit_c(lcm)) { printf("An error occurred while emitting C code.\n"); } } if (getopt_get_bool(gopt, "cpp")) { did_something = 1; if (emit_cpp(lcm)) { printf("An error occurred while emitting C++ code.\n"); } } if (getopt_get_bool(gopt, "java")) { did_something = 1; if (emit_java(lcm)) { perror("An error occurred while emitting Java code.\n"); } } if (getopt_get_bool(gopt, "python")) { did_something = 1; if (emit_python(lcm)) { printf("An error occurred while emitting Python code.\n"); } } if (getopt_get_bool(gopt, "lua")) { did_something = 1; if (emit_lua(lcm)) { printf("An error occurred while emitting Lua code.\n"); } } if (getopt_get_bool(gopt, "csharp")) { did_something = 1; if (emit_csharp(lcm)) { printf("An error occurred while emitting C#.NET code.\n"); } } if (did_something == 0) { printf("No actions specified. Try --help.\n"); } return 0; }
static gboolean pp_piksl_mouse_motion(GtkWidget* widget, GdkEventMotion* event) { ppPiksl* piksl = PP_PIKSL(widget); if (piksl->lastx != -1 || piksl->lasty != -1) { ppLayer* layer = g_ptr_array_index(piksl->layers, piksl->active_layer); // Draw a line int dx = abs((int)event->x - piksl->lastx); int dy = abs((int)event->y - piksl->lasty); int sx = (piksl->lastx < (int)event->x)? 1 : -1; int sy = (piksl->lasty < (int)event->y)? 1 : -1; int err = dx-dy; int e2 = 2*err; int radius = PP_APP->pen_radius; int yy, xx; while (TRUE) { // Write the color to the raster array //*(layer->data + cairo_image_surface_get_width(layer->surface) //* (int)(piksl->lasty/piksl->zoom) //+ (int)(piksl->lastx/piksl->zoom)) = PP_APP->color1; for(yy=-radius; yy<=radius; yy++) for(xx=-radius; xx<=radius; xx++) if(xx*xx+yy*yy <= radius*radius) //setpixel(origin.x+xx, origin.y+yy); *pp_layer_pixel(layer, (int)(piksl->lastx/piksl->zoom)+xx, (int)(piksl->lasty/piksl->zoom)+yy) = PP_APP->color1; if (piksl->lastx == (int)event->x && piksl->lasty == (int)event->y) break; e2 = 2*err; if (e2 > -dy) { err -= dy; piksl->lastx += sx; } if (e2 < dx) { err += dx; piksl->lasty += sy; } } cairo_surface_mark_dirty(layer->surface); // Ask the widget to redraw itself gtk_widget_queue_draw(widget); } piksl->lastx = (int)event->x; piksl->lasty = (int)event->y; return FALSE; }