#define PACK_SIZE 4096
class ModuleServer
{
protected:
Glib::Mutex mutex_map;
public:
virtual void call_switch(char *p_recv, char *p_send) = 0;
};
class CommunicateSer
{
private:
typedef std::pair<guint32, ModuleServer*> Ps;
struct sockaddr_in sa;
int err;
int listen_sd;
int sd;
struct sockaddr_in sa_serv;
struct sockaddr_in sa_cli;
int client_len;
std::map<guint32, ModuleServer*> map_servers;
std::map<guint32, ModuleServer*>::iterator it_map;
Glib::Mutex mutex_map;
std::queue<int> queue_sd;
Glib::Thread *p_server_thread;
Glib::Mutex mutex_sd;
public:
void reg_server(guint32 a_ser_id, ModuleServer* ap_server);
void init(){};
void listen_client();
void server();
};
class IntCalcSer :public ModuleServer
{
public:
void call_switch(char *ap_recv, char *ap_send);
void init();
protected:
struct Arg_Data
{
gint32 a;
gint32 b;
gint32 c;
};
protected:
void add(char *ap_recv, char *ap_send);
void sub(char *ap_recv, char *ap_send);
protected:
typedef void (IntCalcSer::*P_FUNC)(char *ap_recv, char *ap_send);
P_FUNC p_func;
std::map<guint32, P_FUNC> map_func;
std::map<guint32, P_FUNC>::iterator it_map_func;
typedef std::pair<guint32, P_FUNC> Ps_Func;
};
class FloatCalcSer :public ModuleServer
{
public:
void call_switch(char *ap_recv, char *ap_send);
void init();
protected:
struct Arg_Data
{
double a;
double b;
double c;
};
protected:
void add(char *ap_recv, char *ap_send);
void sub(char *ap_recv, char *ap_send);
protected:
typedef void (FloatCalcSer::*P_FUNC)(char *ap_recv, char *ap_send);
P_FUNC p_func;
std::map<guint32, P_FUNC> map_func;
std::map<guint32, P_FUNC>::iterator it_map_func;
typedef std::pair<guint32, P_FUNC> Ps_Func;
};
void CommunicateSer::reg_server(guint32 a_ser_id, ModuleServer* ap_server)
{
map_servers.insert(Ps(a_ser_id, ap_server));
}
|