#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define __USE_GNU
#include <fcntl.h>
#undef __USE_GNU
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <signal.h>

// Socket Address Data
#define HZSOCK_DIR						"/tmp/"
#define HZSOCK_CNAME					"chserv-"
#define HZSOCK_DNAME					"chdock-"
#define HZSOCK_SUFFIX					".sock"
#define HZSOCKNAME_MAX					50
#define DOCK_MAX_IM_NUM					10		// Max. Input Method allowed

struct __DOCK_IM_REC
{
	// Index of ime, referring the index of 'chinputime' array.
	int		im_index;
	char	im_en_name[50];
};
typedef struct __DOCK_IM_REC IMRecord;

struct __DOCK_MESSAGE
{
	// EN refer to english mode, i.e. no chinese im is using.
	// im_index : 			-1 for EN
	// For send message from chinput im_index refer to the array index of 
	// im_record, while for the message from docking, the index should be 
	// referring the chinputime array, which can be get from im_record field.
	// im_record_count:		Total available record, except EN
	int			message_type;
	int			im_index;
	int			im_record_count;
	IMRecord	im_record[DOCK_MAX_IM_NUM];
};
typedef struct __DOCK_MESSAGE DockMessage;

// Definition of message from client (docking)
// General Message
#define HZ_DOCK_INIT						101
#define HZ_DOCK_INIT_ACK					102
#define HZ_DOCK_QUIT						103
// Request for something
#define HZ_DOCK_REQUEST_LIST				111
#define HZ_DOCK_REPLY_LIST					112
// Notify user action
#define HZ_DOCK_CHANGE_IM					121
// IM state synchronization
#define HZ_DOCK_SYNC_QUERY					131
#define HZ_DOCK_SYNC_REPLY					132

// Declare function prototype
int chinput_net_create_socket (int *sock, const char *addr);
int chinput_net_connect_peer (int *sock, const char *addr);
int chinput_net_set_sock_attr (int sock);
int chinput_net_set_signal_handler (int signum, void *hdlr);
int chinput_net_clear_socket (char *message, int csock, int dsock);
