ffead.server.doc
MessageHandler.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * MessageHandler.h
18  *
19  * Created on: Sep 27, 2009
20  * Author: sumeet
21  */
22 
23 #ifndef MESSAGEHANDLER_H_
24 #define MESSAGEHANDLER_H_
25 #include <sstream>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <netdb.h>
34 #include <arpa/inet.h>
35 #include <sys/wait.h>
36 #include <signal.h>
37 #include "Thread.h"
38 #include "Message.h"
39 #include "Exception.h"
40 #include <iostream>
41 #include <fstream>
42 #include "StringUtil.h"
43 #include "vector"
44 #include "algorithm"
45 #include "MQueue.h"
46 #include "Server.h"
47 #include "string"
48 #include "Logger.h"
49 #include "Constants.h"
50 #include "AMEFResources.h"
51 
52 
53 #define MAXBUFLEN 1024
54 #define BACKLOG 10
55 typedef vector<unsigned char> Cont;
56 using namespace std;
58  string path;
59  Logger logger;
60 public:
61  MessageHandler(string);
63  {
64  }
65  static void trigger(string,string);
66  static void stop();
67  Server getServer(){return this->server;}
68  void setServer(Server server){this->server = server;}
69 private:
70  Server server;
71  bool running;
72  static void* service(void* arg);
73  static void init(string);
74  Message readMessageFromQ(string fileName, bool erase);
75  void writeMessageToQ(Message msg,string fileName);
76  bool tempUnSubscribe(string subs,string fileName);
77  Message readMessageFromT(string fileName,string subs);
78  void writeMessageToT(Message msg,string fileName);
79  void subscribe(string subs,string fileName);
80  void unSubscribe(string subs,string fileName);
81 };
82 
83 #endif /* MESSAGEHANDLER_H_ */