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.4 kB

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. std::string grpc_socket_path;
  26. std::string ssl_config_file;
  27. int32_t poll_model_wait_seconds = 1;
  28. std::string model_name;
  29. std::string model_path;
  30. std::string device_type = "Ascend";
  31. int32_t device_id = 0;
  32. };
  33. class Option {
  34. public:
  35. Option(const std::string &name, int32_t *default_point, const std::string &usage);
  36. Option(const std::string &name, bool *default_point, const std::string &usage);
  37. Option(const std::string &name, std::string *default_point, const std::string &usage);
  38. Option(const std::string &name, float *default_point, const std::string &usage);
  39. private:
  40. friend class Options;
  41. bool ParseInt32(std::string *arg);
  42. bool ParseBool(std::string *arg);
  43. bool ParseString(std::string *arg);
  44. bool ParseFloat(std::string *arg);
  45. bool Parse(std::string *arg);
  46. std::string name_;
  47. enum { MS_TYPE_INT32, MS_TYPE_BOOL, MS_TYPE_STRING, MS_TYPE_FLOAT } type_;
  48. int32_t *int32_default_;
  49. bool *bool_default_;
  50. std::string *string_default_;
  51. float *float_default_;
  52. std::string usage_;
  53. };
  54. class Options {
  55. public:
  56. ~Options() = default;
  57. Options(const Options &) = delete;
  58. Options &operator=(const Options &) = delete;
  59. static Options &Instance();
  60. bool ParseCommandLine(int argc, char **argv);
  61. void Usage();
  62. std::shared_ptr<Arguments> GetArgs() { return args_; }
  63. private:
  64. Options();
  65. void CreateOptions();
  66. bool CheckOptions();
  67. static std::shared_ptr<Options> inst_;
  68. std::string usage_;
  69. std::vector<Option> options_;
  70. std::shared_ptr<Arguments> args_;
  71. };
  72. } // namespace serving
  73. } // namespace mindspore
  74. #endif