Add event handler functionality to tg-cli

This commit is contained in:
mjentsch 2014-06-22 23:37:40 +02:00
parent d712b7e17f
commit 0945a3ca11
2 changed files with 63 additions and 3 deletions

View file

@ -4,7 +4,7 @@
EXTRA_LIBS = -lcrypto -lz -lm -lreadline
LDFLAGSTG = -L/usr/local/lib
CPPFLAGSTG = -I/usr/local/include
OBJECTSTG = ../main.o ../loop.o ../interface.o ../net.o ../mtproto-common.o ../mtproto-client.o ../queries.o ../structures.o ../binlog.o ../tools.o ../lua-tg.o ../msglog.o
OBJECTSTG = ../main.o ../loop.o ../interface.o ../net.o ../mtproto-common.o ../mtproto-client.o ../queries.o ../structures.o ../binlog.o ../tools.o ../lua-tg.o ../msglog.o ../tg-cli.o
INCLUDE = -I. -I..
#
@ -34,6 +34,7 @@ CFLAGS = \
-fPIC \
-DPURPLE_PLUGINS \
-DPIC \
-g \
$(CFLAGS_PURPLE)
LIBS_PURPLE = $(shell pkg-config --libs purple)
@ -53,7 +54,7 @@ strip: $(LIBNAME)
.PHONY: debug install
debug: CFLAGS += -g -DDEBUG
debug: $(LIBNAME)
gdb -tui pidgin
gdb -tui -ex 'break telegram-purple.c:tgprpl_login' pidgin
PLUGIN_DIR_PURPLE:=$(shell pkg-config --variable=plugindir purple)
@ -83,4 +84,4 @@ clean:
.PHONY: run
run: all install
pidgin -d | grep telegram
pidgin -d

59
tg-cli.c Executable file
View file

@ -0,0 +1,59 @@
#include <sys/types.h>
#include "mtproto-common.h"
#include "tg-cli.h"
#include "msglog.h"
/*
* Events
*/
/*
* New message received
*/
void (*on_msg_handler)(struct message *M);
void on_update_new_message(void (*on_msg)(struct message *M)) {
on_msg_handler = on_msg;
}
void event_update_new_message(struct message *M) {
if (on_msg_handler) {
on_msg_handler(M);
}
}
/*
* User allocated
*/
void (*on_user_allocated_handler)(peer_t *user);
void on_user_allocated(void (*handler)(peer_t *user)) {
on_user_allocated_handler = handler;
}
void event_user_allocated(peer_t *user) {
if (on_user_allocated_handler) {
on_user_allocated_handler(user);
}
}
/*
* Chat allocated
*/
void (*on_chat_allocated_handler)(peer_t *chat);
void on_chat_allocated(void (*handler)(peer_t *chat)) {
on_chat_allocated_handler = handler;
}
void event_chat_allocated(peer_t *chat) {
if (on_chat_allocated_handler) {
on_chat_allocated_handler(chat);
}
}
// template
//void (*on_blarg_handler)(type);
//void on_blarg(void (*handler)(type)) {
// on_blarg_handler = handler;
//}
//void event_blarg(type) {
// if (on_blarg_handler) {
// on_blarg_handler(type);
// }
//}