glib学习-- timer使用
2016-07-26 10:45
225 查看
如果之让定时器执行一次,回调函数返回false,如果返回true,会定时执行。
Makefile:
#include <stdio.h> #include <unistd.h> #include <signal.h> #include <glib.h> #define true 1 #define false 0 int id = 0; gboolean service_send_change(gpointer data) { id = 0; printf("signal aaaaaaaaaaaaa%d\n", id); return true; } gboolean service_send_changed(gpointer data) { id = 0; printf("signal iiiiiiiiiiiis %d\n", id); return true; } int main(int argc, char* argv[]) { GMainLoop* loop; if(g_thread_supported() == 0) g_thread_init(NULL); g_print("g_main_loop_new\n"); loop = g_main_loop_new(NULL, FALSE); //Ôö¼ÓÒ»¸ö¶¨Ê±Æ÷£¬100ºÁÃëÔËÐÐÒ»´Îcallback id = g_timeout_add(500,service_send_changed,NULL); g_timeout_add(100, service_send_change,NULL); g_print("g_main_loop_run\n"); g_main_loop_run(loop); g_print("g_main_loop_unref\n"); g_main_loop_unref(loop); return 0; }编译:
Makefile:
</pre><pre name="code" class="cpp">CC=gcc .PHONY:all all:test timer watch1 test: $(CC) test.c -pthread -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -pthread -lgthread-2.0 -lglib-2.0 -o test timer: $(CC) timer.c -pthread -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -pthread -lgthread-2.0 -lglib-2.0 -o timer watch1: $(CC) watch1.c -pthread -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -pthread -lgthread-2.0 -lglib-2.0 -o watch1 clean: rm test timer watch1
相关文章推荐
- 通过JQuery对页面表单操作
- 贪心 区间覆盖问题
- 关于图片分辨率
- GitLab安装后修改IP/域名
- [Cordova/Phonegap] Cordova iOS 应用在第三方输入法的键盘弹出(点击输入框)时,页面不上移,导致输入框被键盘遮挡 的解决办法
- Volley XMLRequest GsonRequest 笔记
- POJ【3411】——Hie with the Pie
- 从内核的角度看linux文件系统以及一些类似于mount命令的原理(未完)
- ECMAScript 6
- 中国剩余定理
- 移动开发中的仿真器与模拟器
- PostCSS一种更优雅、更简单的书写CSS方式
- SVN clean up问题
- 中国剩余定理
- Yii2注册js文件
- 【Mr.he原创】旅行
- java里的编码
- HDU-3746 Cyclic Nacklace(kmp专题)
- HDU 3240 Counting Binary Trees [卡特兰数] 【数论+组合数学】
- 安装APK时报“解析错误”