esl_oop.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2007-2014, Anthony Minessale II
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of the original author; nor the names of any contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  25. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef _ESL_OOP_H_
  34. #define _ESL_OOP_H_
  35. #include <esl.h>
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #define this_check(x) do { if (!this) { esl_log(ESL_LOG_ERROR, "object is not initalized\n"); return x;}} while(0)
  40. #define this_check_void() do { if (!this) { esl_log(ESL_LOG_ERROR, "object is not initalized\n"); return;}} while(0)
  41. class ESLevent {
  42. private:
  43. esl_event_header_t *hp;
  44. public:
  45. esl_event_t *event;
  46. char *serialized_string;
  47. int mine;
  48. ESLevent(const char *type, const char *subclass_name = NULL);
  49. ESLevent(esl_event_t *wrap_me, int free_me = 0);
  50. ESLevent(ESLevent *me);
  51. virtual ~ESLevent();
  52. const char *serialize(const char *format = NULL);
  53. bool setPriority(esl_priority_t priority = ESL_PRIORITY_NORMAL);
  54. const char *getHeader(const char *header_name, int idx = -1);
  55. char *getBody(void);
  56. const char *getType(void);
  57. bool addBody(const char *value);
  58. bool addHeader(const char *header_name, const char *value);
  59. bool pushHeader(const char *header_name, const char *value);
  60. bool unshiftHeader(const char *header_name, const char *value);
  61. bool delHeader(const char *header_name);
  62. const char *firstHeader(void);
  63. const char *nextHeader(void);
  64. };
  65. class ESLconnection {
  66. private:
  67. esl_handle_t handle;
  68. public:
  69. ESLconnection(const char *host, const int port, const char *user, const char *password);
  70. ESLconnection(const char *host, const int port, const char *password);
  71. ESLconnection(const char *host, const char *port, const char *user, const char *password);
  72. ESLconnection(const char *host, const char *port, const char *password);
  73. ESLconnection(int socket);
  74. virtual ~ESLconnection();
  75. int socketDescriptor();
  76. int connected();
  77. ESLevent *getInfo();
  78. int send(const char *cmd);
  79. ESLevent *sendRecv(const char *cmd);
  80. ESLevent *api(const char *cmd, const char *arg = NULL);
  81. ESLevent *bgapi(const char *cmd, const char *arg = NULL, const char *job_uuid = NULL);
  82. ESLevent *sendEvent(ESLevent *send_me);
  83. int sendMSG(ESLevent *send_me, const char *uuid = NULL);
  84. ESLevent *recvEvent();
  85. ESLevent *recvEventTimed(int ms);
  86. ESLevent *filter(const char *header, const char *value);
  87. int events(const char *etype, const char *value);
  88. ESLevent *execute(const char *app, const char *arg = NULL, const char *uuid = NULL);
  89. ESLevent *executeAsync(const char *app, const char *arg = NULL, const char *uuid = NULL);
  90. int setAsyncExecute(const char *val);
  91. int setEventLock(const char *val);
  92. int disconnect(void);
  93. };
  94. void eslSetLogLevel(int level);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif
  99. /* For Emacs:
  100. * Local Variables:
  101. * mode:c++
  102. * indent-tabs-mode:t
  103. * tab-width:4
  104. * c-basic-offset:4
  105. * End:
  106. * For VIM:
  107. * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
  108. */