glib

dbus - register object to remote on interface NULL

可紊 提交于 2019-12-25 04:09:06
问题 I have to deal with a binary blob dbus service/server which I need to connect to via dbus (session). The introspection of the interface is as following (obtained via gdbus-codegen ). We register a function to the remote so we get notified if a message has been received by the remote which is called message_handler . That happens as a response on a send_message command which I pass via dbus, but that works (and is thus not shown). In a java example it is done via dbus_connection.exportObject("

GLib tree insertion always inserts in the same node

杀马特。学长 韩版系。学妹 提交于 2019-12-25 00:55:12
问题 I have this very simple piece of code GTree* teste = g_tree_new(cmp); for(int i = 0; i < 10; i++){ g_tree_insert(teste, &i, &i); printf("%d", g_tree_nnodes(teste)); } The "cmp" function is int cmp(const void *a, const void* b){ int* ia = (int*)a; int* ib = (int*)b; return (*ia - *ib); } I don't understand why, but the number of nodes is always one. It seems the compare function is not being used properly, and it always asserts to 0. 回答1: The documentation on this functions says: If the given

Is it safe to use as a member function of one class in different threads?

烈酒焚心 提交于 2019-12-25 00:03:27
问题 For example: struct A { void run1() {} void run2() {} }; int main() { A a; thread t1(bind(&A::run1, ref(a))); thread t2(bind(&A::run2, ref(a))); // not joinable thread! int i; std::cin >> i; } And please look at this example http://developer.gnome.org/glibmm/unstable/thread_2thread_8cc-example.html Does the a object should be protected by mutex or something else? Is there no race condition here? 回答1: The answer depends on the class. If the methods don't share access to the same instance

Memory leak / GLib issue

本小妞迷上赌 提交于 2019-12-24 14:30:43
问题 1: /* 2: * File: xyn-playlist.c 3: * Author: Andrei Ciobanu 4: * 5: * Created on June 4, 2010, 12:47 PM 6: */ 7: 8: #include <dirent.h> 9: #include <glib.h> 10: #include <stdio.h> 11: #include <stdlib.h> 12: #include <sys/stat.h> 13: #include <unistd.h> 14: 15: /** 16: * Returns a list all the file(paths) from a directory. 17: * Returns 'NULL' if a certain error occurs. 18: * @param dir_path. 19: * @param A list of gchars* indicating what file patterns to detect. 20: */ 21: GSList *xyn_pl_get

segfault in g_slice_alloc

吃可爱长大的小学妹 提交于 2019-12-24 08:28:17
问题 I am calling a function with the following lines: void call_system_command(const char *command_params) { GString *cmd = g_string_sized_new(1024); g_string_append_printf(cmd, "/bin/bash /path/to/my/script '%s'", command_params); system(cmd->str); g_string_free(cmd, TRUE); } I am getting segfault in the line with g_string_sized_new. Backtrace from gdb shows: (gdb) bt #0 0x000000320ce56264 in g_slice_alloc () from /lib64/libglib-2.0.so.0 #1 0x000000320ce5c3db in g_string_sized_new () from /lib64

Adding custom structure to GSList with Glib

北城余情 提交于 2019-12-24 05:46:08
问题 I'm trying to add a structure to a singly linked list with the function g_slist_append(list, &structure). This seems to work (it's adding the pointer), however I can't seem to find a way to view the elements in the structure when reading the linked list. My structure looks like this: struct customstruct { int var1; int var2; char *string_1; } Then, I make a list: GSList *list = NULL; Then, I append one instance of the structure like this: struct customstruct list_entry; list_entry.var1 = 1;

Force UTF-8 encoding in glib's “g_print()”

随声附和 提交于 2019-12-24 03:51:50
问题 Short question: Is there a way to force glib's g_print() to use UTF-8 encoding? The problem I hit is that g_print() seems to do character set conversion based on the return value of g_get_charset(). Now the documentation unfortunately mentions On Windows the character set returned by this function is the so-called system default ANSI code-page. However nowadays modern consoles are available: MSYS consoles typically support (and use) UTF-8 by default and even the default Windows console can be

Fetch a file from web using GLib/GIO from C

旧巷老猫 提交于 2019-12-23 08:33:29
问题 With what function should I fetch a file from the web using GLib/GIO libs? If my file is from: gchar *path = "http://xxx.yyyServer/sharing/temp.txt" What should I do to download it? For the local files I simply use C libraries like fopen and fread. How should I do the above? There is unfortunately no examples of file handling in the Tutorials. I can only see a File chooser from File Dialog boxes. UPDATED WITH WORKING CODE FROM COMMENTS: The code below works for binary files of unknown sizes.

Absolute path of executable start directory

房东的猫 提交于 2019-12-23 04:43:31
问题 I am trying to figure out how to grab the start directory for my program. I am using C and have access to GLib. On the Linux side it is easy, g_get_current_directory as soon as the program is launched, and store this value for later use. I tried using the same method on windows but g_get_current_directory returns whatever %APPDATA% resolves to. Any ideas on how I can grab the starting directory using C? Thanks, 回答1: Not in standard C (unless there's something new in C99). C itself doesn't

C++ UTF-8 lightweight & permissive code?

半城伤御伤魂 提交于 2019-12-23 03:24:11
问题 Anyone know of a more permissive license (MIT / public domain) version of this: http://library.gnome.org/devel/glibmm/unstable/classGlib_1_1ustring.html ('drop-in' replacement for std::string thats UTF-8 aware) Lightweight, does everything I need and even more (doubt I'll use the UTF-XX conversions even) I really don't want to be carrying ICU around with me. 回答1: std::string is fine for UTF-8 storage. If you need to analyze the text itself, the UTF-8 awareness will not help you much as there