common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / interface_unified / library / include / system_service / ss_system_process.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SystemServicesIf
19 /// \brief    This file supports the System Manager OS process abstraction.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 /**
23  * @file ss_system_process.h
24  */
25 /** @addtogroup BaseSystem
26  *  @{
27  */
28 /** @addtogroup system_service
29  *  @ingroup BaseSystem
30  *  @{
31  */
32 /** @addtogroup interface_unified
33  *  @ingroup system_service
34  *  @{
35  */
36 #ifndef __Process_H__  // NOLINT (build/header_guard)
37 #define __Process_H__
38
39 #include <spawn.h>
40 #include <native_service/frameworkunified_types.h>
41 #include <native_service/cl_process.h>
42 #include <system_service/ss_system_types.h>
43 #include <signal.h>
44 #include <vector>
45 #include <string>
46 #include <map>
47
48 const long lProcess_VALIDATION_VALUE = 2198645;  // NOLINT (runtime/int)
49 // Used to define a unique value that represents this class.
50 // This value is stored in the object when the object is created,
51 // and cleared when the object is destroyed.
52
53 const int iProcess_DEFAULT_PROCESS_PRIORITY = 10;
54 // This is the default process priority that all new processes will use.
55
56 const int iProcess_MAXIMUM_PROCESS_PRIORITY = 60;
57 // This is the maximum priority a process can have
58
59 const long iProcess_DEFAULT_PROCESS_FLAGS = POSIX_SPAWN_SETSCHEDULER  // NOLINT (runtime/int)
60     | POSIX_SPAWN_SETSCHEDPARAM;
61
62 // This flag field is a bit wise OR of spawning options to use when a process
63 // is created.
64
65 const int iProcess_MAXIMUM_NUMBER_OF_PROCESS_ARGUMENTS = 25;
66 // This is the maximum number of command line (i.e. argv[]) arguments we can
67 // send to a process. This includes; exectuable file name + process arguments + NULL
68
69 const int iProcess_MAXIMUM_PROCESS_NAME_LENGTH = 32;
70 // This is the maximum number of characters that a process name can be in bytes.
71
72 class Process;
73
74 typedef std::map<SS_String, Process *> ProcessMap;
75
76 /**
77  * @class TimerCtrl
78  * \~english @brief OS process
79  * \~english @par   Brief Introduction
80  *        This class is the System Manager OS process abstraction.
81  *
82  */
83 class Process {
84  public:
85   enum eProcessLoadMode {
86     WAIT,   // The invoked program is loaded into available memory, is executed,
87     // and then the original program resumes execution.
88     NOWAIT,  // Causes the current program to execute concurrently with the new child process.
89   };
90
91   enum eProcessSchedulingPolicy {
92     FIFO,  // A fixed priority scheduler in which the highest ready process runs until it
93     // blocks or is preempted by a higher priority process.
94     ROUND_ROBIN,  // The same as FIFO, except processes at the same priority level time-slice.
95     OTHER  // A general time sharing scheduler in which a process decays in priority if it
96   // consumes too much processor before blocking. It reverts to its default priority
97   // when it blocks. Should it fail to run over a 2 second period and it has decayed
98   // then it's boosted one priority level up to a maximum of its default priority.
99   };
100
101   /////////////////////////////////////////////////////////////////////////////////////
102   /// \ingroup Process
103   /// \~english @par Summary
104   ///           - Default Constructor, called when the class is instantiated.
105   /// \~english @param [in]  - cpu_assign
106   ///           - Assignment information of CPU.
107   /// \~english @retval  None
108   /// \~english @par Preconditions
109   ///           -no preconditions
110   /// \~english @par Change of the internal state
111   ///           - initialize all var
112   /// \~english @par Causes of failures
113   ///           - None
114   /// \~english @par Classification
115   ///           - Public
116   /// \~english @par Type
117   ///           - sync only
118   /// \~english @par Detail
119   ///           - initialize all var in class as default value
120   /// \~english @see  ~Process
121   ////////////////////////////////////////////////////////////////////////////////////
122   Process(int cpu_assign = 0x0);
123
124   /////////////////////////////////////////////////////////////////////////////////////
125   /// \ingroup Process
126   /// \~english @par Summary
127   ///           - Copy Constructor
128   /// \~english @param [in]  - p_rhs_i
129   ///           - Process - Reference to a Process that you want to copy.
130   /// \~english @retval  None
131   /// \~english @par Preconditions
132   ///           -no preconditions
133   /// \~english @par Change of the internal state
134   ///           - None
135   /// \~english @par Causes of failures
136   ///           - None
137   /// \~english @par Classification
138   ///           - Public
139   /// \~english @par Type
140   ///           - sync only
141   /// \~english @par Detail
142   ///           - Used to create an object and copy another object to the new object.
143   /// \~english @see  ~Process
144   ////////////////////////////////////////////////////////////////////////////////////
145   Process(const Process& p_rhs_i);
146
147   /////////////////////////////////////////////////////////////////////////////////////
148   /// \ingroup ~Process
149   /// \~english @par Summary
150   ///           - Destructor function
151   /// \~english @param  None
152   /// \~english @retval  None
153   /// \~english @par Preconditions
154   ///           -no preconditions
155   /// \~english @par Change of the internal state
156   ///           - set m_lValidationTag with 0
157   /// \~english @par Causes of failures
158   ///           - None
159   /// \~english @par Classification
160   ///           - Public
161   /// \~english @par Type
162   ///           - sync only
163   /// \~english @par Detail
164   ///           - Destructor, called when the object is destroyed.\n
165   ///             set m_lValidationTag with 0 and kill process.
166   /// \~english @see  Process
167   ////////////////////////////////////////////////////////////////////////////////////
168   virtual ~Process();
169
170   /////////////////////////////////////////////////////////////////////////////////////
171   /// \ingroup operator=
172   /// \~english @par Summary
173   ///           - Assignment Operator
174   /// \~english @param [in]
175   /// \~english @retval  Process - New Process object
176   /// \~english @par Preconditions
177   ///           -no preconditions
178   /// \~english @par Change of the internal state
179   ///           - None
180   /// \~english @par Causes of failures
181   ///           - None
182   /// \~english @par Classification
183   ///           - Public
184   /// \~english @par Type
185   ///           - sync only
186   /// \~english @par Detail
187   ///           - Assignment Operator, called when one object is assigned to another object.
188   /// \~english @see  None
189   ////////////////////////////////////////////////////////////////////////////////////
190   Process& operator=(const Process& p_rhs_i);
191
192   /////////////////////////////////////////////////////////////////////////////////////
193   /// \ingroup GetProcessId
194   /// \~english @par Summary
195   ///           - get process id
196   /// \~english @param  None
197   /// \~english @retval  process pid - the process pid of the process running.
198   /// \~english @par Preconditions
199   ///           -no preconditions
200   /// \~english @par Change of the internal state
201   ///           - None
202   /// \~english @par Causes of failures
203   ///           - None
204   /// \~english @par Classification
205   ///           - Public
206   /// \~english @par Type
207   ///           - sync only
208   /// \~english @par Detail
209   ///           - This method will return to the caller the PosixBasedOS001 Specific Process ID.
210   /// \~english @see  None
211   ////////////////////////////////////////////////////////////////////////////////////
212   int const GetProcessId(void) {
213     return static_cast<int>(m_tProcessId);
214   }
215
216   /////////////////////////////////////////////////////////////////////////////////////
217   /// \ingroup SetCallingArgumentList
218   /// \~english @par Summary
219   ///           - This method will set the calling argument list that this object represents
220   /// \~english @param [in]  p_pcArgv_i
221   ///           - const char *[] - Pointer to array of null terminated parameter list.
222   /// \~english @param [in]  p_iArgc_i
223   ///           - const int - - Number of arguments in the array passed.
224   /// \~english @retval  None
225   /// \~english @par Preconditions
226   ///           -no preconditions
227   /// \~english @par Change of the internal state
228   ///           - put the new arguments into m_strlstArgv
229   /// \~english @par Causes of failures
230   ///           - None
231   /// \~english @par Classification
232   ///           - Public
233   /// \~english @par Type
234   ///           - sync only
235   /// \~english @par Detail
236   ///           - Set the executable filename first. This is always the 1st argument
237   ///           - in the argument list. Then set the argument list for the process
238   ///           - which is held in m_strlstArgv.
239   ///           - First make sure that the argument list is empty.
240   ///           - Once empty, put the new arguments into the list
241   /// \~english @see  None
242   ////////////////////////////////////////////////////////////////////////////////////
243   void SetCallingArgumentList(const char *p_pcArgv_i[], const int p_iArgc_i);
244
245   /////////////////////////////////////////////////////////////////////////////////////
246   /// \ingroup SetCallingArgumentList
247   /// \~english @par Summary
248   ///           - This method will set the calling argument list that this object represents.
249   /// \~english @param [in] p_strlstParameters_i
250   ///           - const StringList& - String list of arguments that will be used to start.
251   /// \~english @retval  None.
252   /// \~english @par Preconditions
253   ///           - no preconditions.
254   /// \~english @par Change of the internal state
255   ///           - set m_strlstArgv with p_strlstParameters_i.
256   /// \~english @par Causes of failures
257   ///           - None.
258   /// \~english @par Classification
259   ///           - Public.
260   /// \~english @par Type
261   ///           - sync only
262   /// \~english @par Detail
263   ///           - if p_strlstParameters_i is not empty,then clear m_strlstArgv \n
264   ///           - and set m_strlstArgv with p_strlstParameters_i.
265   /// \~english @see  None
266   ////////////////////////////////////////////////////////////////////////////////////
267   void SetCallingArgumentList(const StringList& p_strlstParameters_i);
268
269 /////////////////////////////////////////////////////////////////////////////////////
270 /// \ingroup GetExecutableFileName
271 /// \~english @par Summary
272 ///           - Get executable file name
273 /// \~english @param  None
274 /// \~english @retval  Pointer
275 ///                   - Points to SS_String object that holds the path and executable file name for this process
276 /// \~english @par Preconditions
277 ///           -no preconditions
278 /// \~english @par Change of the internal state
279 ///           - None
280 /// \~english @par Causes of failures
281 ///           - None
282 /// \~english @par Classification
283 ///           - Public
284 /// \~english @par Type
285 ///           - sync only
286 /// \~english @par Detail
287 ///           - This method will return a pointer to the executable filename that this object represents
288 /// \~english @see  None
289 ////////////////////////////////////////////////////////////////////////////////////
290   const char * const GetExecutableFileName() {
291     return m_strFile.c_str();
292   }
293
294   /////////////////////////////////////////////////////////////////////////////////////
295   /// \ingroup GetProcessReturnCode
296   /// \~english @par Summary
297   ///           - This function will return the processes exit/return code.
298   /// \~english @param  None
299   /// \~english @retval  process exit code - Code for the last process to execute
300   /// \~english @par Preconditions
301   ///           -no preconditions
302   /// \~english @par Change of the internal state
303   ///           - set m_iReturnCode with WEXITSTATUS(iProcessReturn)
304   /// \~english @par Causes of failures
305   ///           - None
306   /// \~english @par Classification
307   ///           - Public
308   /// \~english @par Type
309   ///           - sync only
310   /// \~english @par Detail
311   ///           - This function will return the processes exit/return code.\n
312   ///             This is not the value of ERRNO as returned by GetLastPosixBasedOS001ErrorCode().
313   /// \~english @see  None
314   ////////////////////////////////////////////////////////////////////////////////////
315   int GetProcessReturnCode(void);
316
317   /////////////////////////////////////////////////////////////////////////////////////
318   /// \ingroup SetSchedulingPolicy
319   /// \~english @par Summary
320   ///            - This method will change the scheduling policy for the process this object represents.
321   /// \~english @param  [in] p_eSchedulingPolicy_i
322   ///            - const eProcessSchedulingPolicy - Scheduling Policy for this process
323   /// \~english @par
324   ///            - eProcessSchedulingPolicy
325   /// \~english @code
326   ///            - enum eProcessSchedulingPolicy {
327   ///                     FIFO,        A fixed priority scheduler in which the highest ready process runs until it\n
328   ///                                  blocks or is preempted by a higher priority process.
329   ///                     ROUND_ROBIN, The same as FIFO, except processes at the same priority level time-slice.
330   ///                     OTHER        A general time sharing scheduler in which a process decays in priority if it\n
331   ///                                  consumes too much processor before blocking. It reverts to its default priority\n
332   ///                                  when it blocks. Should it fail to run over a 2 second period and it has decayed\n
333   ///                                  then it's boosted one priority level up to a maximum of its default priority.
334   ///              };
335   ///            @endcode
336   /// \~english @retval  None
337   /// \~english @par Preconditions
338   ///            -no preconditions
339   /// \~english @par Change of the internal state
340   ///            -If the result of function is not 0,then set m_iErrorCode with errno
341   ///            - else set m_iErrorCode with 0.
342   /// \~english @par Causes of failures
343   ///            - None
344   /// \~english @par Classification
345   ///            - Public
346   /// \~english @par Type
347   ///            - sync only
348   /// \~english @par Detail
349   ///            - Attempt to change the scheduling policy for the process that this object
350   ///              represents. If the change fails, restore the previous settings.
351   /// \~english @see  None
352   ////////////////////////////////////////////////////////////////////////////////////
353   void SetSchedulingPolicy(
354       const eProcessSchedulingPolicy p_eSchedulingPolicy_i);
355
356 /////////////////////////////////////////////////////////////////////////////////////
357 /// \ingroup GetSchedulingPolicy
358 /// \~english @par Summary
359 ///           - Get currently configured scheduling policy
360 /// \~english @param  None
361 /// \~english @retval  FIFO         - A fixed priority scheduler in which the highest ready process runs until it\n
362 ///                                   blocks or is preempted by a higher priority process.
363 /// \~english @retval  ROUND_ROBIN  - The same as FIFO, except processes at the same priority level time-slice.
364 /// \~english @retval  OTHER        - A general time sharing scheduler in which a process decays in priority if it\n
365 ///                                   consumes too much processor before blocking. It reverts to its default priority\n
366 ///                                   when it blocks. Should it fail to run over a 2 second period and it has decayed\n
367 ///                                   then it's boosted one priority level up to a maximum of its default priority.
368 /// \~english @par Preconditions
369 ///           -no preconditions
370 /// \~english @par Change of the internal state
371 ///           - If the result of calling function sched_getscheduler(m_tProcessId) is -1
372 ///             then set m_iErrorCode with errno
373 /// \~english @par Causes of failures
374 ///           - None
375 /// \~english @par Classification
376 ///           - Public
377 /// \~english @par Type
378 ///           - sync only
379 /// \~english @par Detail
380 ///           - This method will return to the caller the currently configured process scheduling policy.
381 ///             If the result of calling function sched_getscheduler(m_tProcessId) is -1,
382 ///             then return ROUND_ROBIN.
383 /// \~english @see  None
384 ////////////////////////////////////////////////////////////////////////////////////
385   eProcessSchedulingPolicy const GetSchedulingPolicy(void);
386
387   /////////////////////////////////////////////////////////////////////////////////////
388   /// \ingroup SetPriority
389   /// \~english @par Summary
390   ///           - This method will change the priority for the process this object represents.
391   /// \~english @param  [in] p_iPriority_i
392   ///           - int - Priority of the process
393   /// \~english @retval  None
394   /// \~english @par Preconditions
395   ///           -no preconditions
396   /// \~english @par Change of the internal state
397   ///           - If the result of function sched_setparam(m_tProcessId, &cur_sch_params)\n
398   ///             is -1,then set m_iErrorCode with errno, else set m_iErrorCode with 0.
399   /// \~english @par Causes of failures
400   ///           - None
401   /// \~english @par Classification
402   ///           - Public
403   /// \~english @par Type
404   ///           - sync only
405   /// \~english @par Detail
406   ///           - Using p_iPriority_i to change the priority for the process\n
407   ///             this object represents,if the result of function \n
408   ///             sched_setparam(m_tProcessId, &cur_sch_params) is -1
409   ///             m_iErrorCode will be seted with errno,else be seted with 0
410   /// \~english @see  None
411   ////////////////////////////////////////////////////////////////////////////////////
412   void SetPriority(const int p_iPriority_i);
413
414   /////////////////////////////////////////////////////////////////////////////////////
415   /// \ingroup SetPriority Notice:Can't find the body of this function
416   /// \~english @par Summary
417   ///           - This method will change the priority for the specified process ID.
418   /// \~english @param  [in] p_iPid_i
419   ///           - pid_t - PID of the process to change the priority
420   /// \~english @param  [in] p_iPriority_i
421   ///           - int - Priority of the process
422   /// \~english @retval  None
423   /// \~english @par Preconditions
424   ///           -no preconditions
425   /// \~english @par Change of the internal state
426   ///           -
427   /// \~english @par Causes of failures
428   ///           -
429   /// \~english @par Classification
430   ///           - Public
431   /// \~english @par Type
432   ///           - sync only
433   /// \~english @par Detail
434   ///           -none
435   /// \~english @see  None
436   ////////////////////////////////////////////////////////////////////////////////////
437   void SetPriority(const pid_t p_iPid_i, const int p_iPriority_i);
438
439   /////////////////////////////////////////////////////////////////////////////////////
440   /// \ingroup IncreasePriorityByOne
441   /// \~english @par Summary
442   ///            - This method will increase the priority for the process this\n
443   ///              object represents by one.
444   /// \~english @param  None
445   /// \~english @retval  None
446   /// \~english @par Preconditions
447   ///           -no preconditions
448   /// \~english @par Change of the internal state
449   ///           - None
450   /// \~english @par Causes of failures
451   ///           - None
452   /// \~english @par Classification
453   ///           - Public
454   /// \~english @par Type
455   ///           - sync only
456   /// \~english @par Detail
457   ///           - Retrieve the current priority of the process. Check to see if already at max.\n
458   ///             If so just return. Otherwise increase by one and set the priority...
459   /// \~english @see  None
460   ////////////////////////////////////////////////////////////////////////////////////
461   void IncreasePriorityByOne(void);
462
463   /////////////////////////////////////////////////////////////////////////////////////
464   /// \ingroup DecreasePriorityByOne
465   /// \~english @par Summary
466   ///           - This method will decrease the priority for the process this object represents by one.
467   /// \~english @param  None
468   /// \~english @retval  None
469   /// \~english @par Preconditions
470   ///           -no precondition
471   /// \~english @par Change of the internal state
472   ///           - None
473   /// \~english @par Causes of failures
474   ///           - None
475   /// \~english @par Classification
476   ///           - Public
477   /// \~english @par Type
478   ///           - sync only
479   /// \~english @par Detail
480   ///           - Retrieve the current priority of the process. Check to see if already at minimum.
481   ///             If so just return. Otherwise decrease by one and set the priority...
482   /// \~english @see  None
483   ////////////////////////////////////////////////////////////////////////////////////
484   void DecreasePriorityByOne(void);
485
486   /////////////////////////////////////////////////////////////////////////////////////
487   /// \ingroup GetPriority
488   /// \~english @par Summary
489   ///           - This method will return to the caller the currently configured process priority.
490   /// \~english @param  None
491   /// \~english @retval  int priority - process priority
492   /// \~english @par Preconditions
493   ///           -no preconditions
494   /// \~english @par Change of the internal state
495   ///           - If the result of function sched_getparam(m_tProcessId, &cur_sch_params) is less than -1,\n
496   ///             then m_iErrorCode will be seted with errno.
497   /// \~english @par Causes of failures
498   ///           - None
499   /// \~english @par Classification
500   ///           - Public
501   /// \~english @par Type
502   ///           - sync only
503   /// \~english @par Detail
504   ///           - If the result of function sched_getparam(m_tProcessId, &cur_sch_params)\n
505   ///             is less than -1,will be return -1,else return Currently configured process priority.
506   /// \~english @see  None
507   ////////////////////////////////////////////////////////////////////////////////////
508   int const GetPriority(void);
509
510   /////////////////////////////////////////////////////////////////////////////////////
511   /// \ingroup SetProcessName
512   /// \~english @par Summary
513   ///            - This method will set this objects process name member variable to the provided string value.
514   /// \~english @param  [in] p_strProcessName_i
515   ///            - SS_String - Process Name to set the m_strProcessName member variable to
516   /// \~english @retval  None
517   /// \~english @par Preconditions
518   ///            -no preconditions
519   /// \~english @par Change of the internal state
520   ///            - Using p_strProcessName_i to set m_strProcessName
521   /// \~english @par Causes of failures
522   ///            - None
523   /// \~english @par Classification
524   ///            - Public
525   /// \~english @par Type
526   ///            - sync only
527   /// \~english @par Detail
528   ///            - This method will set this objects process name member variable to the provided string value.\n
529   ///              If the user of this object wishes to register the name with PosixBasedOS001 OS,\n
530   ///              the AttachName() method should be called.
531   /// \~english @see  None
532   ////////////////////////////////////////////////////////////////////////////////////
533   void SetProcessName(const SS_String& p_strProcessName_i);
534
535   /////////////////////////////////////////////////////////////////////////////////////
536   /// \ingroup GetProcessName
537   /// \~english @par Summary
538   ///           - Get process name
539   /// \~english @param  None
540   /// \~english @retval  SS_String - Process Name
541   /// \~english @par Preconditions
542   ///           -no preconditions
543   /// \~english @par Change of the internal state
544   ///           - None
545   /// \~english @par Causes of failures
546   ///           - None
547   /// \~english @par Classification
548   ///           - Public
549   /// \~english @par Type
550   ///           - sync only
551   /// \~english @par Detail
552   ///           - This method will return to the caller the registered name of this process.\n
553   ///             been registered with the OS, a NULL string will be returned. If a name has not
554   /// \~english @see  None
555   ////////////////////////////////////////////////////////////////////////////////////
556   SS_String GetProcessName(void) const {
557     return m_strProcessName;
558   }
559
560   /////////////////////////////////////////////////////////////////////////////////////
561   /// \ingroup CreateProcess
562   /// \~english @par Summary
563   ///            - This method will create a process with the executable provided and \n
564   ///              mode as a calling parameter.The caller can also provide a list of arguments \n
565   ///              that will be provided to the executable at startup.
566   /// \~english @param  [in] p_strFile_i
567   ///            - SS_String - Path and Filename of executable to create process for
568   /// \~english @param  [in] p_strlstArgv_i
569   ///            - StringList - List of ARGV values for new process
570   /// \~english @param  [in] p_eMode_i
571   ///            - eProcessLoadMode - Mode to create and load new process
572   /// \~english @param  [in] p_strProcessName_i
573   ///            - SS_String - This is the name that will be registered to the OS for this process
574   /// \~english @param  [in] p_eSchedulingPolicy_i
575   ///            - eProcessSchedulingPolicy
576   /// \~english @param  [in] p_iPriority_i
577   ///            - int - Priority for this process
578   /// \~english @param  [in] unix_user_name
579   ///            - char* - unix user name
580   /// \~english @param  [in] p_lSpawnFlags_i
581   ///            - long - Spawning flags. These are PosixBasedOS001 specific....
582   /// \~english @par
583   ///            eProcessLoadMode enum
584   /// \~english @code
585   ///            - enum eProcessLoadMode {
586   ///                WAIT,        //The invoked program is loaded into available memory, is executed,
587   ///                             //and then the original program resumes execution.
588   ///                NOWAIT,      // Causes the current program to execute concurrently with the new child process.
589   ///              };
590   ///            @endcode
591   /// \~english @par
592   ///            eProcessSchedulingPolicy enum
593   /// \~english @code
594   ///            - enum eProcessSchedulingPolicy {
595   ///                FIFO,         // A fixed priority scheduler in which the highest ready process runs until it
596   ///                              // blocks or is preempted by a higher priority process.
597   ///                ROUND_ROBIN,  // The same as FIFO, except processes at the same priority level time-slice.
598   ///                OTHER         // A general time sharing scheduler in which a process decays in priority if it
599   ///                              // consumes too much processor before blocking. It reverts to its default priority
600   ///                              // when it blocks. Should it fail to run over a 2 second period and it has decayed
601   ///                              // then it's boosted one priority level up to a maximum of its default priority.
602   ///             };
603   ///            @endcode
604   /// \~english @retval  None
605   /// \~english @par Preconditions
606   ///           -no preconditions
607   /// \~english @par Change of the internal state
608   ///           - set m_iErrorCode with 0
609   ///             set m_iReturnCode with 0
610   ///             set m_eProcessLoadMode with p_eMode_i;
611   ///             set m_strFile with p_strFile_i;
612   ///             set m_strProcessName with p_strProcessName_i;
613   ///             use the result of function CL_ProcessCreate() to set m_tProcessId
614   /// \~english @par Causes of failures
615   ///           - None
616   /// \~english @par Classification
617   ///           - Public
618   /// \~english @par Type
619   ///           - sync only
620   /// \~english @par Detail
621   ///            -This method will create a PosixBasedOS001 process with the executable provided\n
622   ///             and mode as a calling parameter.The caller can also provide a list of arguments\n
623   ///             that will be provided to the executable at startup.The calling p_strProcessName \m
624   ///             parameter is a textual name that will be associated with the newly created process\n
625   ///             by the OS. The process state information will be maintained by this object.\n
626   ///             Upon successful creation of the process, the scheduling policy and priority\n
627   ///             of the process will be set to the provided values. The user can change these\n
628   ///             values through the SetSchedulingPolicy() and SetPriority() method calls.\n
629   ///             Using unix_user_name to get uid and gid,set uid and gid when calling\n
630   ///             CL_ProcessCreateAttrSetUid() and CL_ProcessCreateAttrSetGid\n
631   /// \~english @see  None
632   ////////////////////////////////////////////////////////////////////////////////////
633   void CreateProcess(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
634       const StringList& p_strlstArgv_i,   // List of ARGV values for new process
635       const eProcessLoadMode p_eMode_i,   // Mode to create and load new process
636       const SS_String& p_strProcessName_i,  // This is the name that will be registered to the OS for this process
637       const eProcessSchedulingPolicy p_eSchedulingPolicy_i,  // Scheduling Policy for this process
638       const int p_iPriority_i,        // Priority for this process
639       const char* unix_user_name, const long p_lSpawnFlags_i);  // Spawning flags. These are PosixBasedOS001 specific....  // NOLINT (runtime/int)
640
641   /////////////////////////////////////////////////////////////////////////////////////
642   /// \ingroup CreateProcess
643   /// \~english @par Summary
644   ///            - This method will create a PosixBasedOS001 process with the executable\n
645   ///              provided and mode as a calling parameter.
646   /// \~english @param  [in] p_strFile_i
647   ///            - SS_String - Path and Filename of executable to create process for
648   /// \~english @param  [in] p_strProcessName_i
649   ///            - SS_String - This is the name that will be registered to the OS for this process
650   /// \~english @param  [in] unix_user_name
651   ///            - char* - unix user name
652   /// \~english @param  [in] p_lSpawnFlags_i
653   ///            - long - Posix Spawning flags. These are PosixBasedOS001 specific
654   /// \~english @retval  None
655   /// \~english @par Preconditions
656   ///           -no preconditions
657   /// \~english @par Change of the internal state
658   ///           - None
659   /// \~english @par Causes of failures
660   ///           - None
661   /// \~english @par Classification
662   ///           - Public
663   /// \~english @par Type
664   ///           - sync only
665   /// \~english @par Detail
666   ///           - The caller can also provide a list of arguments that will be provided\n
667   ///             to the executable at startup.The calling p_strProcessName parameter is a textual name\n
668   ///             that will be associated with the newly created process by the OS.\n
669   ///             The process state information will be maintained by this object.
670   /// \~english @see  None
671   ////////////////////////////////////////////////////////////////////////////////////
672   void CreateProcess(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
673       const SS_String& p_strProcessName_i,  // This is the name that will be registered to the OS for this process
674       const char* unix_user_name = NULL, const long p_lSpawnFlags_i =  // NOLINT (runtime/int)
675           iProcess_DEFAULT_PROCESS_FLAGS);  // Spawning flags.
676                                             // These are PosixBasedOS001 specific....
677   /////////////////////////////////////////////////////////////////////////////////////
678   /// \ingroup CreateProcess
679   /// \~english @par Summary
680   ///           - This method will create a process with the executable
681   ///           provided and mode as a calling parameter.
682   /// \~english @param  [in] p_strFile_i
683   ///            - SS_String - Path and Filename of executable to create
684   ///            process for
685   /// \~english @param  [in] p_strProcessName_i
686   ///            - SS_String - This is the name that will be registered to the
687   ///            OS for this process
688   /// \~english @param  [in] p_iPriority_i
689   ///            - int - Priority of process
690   /// \~english @param  [in] unix_user_name
691   ///            - char* - unix user name
692   /// \~english @param  [in] p_lSpawnFlags_i
693   ///            - long - Posix Spawning flags. These are PosixBasedOS001
694   ///            specific
695   /// \~english @retval  None
696   /// \~english @par Preconditions
697   ///           -no preconditions
698   /// \~english @par Change of the internal state
699   ///           - None
700   /// \~english @par Causes of failures
701   ///           - None
702   /// \~english @par Classification
703   ///           - Public
704   /// \~english @par Type
705   ///           - sync only
706   /// \~english @par Detail
707   ///           - The caller can also provide a list of arguments that will be
708   ///           provided\n
709   ///             to the executable at startup.The calling p_strProcessName
710   ///             parameter is a textual name\n
711   ///             that will be associated with the newly created process by
712   ///             the OS.\n
713   ///             The process state information will be maintained by this
714   ///             object.
715   /// \~english @see  None
716   ////////////////////////////////////////////////////////////////////////////////////
717   void CreateProcess(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
718       const SS_String& p_strProcessName_i,  // This is the name that will be registered to the OS for this process
719       const int p_iPriority_i,        // Priority of this process
720       const char* unix_user_name = NULL, const long p_lSpawnFlags_i =  // NOLINT (runtime/int)
721           iProcess_DEFAULT_PROCESS_FLAGS);  // Spawning flags.
722                                             // These are PosixBasedOS001 specific....
723
724 /////////////////////////////////////////////////////////////////////////////////////
725 /// \ingroup CreateProcess
726 /// \~english @par Summary
727 ///           - This method will create a process with the executable provided and mode as a calling parameter.
728 /// \~english @param  [in] p_strFile_i
729 ///            - SS_String - p_strFile_i Path and Filename of executable to create process for
730 /// \~english @param  [in] unix_user_name
731 ///            - char* - unix user name
732 /// \~english @param  [in] p_lSpawnFlags_i
733 ///            - long - Spawning flags. These are PosixBasedOS001 specific.
734 /// \~english @retval  None
735 /// \~english @par Preconditions
736 ///           -
737 /// \~english @par Change of the internal state
738 ///           - None
739 /// \~english @par Causes of failures
740 ///           - None
741 /// \~english @par Classification
742 ///           - Public
743 /// \~english @par Type
744 ///           - sync only
745 /// \~english @par Detail
746 ///           - The caller can also provide a list of arguments that will be provided\n
747 ///             to the executable at startup.The calling p_strProcessName parameter is a textual name\n
748 ///             that will be associated with the newly created process by the OS.\n
749 ///             The process state information will be maintained by this object.
750 /// \~english @see  None
751 ////////////////////////////////////////////////////////////////////////////////////
752   void CreateProcess(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
753       const char* unix_user_name = NULL, const long p_lSpawnFlags_i =  // NOLINT (runtime/int)
754           iProcess_DEFAULT_PROCESS_FLAGS);  // Spawning flags.
755                                             // These are PosixBasedOS001 specific....
756
757 /////////////////////////////////////////////////////////////////////////////////////
758 /// \ingroup CreateProcess
759 /// \~english @par Summary
760 ///           - This method will create a process with the executable provided and mode as a calling parameter.
761 /// \~english @param  [in] p_strFile_i
762 ///            - SS_String - p_strFile_i Path and Filename of executable to create process for
763 /// \~english @param  [in] p_strProcessName_i
764 ///            - SS_String - This is the name that will be registered to the OS for this process
765 /// \~english @param  [in] p_strlstArgv_i
766 ///            - StringList - List of ARGV values for new process
767 /// \~english @param  [in] unix_user_name
768 ///            - char* - unix user name
769 /// \~english @param  [in] p_lSpawnFlags_i
770 ///            - long - Spawning flags. These are PosixBasedOS001 specific.
771 /// \~english @retval  None
772 /// \~english @par Preconditions
773 ///           -no preconditions
774 /// \~english @par Change of the internal state
775 ///           - None
776 /// \~english @par Causes of failures
777 ///           - None
778 /// \~english @par Classification
779 ///           - Public
780 /// \~english @par Type
781 ///           - sync only
782 /// \~english @par Detail
783 ///           - The caller can also provide a list of arguments that will be provided\n
784 ///             to the executable at startup.The calling p_strProcessName parameter is a textual name\n
785 ///             that will be associated with the newly created process by the OS.\n
786 ///             The process state information will be maintained by this object.
787 /// \~english @see  None
788 ////////////////////////////////////////////////////////////////////////////////////
789   void CreateProcess(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
790       const SS_String& p_strProcessName_i,  // This is the name that will be registered to the OS for this process
791       const StringList& p_strlstArgv_i,   // List of ARGV values for new process
792       const char* unix_user_name = NULL, const long p_lSpawnFlags_i =  // NOLINT (runtime/int)
793           iProcess_DEFAULT_PROCESS_FLAGS);  // Spawning flags.
794                                             // These are PosixBasedOS001 specific....
795
796 /////////////////////////////////////////////////////////////////////////////////////
797 /// \ingroup CreateProcess
798 /// \~english @par Summary
799 ///           - This method will create a  process with the executable provided and mode as a calling parameter.
800 /// \~english @param  [in] p_strFile_i
801 ///            - SS_String - Path and Filename of executable to create process for
802 /// \~english @param  [in] p_strProcessName_i
803 ///            - SS_String - This is the name that will be registered to the OS for this process
804 /// \~english @param  [in] p_iPriority_i
805 ///            - int - Priority for this process
806 /// \~english @param  [in] p_strlstArgv_i
807 ///            - StringList - List of ARGV values for new process
808 /// \~english @param  [in] unix_user_name
809 ///            - char* - unix user name
810 /// \~english @param  [in] p_lSpawnFlags_i
811 ///            - long - Spawning flags.These are PosixBasedOS001 specific.
812 /// \~english @retval  None
813 /// \~english @par Preconditions
814 ///           -no preconditions
815 /// \~english @par Change of the internal state
816 ///           - None
817 /// \~english @par Causes of failures
818 ///           - None
819 /// \~english @par Classification
820 ///           - Public
821 /// \~english @par Type
822 ///           - sync only
823 /// \~english @par Detail
824 ///           - The caller can also provide a list of arguments that will be provided\n
825 ///             to the executable at startup.The calling p_strProcessName parameter is a textual name\n
826 ///             that will be associated with the newly created process by the OS.\n
827 ///             The process state information will be maintained by this object.
828 /// \~english @see  None
829 ////////////////////////////////////////////////////////////////////////////////////
830   void CreateProcess(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
831       const SS_String& p_strProcessName_i,  // This is the name that will be registered to the OS for this process
832       const int p_iPriority_i,        // Priority for this process
833       const StringList& p_strlstArgv_i,   // List of ARGV values for new process
834       const char* unix_user_name = NULL, const long p_lSpawnFlags_i =  // NOLINT (runtime/int)
835           iProcess_DEFAULT_PROCESS_FLAGS);  // Spawning flags.
836                                             // These are PosixBasedOS001 specific....
837   /////////////////////////////////////////////////////////////////////////////////////
838   /// \ingroup CreateProcess
839   /// \~english @par Summary
840   ///           - This method will create a  process with the executable provided and mode as a calling parameter.
841   /// \~english @param  [in] p_strFile_i
842   ///            - SS_String - Path and Filename of executable to create process for
843   /// \~english @param  [in] c_argv
844   ///            - char - This is the argument that will be registered to the OS for this process
845   /// \~english @param  [in] environment_string
846   ///            - char - enviroment for this process
847   /// \~english @param  [in] cl_attr
848   ///            - CL_ProcessAttr_t - List of ARGV values for new process
849   /// \~english @retval  None
850   /// \~english @par Preconditions
851   ///           -no preconditions
852   /// \~english @par Change of the internal state
853   ///           - None
854   /// \~english @par Causes of failures
855   ///           - None
856   /// \~english @par Classification
857   ///           - Public
858   /// \~english @par Type
859   ///           - sync only
860   /// \~english @par Detail
861   ///           - The caller can also provide a list of arguments that will be provided\n
862   ///             that will be associated with the newly created process by the OS.\n
863   ///             The process state information will be maintained by this object.
864   /// \~english @see  None
865   ////////////////////////////////////////////////////////////////////////////////////
866   void CreateProcess(const SS_String* p_str_file, char* const * c_argv,
867                      char* environment_string, const CL_ProcessAttr_t *cl_attr);
868
869 /////////////////////////////////////////////////////////////////////////////////////
870 /// \ingroup CreateProcessWait
871 /// \~english @par Summary
872 ///           - This method will create a process with the executable provided.
873 /// \~english @param  [in] p_strFile_i
874 ///            - SS_String - Path and Filename of executable to create process for
875 /// \~english @retval  None
876 /// \~english @par Preconditions
877 ///           -no preconditions
878 /// \~english @par Change of the internal state
879 ///           - None
880 /// \~english @par Causes of failures
881 ///           - None
882 /// \~english @par Classification
883 ///           - Public
884 /// \~english @par Type
885 ///           - sync only
886 /// \~english @par Detail
887 ///           - This method will create a process with the executable provided.\n
888 ///             The process state information will be maintained by this object.
889 /// \~english @see  None
890 ////////////////////////////////////////////////////////////////////////////////////
891   void CreateProcessWait(const SS_String& p_strFile_i);  // Path and Filename of executable to create process for
892
893 /////////////////////////////////////////////////////////////////////////////////////
894 /// \ingroup CreateProcessWait
895 /// \~english @par Summary
896 ///           - This method will create a PosixBasedOS001 process with the executable provided.
897 /// \~english @param  [in] p_strFile_i
898 ///            - SS_String - Path and Filename of executable to create process for
899 /// \~english @param  [in] p_strlstArguments_i
900 ///            - StringList - List of process calling arguments
901 /// \~english @retval  None
902 /// \~english @par Preconditions
903 ///           -no preconditions
904 /// \~english @par Change of the internal state
905 ///           - None
906 /// \~english @par Causes of failures
907 ///           - None
908 /// \~english @par Classification
909 ///           - Public
910 /// \~english @par Type
911 ///           - sync only
912 /// \~english @par Detail
913 ///           - This method will create a PosixBasedOS001 process with the executable provided.\n
914 ///             The process state information will be maintained by this object.
915 /// \~english @see  None
916 ////////////////////////////////////////////////////////////////////////////////////
917   void CreateProcessWait(const SS_String& p_strFile_i,  // Path and Filename of executable to create process for
918       const StringList& p_strlstArguments_i);  // List of process calling arguments
919
920 /////////////////////////////////////////////////////////////////////////////////////
921 /// \ingroup KillProcess
922 /// \~english @par Summary
923 ///           - This method will send the specified signal to the process represented by this object
924 /// \~english @param  [in] signal
925 ///            - int - signal
926 /// \~english @retval  None
927 /// \~english @par Preconditions
928 ///           -no preconditions
929 /// \~english @par Change of the internal state
930 ///           - Intialize the objects m_iErrorCode member variable to 0
931 /// \~english @par Causes of failures
932 ///           - None
933 /// \~english @par Classification
934 ///           - Public
935 /// \~english @par Type
936 ///           - sync only
937 /// \~english @par Detail
938 ///           - This method will send the specified signal to the process represented by this object.\n
939 ///             All variables associated with this object will be initialized to a know value.\n
940 ///             If this process has a name registered with the OS, that name will be removed.
941 /// \~english @see  None
942 ////////////////////////////////////////////////////////////////////////////////////
943   void KillProcess(int signal = SIGKILL);
944
945 /////////////////////////////////////////////////////////////////////////////////////
946 /// \ingroup DoesProcessExist
947 /// \~english @par Summary
948 ///           -Check if the process existed
949 /// \~english @param  None
950 /// \~english @retval TRUE  - Process Exists
951 /// \~english @retval FALSE - Process does not exist
952 /// \~english @par Preconditions
953 ///           -no preconditions
954 /// \~english @par Change of the internal state
955 ///           - The internal state is not changed.
956 /// \~english @par Causes of failures
957 ///           -None
958 /// \~english @par Classification
959 ///           - Public
960 /// \~english @par Type
961 ///           - sync only
962 /// \~english @par Detail
963 ///           - This method will return a BOOLean indicating whether this process exists.
964 /// \~english @see
965 ////////////////////////////////////////////////////////////////////////////////////
966   BOOL DoesProcessExist(void);
967
968 /////////////////////////////////////////////////////////////////////////////////////
969 /// \ingroup DisableAutoKill
970 /// \~english @par Summary
971 ///           -none
972 /// \~english @param  None
973 /// \~english @retval  None
974 /// \~english @par Preconditions
975 ///           -no preconditions
976 /// \~english @par Change of the internal state
977 ///           - set m_fAutoKill as FALSE
978 /// \~english @par Causes of failures
979 ///           - None
980 /// \~english @par Classification
981 ///           - Public
982 /// \~english @par Type
983 ///           - sync only
984 /// \~english @par Detail
985 ///           - This method will disable the Auto Kill function in the destructor,\n
986 ///             thus letting the process whom this object represents continue running.
987 /// \~english @see  None
988 ////////////////////////////////////////////////////////////////////////////////////
989   void DisableAutoKill(void) {
990     m_fAutoKill = FALSE;
991   }
992
993 /////////////////////////////////////////////////////////////////////////////////////
994 /// \ingroup EnableAutoKill
995 /// \~english @par Summary
996 ///           - Enable the Auto Kill
997 /// \~english @param  None
998 /// \~english @retval  None
999 /// \~english @par Preconditions
1000 ///           -no preconditions
1001 /// \~english @par Change of the internal state
1002 ///           - set m_fAutoKill as TRUE
1003 /// \~english @par Causes of failures
1004 ///           - None
1005 /// \~english @par Classification
1006 ///           - Public
1007 /// \~english @par Type
1008 ///           - sync only
1009 /// \~english @par Detail
1010 ///           - This method will Enable the Auto Kill function in the destructor,\n
1011 ///             thus killing the process whom this object represents.
1012 /// \~english @see  None
1013 ////////////////////////////////////////////////////////////////////////////////////
1014   void EnableAutoKill(void) {
1015     m_fAutoKill = TRUE;
1016   }
1017
1018  private:
1019   //  Class Data Members
1020   //---------------------------------------------
1021
1022   long m_lValidationTag;  // Used to check if this is a valid  // NOLINT (runtime/int)
1023   // object or not.
1024
1025   int m_cpu_assign;
1026   pid_t m_tProcessId;  // This is the process ID for this process. All command, control,
1027   // and status gathering will use this ID.
1028   eProcessLoadMode m_eProcessLoadMode;  // This is the process load mode provided by the caller when this
1029   // process was created.
1030   SS_String m_strFile;  // This is the executable path and file name of this process
1031   StringList m_strlstArgv;  // This is the calling parameter Argv list provided by the caller.
1032   SS_String m_strProcessName;  // This is the name that was registered to the OS for process identification
1033
1034   int m_iErrorCode;  // This was the returned PosixBasedOS001 error code for the last call. The programmer
1035   // can look at this error code if an error was detected and an
1036   // exception was thrown.
1037   BOOL m_fAutoKill;  // Used to indicate to destructor to kill the process whom this object
1038   // represents on exit.
1039   int m_iReturnCode;
1040
1041   //////////////////////////////////////////////////////////////////////
1042   /// Copy
1043   ///
1044   /// Copies data members from the specified object to this object.
1045   /// No attempt is made to free dynamically allocated objects within
1046   /// this object (you must do that before calling this function).
1047   ///
1048   ///////////////////////////////////////////////////////////////////////
1049   void Copy(const Process& p_rhs_i);
1050
1051   ////////////////////////////////////////////////////////////////////////////////////////////////////
1052   /// ConvertToPosixBasedOS001SchedularPolicy
1053   /// This method will return to the caller the equivalent PosixBasedOS001 schedular policy for the process
1054   /// that this object represents
1055   ///
1056   ///
1057   /// Calling Arguments:
1058   ///      Scheduling Policy
1059   ///
1060   /// \return policy
1061   ///      FIFO,       A fixed priority scheduler in which the highest ready process runs until it
1062   ///               blocks or is preempted by a higher priority process.
1063   ///      ROUND_ROBIN,   The same as FIFO, except processes at the same priority level time-slice.
1064   ///      OTHER       A general time sharing scheduler in which a process decays in priority if it
1065   ///               consumes too much processor before blocking. It reverts to its default priority
1066   ///               when it blocks. Should it fail to run over a 2 second period and it has decayed
1067   ///               then it's boosted one priority level up to a maximum of its default priority.
1068   //////////////////////////////////////////////////////////////////////////////////////////////////////////
1069   int const ConvertToPosixBasedOS001SchedularPolicy(
1070       const eProcessSchedulingPolicy p_eSchedulingPolicy_i);
1071
1072   ////////////////////////////////////////////////////////////////////////////////////////////////////
1073   /// ConvertFromPosixBasedOS001SchedularPolicy
1074   ///
1075   /// This method will return to the caller the eProcessSchedulingPolicy based on the PosixBasedOS001 schedular
1076   /// policy for the process that this object represents
1077   ///
1078   ///
1079   /// Calling Arguments:
1080   ///      PosixBasedOS001 Scheduling Policy
1081   ///
1082   /// \return policy
1083   ///      FIFO,      A fixed priority scheduler in which the highest ready process runs until it
1084   ///              blocks or is preempted by a higher priority process.
1085   ///      ROUND_ROBIN,  The same as FIFO, except processes at the same priority level time-slice.
1086   ///      OTHER      A general time sharing scheduler in which a process decays in priority if it
1087   ///              consumes too much processor before blocking. It reverts to its default priority
1088   ///              when it blocks. Should it fail to run over a 2 second period and it has decayed
1089   ///              then it's boosted one priority level up to a maximum of its default priority.
1090   ///////////////////////////////////////////////////////////////////////////////////////////////////////
1091   eProcessSchedulingPolicy const ConvertFromPosixBasedOS001SchedularPolicy(
1092       const int p_iPosixBasedOS001chedulingPolicy_i);
1093
1094   ////////////////////////////////////////////////////////////////////////////////////////////////////
1095   /// \ingroup SS_SystemServicesIf
1096   ////////////////////////////////////////////////////////////////////////////////////////////////////
1097   /// \brief Check environment variable MOCK_LIBRARY where Mock Library Name to set in LD_PRELOAD is set
1098   ///        and output character string to set in LD_PRELOAD if there is setting.
1099   /// \return
1100   ////////////////////////////////////////////////////////////////////////////////////////////////////
1101   void CheckLdPreLoad(SS_String *process_path, char *environment_string);
1102
1103   ////////////////////////////////////////////////////////////////////////////////////////////////////
1104   /// \ingroup SS_SystemServicesIf
1105   ////////////////////////////////////////////////////////////////////////////////////////////////////
1106   /// \brief Acquire the character string of the environment variable and set it in String Vector
1107   ///        and return in a pointer of Vector.
1108   /// \return vector<SS_String> pointer
1109   ////////////////////////////////////////////////////////////////////////////////////////////////////
1110   std::vector<SS_String> *GetEnvironVector(void);
1111 // ----------------------------------------
1112 // ---------------- End -------------------
1113 };
1114 #endif  // NOLINT (build/header_guard)
1115
1116 /** @}*/
1117 /** @}*/
1118 /** @}*/