00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _MW_SERVICE_H
00022 #define _MW_SERVICE_H
00023
00024
00025 #include "mw_common.h"
00026
00027
00028
00029 struct mwChannel;
00030 struct mwService;
00031 struct mwSession;
00032 struct mwMsgChannelCreate;
00033 struct mwMsgChannelAccept;
00034 struct mwMsgChannelDestroy;
00035
00036
00038 enum mwServiceState {
00039 mwServiceState_STOPPED,
00040 mwServiceState_STOPPING,
00041 mwServiceState_STARTED,
00042 mwServiceState_STARTING,
00043 mwServiceState_ERROR,
00044 mwServiceState_UNKNOWN,
00045 };
00046
00047
00049 #define MW_SERVICE(srv) ((struct mwService *) srv)
00050
00051
00052 #define MW_SERVICE_IS_STATE(srvc, state) \
00053 (mwService_getState(MW_SERVICE(srvc)) == (state))
00054
00055 #define MW_SERVICE_IS_STOPPED(srvc) \
00056 MW_SERVICE_IS_STATE(srvc, mwServiceState_STOPPED)
00057
00058 #define MW_SERVICE_IS_STOPPING(srvc) \
00059 MW_SERVICE_IS_STATE(srvc, mwServiceState_STOPPING)
00060
00061 #define MW_SERVICE_IS_STARTED(srvc) \
00062 MW_SERVICE_IS_STATE(srvc, mwServiceState_STARTED)
00063
00064 #define MW_SERVICE_IS_STARTING(srvc) \
00065 MW_SERVICE_IS_STATE(srvc, mwServiceState_STARTING)
00066
00067
00069 #define MW_SERVICE_IS_LIVE(srvc) \
00070 (MW_SERVICE_IS_STARTING(srvc) || MW_SERVICE_IS_STARTED(srvc))
00071
00073 #define MW_SERVICE_IS_DEAD(srvc) \
00074 (MW_SERVICE_IS_STOPPING(srvc) || MW_SERVICE_IS_STOPPED(srvc))
00075
00076
00077 typedef void (*mwService_funcStart)(struct mwService *service);
00078
00079 typedef void (*mwService_funcStop)(struct mwService *service);
00080
00081 typedef void (*mwService_funcClear)(struct mwService *service);
00082
00083 typedef const char *(*mwService_funcGetName)(struct mwService *service);
00084
00085 typedef const char *(*mwService_funcGetDesc)(struct mwService *service);
00086
00088 typedef void (*mwService_funcRecvCreate)
00089 (struct mwService *service,
00090 struct mwChannel *channel,
00091 struct mwMsgChannelCreate *msg);
00092
00094 typedef void (*mwService_funcRecvAccept)
00095 (struct mwService *service,
00096 struct mwChannel *channel,
00097 struct mwMsgChannelAccept *msg);
00098
00100 typedef void (*mwService_funcRecvDestroy)
00101 (struct mwService *service,
00102 struct mwChannel *channel,
00103 struct mwMsgChannelDestroy *msg);
00104
00105 typedef void (*mwService_funcRecv)
00106 (struct mwService *service,
00107 struct mwChannel *channel,
00108 guint16 msg_type,
00109 struct mwOpaque *data);
00110
00111
00118 struct mwService {
00119
00123 guint32 type;
00124
00130 enum mwServiceState state;
00131
00134 struct mwSession *session;
00135
00138 mwService_funcGetName get_name;
00139
00142 mwService_funcGetDesc get_desc;
00143
00149 mwService_funcRecvCreate recv_create;
00150
00156 mwService_funcRecvAccept recv_accept;
00157
00163 mwService_funcRecvDestroy recv_destroy;
00164
00169 mwService_funcRecv recv;
00170
00175 mwService_funcStart start;
00176
00181 mwService_funcStop stop;
00182
00190 mwService_funcClear clear;
00191
00196 gpointer client_data;
00197
00203 GDestroyNotify client_cleanup;
00204 };
00205
00206
00211
00212
00223 void mwService_init(struct mwService *service,
00224 struct mwSession *session,
00225 guint32 service_type);
00226
00227
00230 void mwService_started(struct mwService *service);
00231
00232
00235 void mwService_stopped(struct mwService *service);
00236
00237
00246
00247
00253 void mwService_recvCreate(struct mwService *service,
00254 struct mwChannel *channel,
00255 struct mwMsgChannelCreate *msg);
00256
00257
00263 void mwService_recvAccept(struct mwService *service,
00264 struct mwChannel *channel,
00265 struct mwMsgChannelAccept *msg);
00266
00267
00273 void mwService_recvDestroy(struct mwService *service,
00274 struct mwChannel *channel,
00275 struct mwMsgChannelDestroy *msg);
00276
00277
00284 void mwService_recv(struct mwService *service,
00285 struct mwChannel *channel,
00286 guint16 msg_type,
00287 struct mwOpaque *data);
00288
00289
00291 guint32 mwService_getType(struct mwService *);
00292
00293
00295 const char *mwService_getName(struct mwService *);
00296
00297
00299 const char *mwService_getDesc(struct mwService *);
00300
00301
00303 struct mwSession *mwService_getSession(struct mwService *service);
00304
00305
00308 enum mwServiceState mwService_getState(struct mwService *service);
00309
00310
00318 void mwService_start(struct mwService *service);
00319
00320
00327 void mwService_stop(struct mwService *service);
00328
00329
00336 void mwService_free(struct mwService *service);
00337
00338
00343 void mwService_setClientData(struct mwService *service,
00344 gpointer data, GDestroyNotify cleanup);
00345
00346
00348 gpointer mwService_getClientData(struct mwService *service);
00349
00350
00353 void mwService_removeClientData(struct mwService *service);
00354
00355
00359 #endif
00360