arguments.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearman server and library
  4. * Copyright (C) 2011 DataDifferential All rights reserved.
  5. *
  6. * Use and distribution licensed under the BSD license. See
  7. * the COPYING file in the parent directory for full text.
  8. */
  9. #include <config.h>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <string>
  13. #include <vector>
  14. #include <iostream>
  15. #include <unistd.h>
  16. #ifdef HAVE_GETOPT_H
  17. #include <getopt.h>
  18. #endif
  19. #include <libgearman/gearman.h>
  20. #include "arguments.h"
  21. namespace gearman_client
  22. {
  23. Args::Args(int p_argc, char *p_argv[]) :
  24. _host(NULL),
  25. _port(0),
  26. _count(0),
  27. _unique(NULL),
  28. _job_per_newline(false),
  29. _strip_newline(false),
  30. _worker(false),
  31. _suppress_input(false),
  32. _prefix(false),
  33. _background(false),
  34. _daemon(false),
  35. _usage(false),
  36. _is_error(false),
  37. _priority(GEARMAN_JOB_PRIORITY_NORMAL),
  38. _timeout(-1),
  39. argv(p_argv),
  40. _error(0)
  41. {
  42. init(p_argc);
  43. }
  44. Args::~Args()
  45. {
  46. }
  47. void Args::init(int argc)
  48. {
  49. int c;
  50. opterr= 0;
  51. while ((c = getopt(argc, argv, "bc:f:h:HILnNp:Pst:u:wi:d")) != -1)
  52. {
  53. switch(c)
  54. {
  55. case 'b':
  56. _background= true;
  57. break;
  58. case 'c':
  59. _count= static_cast<uint32_t>(atoi(optarg));
  60. break;
  61. case 'd':
  62. _daemon= true;
  63. break;
  64. case 'f':
  65. add(optarg);
  66. break;
  67. case 'h':
  68. _host= optarg;
  69. break;
  70. case 'i':
  71. _pid_file= optarg;
  72. break;
  73. case 'I':
  74. _priority= GEARMAN_JOB_PRIORITY_HIGH;
  75. break;
  76. case 'L':
  77. _priority= GEARMAN_JOB_PRIORITY_LOW;
  78. break;
  79. case 'n':
  80. _job_per_newline= true;
  81. break;
  82. case 'N':
  83. _job_per_newline= true;
  84. _strip_newline= true;
  85. break;
  86. case 'p':
  87. _port= static_cast<in_port_t>(atoi(optarg));
  88. break;
  89. case 'P':
  90. _prefix= true;
  91. break;
  92. case 's':
  93. _suppress_input= true;
  94. break;
  95. case 't':
  96. _timeout= atoi(optarg);
  97. break;
  98. case 'u':
  99. _unique= optarg;
  100. break;
  101. case 'w':
  102. _worker= true;
  103. break;
  104. case 'H':
  105. _usage= true;
  106. return;
  107. default:
  108. _is_error= true;
  109. return;
  110. }
  111. }
  112. argv+= optind;
  113. }
  114. } // namespace gearman_client