DDS  ver. 3.6
EnvProp.h
Go to the documentation of this file.
1 // Copyright 2015 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef DDSENVPROP_H_
6 #define DDSENVPROP_H_
7 
8 // STD
9 #include <cstdlib>
10 #include <string>
11 
12 namespace dds
13 {
15  enum EEnvProp
16  {
28  };
29 
38  template <EEnvProp T>
39  inline typename std::enable_if<T == task_id || T == dds_slot_id, uint64_t>::type env_prop()
40  {
41  size_t ret(0);
42  std::string envName;
43  switch (T)
44  {
45  case task_id:
46  envName = "DDS_TASK_ID";
47  break;
48  case dds_slot_id:
49  envName = "DDS_SLOT_ID";
50  break;
51  default:
52  return 0;
53  }
54  const char* env = std::getenv(envName.c_str());
55  if (nullptr == env)
56  return ret;
57 
58  try
59  {
60  ret = std::stoull(env);
61  }
62  catch (...)
63  {
64  return 0;
65  }
66 
67  return ret;
68  }
69 
78  template <EEnvProp T>
79  inline typename std::enable_if<T == task_index || T == collection_index, size_t>::type env_prop()
80  {
81  size_t ret(0);
82  std::string envName;
83  switch (T)
84  {
85  case task_index:
86  envName = "DDS_TASK_INDEX";
87  break;
88  case collection_index:
89  envName = "DDS_COLLECTION_INDEX";
90  break;
91  default:
92  return 0;
93  }
94  const char* env = std::getenv(envName.c_str());
95  if (nullptr == env)
96  return ret;
97 
98  try
99  {
100  ret = std::stoi(env);
101  }
102  catch (...)
103  {
104  return 0;
105  }
106 
107  return ret;
108  }
109 
118  template <EEnvProp T>
119  inline typename std::enable_if<T == task_name || T == collection_name || T == group_name || T == dds_location ||
120  T == task_path || T == dds_session_id,
121  std::string>::type
123  {
124  std::string envName;
125  switch (T)
126  {
127  case task_name:
128  envName = "DDS_TASK_NAME";
129  break;
130  case collection_name:
131  envName = "DDS_COLLECTION_NAME";
132  break;
133  case group_name:
134  envName = "DDS_GROUP_NAME";
135  break;
136  case dds_location:
137  envName = "DDS_LOCATION";
138  break;
139  case task_path:
140  envName = "DDS_TASK_PATH";
141  break;
142  case dds_session_id:
143  envName = "DDS_SESSION_ID";
144  break;
145  default:
146  return 0;
147  }
148  const char* env = std::getenv(envName.c_str());
149  if (nullptr == env)
150  return "";
151 
152  return std::string(env);
153  }
154 }; // namespace dds
155 
156 #endif /*DDSENVPROP_H_*/
std::enable_if< T==task_id||T==dds_slot_id, uint64_t >::type env_prop()
The function returns a value for a given environment property.
Definition: EnvProp.h:39
associated with $DDS_COLLECTION_NAME - ID of the parent collection.
Definition: EnvProp.h:23
associated with $DDS_TASK_PATH - full path to the user task, for example, main/group1/collection_12/t...
Definition: EnvProp.h:20
associated with $DDS_SLOT_ID - slot ID
Definition: EnvProp.h:27
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13
associated with $DDS_TASK_ID environment variable.
Definition: EnvProp.h:17
associated with $DDS_GROUP_NAME - ID of the parent group.
Definition: EnvProp.h:24
EEnvProp
a list of envioronment properties
Definition: EnvProp.h:15
associated with $DDS_TASK_NAME - ID of the task.
Definition: EnvProp.h:19
associated with $DDS_SESSION_ID - session ID of the DDS.
Definition: EnvProp.h:26
associated with $DDS_TASK_INDEX environment variable.
Definition: EnvProp.h:18
associated with $DDS_COLLECTION_INDEX environemnt variable.
Definition: EnvProp.h:22
associated with $DDS_LOCATION environemnt variable.
Definition: EnvProp.h:25