hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BaseHandler.h
Go to the documentation of this file.
1 #ifndef BASEHANDLER_H
2 #define BASEHANDLER_H
3 #include <sys/types.h>
4 #include <stdlib.h>
5 #include <string.h>
7 {
8  public:
9  BaseHandler(unsigned int id)
10  {
11  this->id = id;
12  errCode = 0;
13  errDescLen = 256;
14  errDescription = (char*)malloc(errDescLen);
15  }
16  virtual ~BaseHandler(){if(errDescription)free(errDescription);}
17  unsigned int getId(){return id;}
18  void setError(int code, const char *description)
19  {
20  errCode = code;
21  if(description)
22  {
23  size_t len = strlen(description) + 1;
24  if(len > errDescLen)
25  {
26  errDescription = (char*)realloc(errDescription, len);
27  if(errDescription == NULL)
28  {
29  return;
30  }
31  errDescLen = len;
32  }
33  memcpy(errDescription, description, len);
34  }
35  else
36  {
37  *errDescription = '\0';
38  }
39  }
40  int getError(char **description)
41  {
42  *description = errDescription;
43  return errCode;
44  }
45  virtual void* handle(char command, ...) = 0;
46  private:
47  unsigned int id;
48  char *errDescription;
49  size_t errDescLen;
50  int errCode;
51 };
52 #endif
53