00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00033 #ifndef ALP_IPC_SERVER_H
00034 #define ALP_IPC_SERVER_H
00035
00036
00037 #include <string>
00038
00039 #include <hiker/ipc.h>
00040 #include <hiker/types.h>
00041
00042
00043
00044 namespace alp {
00045
00046 namespace ipc {
00047
00048 class Message;
00049
00050 class Server
00051 {
00052 public:
00053 enum CallbackFlags
00054 {
00055 cfConnect = 0x01,
00056 cfDisconnect = 0x02,
00057 cfReceive = 0x04,
00058 cfAll = cfConnect | cfDisconnect | cfReceive
00059 };
00060
00061 Server(const char* name, AlpIpcChannelAccessMode mode, int flags = cfAll);
00062 Server(const std::string& name, AlpIpcChannelAccessMode mode, int flags = cfAll);
00063 virtual ~Server();
00064
00065 virtual alp_status_t Run();
00066
00067 alp_status_t Status() const;
00068 int Flags() const;
00069 alp_status_t Send(Message& msg);
00070
00071 uid_t GetConnectionUID() const;
00072 gid_t GetConnectionGID() const;
00073 pid_t GetConnectionPID() const;
00074
00075 protected:
00076 virtual void OnChannelConnect(AlpConnection* connection) {;}
00077 virtual void OnChannelDisconnect(AlpConnection* connection) {;}
00078 virtual void OnMessageReceived(Message& message) {;}
00079
00080 private:
00081 void Init(const char* name, AlpIpcChannelAccessMode mode);
00082
00083 static void ChannelConnectCB(AlpConnection* connection,
00084 Server* server);
00085 static void ChannelDisconnectCB(AlpConnection* connection,
00086 Server* server);
00087 static void MessageReceiveCB(AlpConnection* connection,
00088 AlpMessage* message,
00089 Server* server);
00090
00091 AlpChannel* fServerChannel;
00092 alp_status_t fStatus;
00093 int fFlags;
00094 AlpConnection* fCurrentConnection;
00095 };
00096
00097 }
00098
00099 }
00100
00101
00102
00103 #endif // ALP_IPC_SERVER_H