offload_env.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. Copyright (c) 2014-2016 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. #include "offload_util.h"
  30. // data structure and routines to parse MIC user environment and pass to MIC
  31. enum MicEnvVarKind
  32. {
  33. c_no_mic, // not MIC env var
  34. c_mic_var, // for <mic-prefix>_<var>
  35. c_mic_card_var, // for <mic-prefix>_<card-number>_<var>
  36. c_mic_card_env // for <mic-prefix>_<card-number>_ENV
  37. };
  38. struct DLL_LOCAL MicEnvVar {
  39. public:
  40. MicEnvVar() : prefix(0) {}
  41. ~MicEnvVar();
  42. void analyze_env_var(char *env_var_string);
  43. char** create_environ_for_card(int card_num);
  44. MicEnvVarKind get_env_var_kind(
  45. char *env_var_string,
  46. int *card_number,
  47. char **env_var_name,
  48. int *env_var_name_length,
  49. char **env_var_def
  50. );
  51. void add_env_var(
  52. int card_number,
  53. char *env_var_name,
  54. int env_var_name_length,
  55. char *env_var_def
  56. );
  57. void set_prefix(const char *pref) {
  58. prefix = (pref && *pref != '\0') ? pref : 0;
  59. }
  60. struct VarValue {
  61. public:
  62. char* env_var;
  63. int length;
  64. char* env_var_value;
  65. VarValue(char* var, int ln, char* value)
  66. {
  67. env_var = var;
  68. length = ln;
  69. env_var_value = value;
  70. }
  71. ~VarValue();
  72. };
  73. struct CardEnvVars {
  74. public:
  75. int card_number;
  76. std::list<struct VarValue*> env_vars;
  77. CardEnvVars() { card_number = any_card; }
  78. CardEnvVars(int num) { card_number = num; }
  79. ~CardEnvVars();
  80. void add_new_env_var(int number, char *env_var, int length,
  81. char *env_var_value);
  82. VarValue* find_var(char* env_var_name, int env_var_name_length);
  83. };
  84. static const int any_card;
  85. private:
  86. void mic_parse_env_var_list(int card_number, char *env_var_def);
  87. CardEnvVars* get_card(int number);
  88. const char *prefix;
  89. std::list<struct CardEnvVars *> card_spec_list;
  90. CardEnvVars common_vars;
  91. };
  92. #endif // OFFLOAD_ENV_H_INCLUDED