main.cc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (C) 2013 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. #include <config.h>
  15. #include <d2/d2_log.h>
  16. #include <log/logger_support.h>
  17. #include <log/logger_manager.h>
  18. #include <iostream>
  19. using namespace isc::d2;
  20. using namespace std;
  21. /// This file contains entry point (main() function) for standard DHCP-DDNS
  22. /// process, b10-d2, component for BIND10 framework. It parses command-line
  23. /// arguments and instantiates D2Controller class that is responsible for
  24. /// establishing connection with msgq (receiving commands and configuration)
  25. /// and also creating D2Server object as well.
  26. ///
  27. /// For detailed explanation or relations between main(), D2Controller,
  28. /// D2Server and other classes, see \ref d2Session.
  29. namespace {
  30. const char* const D2_NAME = "b10-d2";
  31. void
  32. usage() {
  33. cerr << "Usage: " << D2_NAME << " [-v] [-s]" << endl;
  34. cerr << " -s: stand-alone mode (don't connect to BIND10)" << endl;
  35. cerr << " -v: verbose output (only when in stand-alone mode" << endl;
  36. exit(EXIT_FAILURE);
  37. }
  38. } // end of anonymous namespace
  39. int
  40. main(int argc, char* argv[]) {
  41. int ch;
  42. // @TODO NOTE these parameters are preliminary only. They are here to
  43. // for symmetry with the DHCP servers. They may or may not
  44. // become part of the eventual implementation.
  45. bool stand_alone = false; // Should be connect to BIND10 msgq?
  46. bool verbose_mode = false; // Should server be verbose?
  47. while ((ch = getopt(argc, argv, "vsp:")) != -1) {
  48. switch (ch) {
  49. case 'v':
  50. verbose_mode = true;
  51. break;
  52. case 's':
  53. stand_alone = true;
  54. break;
  55. default:
  56. usage();
  57. }
  58. }
  59. // Check for extraneous parameters.
  60. if (argc > optind) {
  61. usage();
  62. }
  63. // Initialize logging. If verbose, we'll use maximum verbosity.
  64. // If standalone is enabled, do not buffer initial log messages
  65. // Verbose logging is only enabled when in stand alone mode.
  66. isc::log::initLogger(D2_NAME,
  67. ((verbose_mode && stand_alone)
  68. ? isc::log::DEBUG : isc::log::INFO),
  69. isc::log::MAX_DEBUG_LEVEL, NULL, !stand_alone);
  70. LOG_INFO(d2_logger, D2CTL_STARTING);
  71. // For now we will sleep awhile to simulate doing something.
  72. // Without at least a sleep, the process will start, exit and be
  73. // restarted by Bind10/Init endlessley in a rapid succession.
  74. sleep(1000);
  75. LOG_INFO(d2_logger, D2CTL_STOPPING);
  76. return (EXIT_SUCCESS);
  77. }