Skip to content

Instantly share code, notes, and snippets.

@yongboy
Last active December 14, 2015 23:49
Show Gist options
  • Save yongboy/5168005 to your computer and use it in GitHub Desktop.
Save yongboy/5168005 to your computer and use it in GitHub Desktop.
the full endpoint_impl.h content
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *message_type;
char *message_id;
char *endpoint;
char *message_data;
char *ori_data;
} message_fields;
typedef struct {
char *endpoint;
void (*on_init)(const char *endpoint);
void (*on_connect)(const char *sessionid);
void (*on_message)(const char *sessionid, const message_fields *msg_fields);
void (*on_json_message)(const char *sessionid, const message_fields *msg_fields);
void (*on_event)(const char *sessionid, const message_fields *msg_fields);
void (*on_other)(const char *sessionid, const message_fields *msg_fields);
void (*on_disconnect)(const char *sessionid, const message_fields *msg_fields);
void (*on_destroy)(const char *endpoint);
} endpoint_implement;
extern void send_msg(char *sessionid, char *message);
extern void broadcast_clients(char *except_sessionid, char *message);
static void on_init(const char *endpoint);
static void on_connect(const char *sessionid);
static void on_message(const char *sessionid, const message_fields *msg_fields) {
printf("on_message recevie ori msg is %s\n", msg_fields->ori_data);
}
static void on_json_message(const char *sessionid, const message_fields *msg_fields) {
printf("on_json_message recevie ori msg is %s\n", msg_fields->ori_data);
}
static void on_other(const char *sessionid, const message_fields *msg_fields) {
printf("on_other recevie ori msg is %s\n", msg_fields->ori_data);
}
static void on_event(const char *sessionid, const message_fields *msg_fields);
static void on_disconnect(const char *sessionid, const message_fields *msg_fields);
static void on_destroy(const char *endpoint);
static endpoint_implement *init_default_endpoint_implement(char *endpoint_name) {
endpoint_implement *impl_point = (endpoint_implement *)malloc(sizeof(endpoint_implement));
impl_point->endpoint = strdup(endpoint_name);
impl_point->on_init = on_init;
impl_point->on_connect = on_connect;
impl_point->on_message = on_message;
impl_point->on_json_message = on_json_message;
impl_point->on_event = on_event;
impl_point->on_other = on_other;
impl_point->on_disconnect = on_disconnect;
impl_point->on_destroy = on_destroy;
return impl_point;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment