ccsession.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // $Id$
  15. #ifndef __CCSESSION_H
  16. #define __CCSESSION_H 1
  17. #include <string>
  18. #include <config/data_def.h>
  19. #include <cc/session.h>
  20. #include <cc/data.h>
  21. class CommandSession {
  22. public:
  23. /**
  24. * Initialize a config/command session
  25. * @param module_name: The name of this module. This is not a
  26. * reference because we expect static strings
  27. * to be passed here.
  28. * @param spec_file_name: The name of the file containing the data
  29. * definition.
  30. */
  31. CommandSession(std::string spec_file_name,
  32. isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config) = NULL,
  33. isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command) = NULL
  34. ) throw (isc::cc::SessionError);
  35. int getSocket();
  36. /**
  37. * Check if there is a command or config change on the command
  38. * session. If so, the appropriate handler is called if set.
  39. * If not set, a default answer is returned.
  40. * This is a non-blocking read; if there is nothing this function
  41. * will return 0.
  42. */
  43. int check_command();
  44. /**
  45. * The config handler function should expect an ElementPtr containing
  46. * the full configuration where non-default values have been set.
  47. * Later we might want to think about more granular control
  48. * (i.e. this does not scale to for instance lists containing
  49. * 100000 zones, where the whole list is passed every time a single
  50. * thing changes)
  51. */
  52. void set_config_handler(isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config)) { config_handler_ = config_handler; };
  53. /**
  54. * Set a command handler; the function that is passed takes an
  55. * ElementPtr, pointing to a list element, containing
  56. * [ module_name, command_name, arg1, arg2, ... ]
  57. * The returned ElementPtr should look like
  58. * { "result": [ return_value, result_value ] }
  59. * result value here is optional and depends on the command
  60. *
  61. * This protocol is very likely to change.
  62. */
  63. void set_command_handler(isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command)) { command_handler_ = command_handler; };
  64. private:
  65. void read_data_definition(const std::string& filename);
  66. std::string module_name_;
  67. isc::cc::Session session_;
  68. isc::data::ModuleSpec data_definition_;
  69. isc::data::ElementPtr config_;
  70. isc::data::ElementPtr(*config_handler_)(isc::data::ElementPtr new_config);
  71. isc::data::ElementPtr(*command_handler_)(isc::data::ElementPtr command);
  72. };
  73. #endif // __CCSESSION_H
  74. // Local Variables:
  75. // mode: c++
  76. // End: