Initial commit
[jamendo] / branches / nota-show-app / src / pdu.h
1 #ifndef PDU_H
2 #define PDU_H
3
4 #include "notaio.h"
5 #include <stdio.h>
6
7 #define DEFAULT_SID 42
8
9 enum MessageTypes {
10         PUT_IMAGE = 's',
11         GET_IMAGE = 'g',
12         FACE_FOUND = 'f',
13         DISCONNECT = 'd',
14         QUIT = 'q'
15 };
16
17 typedef struct _ServiceMessage {
18         uns8 sigid_length;
19         uns8 sigid[2];
20         uns8 argtype;
21         uns16 arglen;
22         char argdata[0];
23 } ServiceMessage;
24
25 #define SERVICE_MESSAGE_HEADER_LEN (sizeof(struct _ServiceMessage))
26
27 typedef struct {
28         volatile int *run_check;
29         void (*log)(const char*);
30         void (*put_image)(unsigned char* img_buf, int img_size);
31         unsigned char* (*get_image)(int* img_size);
32         void (*disconnect)(int socket);
33         void (*quit)(int socket);
34         void (*face_found)(int x,int y,int r);
35         
36 } ServiceCallbacks;
37
38
39 ServiceMessage* pack_pdu(int sigid, uns8* payload, int payload_len, int* pdu_len);
40
41 HErrorCode read_smsg(HSSockID* socket, HSReceiveMode mode, ServiceCallbacks* cb);
42
43 #define LOG(str) { cb->log(str); }
44 #define LOG1(fmt,arg) { char str[256]; snprintf(str,255,fmt,arg); cb->log(str); }
45 #define LOG2(fmt,arg1,arg2) { char str[256]; snprintf(str,255,fmt,arg1,arg2); cb->log(str); }
46
47 #endif