offload_env.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. Copyright (c) 2014 Intel Corporation. All Rights Reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Intel Corporation nor the names of its
  12. contributors may be used to endorse or promote products derived
  13. from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef OFFLOAD_ENV_H_INCLUDED
  27. #define OFFLOAD_ENV_H_INCLUDED
  28. #include <list>
  29. // data structure and routines to parse MIC user environment and pass to MIC
  30. enum MicEnvVarKind
  31. {
  32. c_no_mic, // not MIC env var
  33. c_mic_var, // for <mic-prefix>_<var>
  34. c_mic_card_var, // for <mic-prefix>_<card-number>_<var>
  35. c_mic_card_env // for <mic-prefix>_<card-number>_ENV
  36. };
  37. struct MicEnvVar {
  38. public:
  39. MicEnvVar() : prefix(0) {}
  40. ~MicEnvVar();
  41. void analyze_env_var(char *env_var_string);
  42. char** create_environ_for_card(int card_num);
  43. MicEnvVarKind get_env_var_kind(
  44. char *env_var_string,
  45. int *card_number,
  46. char **env_var_name,
  47. int *env_var_name_length,
  48. char **env_var_def
  49. );
  50. void add_env_var(
  51. int card_number,
  52. char *env_var_name,
  53. int env_var_name_length,
  54. char *env_var_def
  55. );
  56. void set_prefix(const char *pref) {
  57. prefix = (pref && *pref != '\0') ? pref : 0;
  58. }
  59. struct VarValue {
  60. public:
  61. char* env_var;
  62. int length;
  63. char* env_var_value;
  64. VarValue(char* var, int ln, char* value)
  65. {
  66. env_var = var;
  67. length = ln;
  68. env_var_value = value;
  69. }
  70. ~VarValue();
  71. };
  72. struct CardEnvVars {
  73. public:
  74. int card_number;
  75. std::list<struct VarValue*> env_vars;
  76. CardEnvVars() { card_number = any_card; }
  77. CardEnvVars(int num) { card_number = num; }
  78. ~CardEnvVars();
  79. void add_new_env_var(int number, char *env_var, int length,
  80. char *env_var_value);
  81. VarValue* find_var(char* env_var_name, int env_var_name_length);
  82. };
  83. static const int any_card;
  84. private:
  85. void mic_parse_env_var_list(int card_number, char *env_var_def);
  86. CardEnvVars* get_card(int number);
  87. const char *prefix;
  88. std::list<struct CardEnvVars *> card_spec_list;
  89. CardEnvVars common_vars;
  90. };
  91. #endif // OFFLOAD_ENV_H_INCLUDED