You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

option_parser.h 2.5 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_SERVING_OPTION_PARSER_H_
  17. #define MINDSPORE_SERVING_OPTION_PARSER_H_
  18. #include <string>
  19. #include <vector>
  20. #include <memory>
  21. namespace mindspore {
  22. namespace serving {
  23. struct Arguments {
  24. int32_t grpc_port = 5500;
  25. int32_t rest_api_port = 5501;
  26. std::string grpc_socket_path;
  27. std::string ssl_config_file;
  28. int32_t poll_model_wait_seconds = 1;
  29. std::string model_name;
  30. std::string model_path;
  31. std::string device_type = "Ascend";
  32. int32_t device_id = 0;
  33. };
  34. class Option {
  35. public:
  36. Option(const std::string &name, int32_t *default_point, const std::string &usage);
  37. Option(const std::string &name, bool *default_point, const std::string &usage);
  38. Option(const std::string &name, std::string *default_point, const std::string &usage);
  39. Option(const std::string &name, float *default_point, const std::string &usage);
  40. ~Option() = default;
  41. private:
  42. friend class Options;
  43. bool ParseInt32(std::string *arg);
  44. bool ParseBool(std::string *arg);
  45. bool ParseString(std::string *arg);
  46. bool ParseFloat(std::string *arg);
  47. bool Parse(std::string *arg);
  48. std::string name_;
  49. enum { MS_TYPE_INT32, MS_TYPE_BOOL, MS_TYPE_STRING, MS_TYPE_FLOAT } type_;
  50. int32_t *int32_default_;
  51. bool *bool_default_;
  52. std::string *string_default_;
  53. float *float_default_;
  54. std::string usage_;
  55. };
  56. class Options {
  57. public:
  58. ~Options() = default;
  59. Options(const Options &) = delete;
  60. Options &operator=(const Options &) = delete;
  61. static Options &Instance();
  62. bool ParseCommandLine(int argc, char **argv);
  63. void Usage();
  64. std::shared_ptr<Arguments> GetArgs() { return args_; }
  65. private:
  66. Options();
  67. void CreateOptions();
  68. bool CheckOptions();
  69. static std::shared_ptr<Options> inst_;
  70. std::string usage_;
  71. std::vector<Option> options_;
  72. std::shared_ptr<Arguments> args_;
  73. };
  74. } // namespace serving
  75. } // namespace mindspore
  76. #endif