common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / system_manager / server / include / ss_system_memory_monitor.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_SystemManager
19 /// \brief    This file provides support for System Manager System Low Memory
20 ///           detection.
21 ///
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #ifndef __SS_SYSTEM_MEMORY_MONITOR_H__  // NOLINT
25 #define __SS_SYSTEM_MEMORY_MONITOR_H__
26
27 #include <native_service/frameworkunified_types.h>
28 #include <system_service/resm.h>
29 #include <system_service/ss_system_timer.h>
30 #include <iostream>
31 #include <string>
32 #include "ss_sm_config.h"
33
34
35 typedef enum _ESMSysMemThreadCommandIds {
36   eSysMemThrdCmd_SYS_LOW_MEMORY = 0x744,  ///< SM.CrashDetector --> SM
37 } ESMSysMemThreadCommandIds;
38
39 struct SysMem {
40   UI_32 FreeMemoryBytes;
41   UI_32 TotalMemoryBytes;
42 };
43
44 const UI_32 SS_SLM_MEM_MONITOR_TIMER_ID = 3000;
45 const UI_32 SS_SLM_SYSTEMMANAGERLOG_TIMER_ID      = 3001;
46 const UI_32 SS_MEMORY_TIMER_CONFIG_MS   = 1000;
47 const UI_32 SS_SYSTEMMANAGERLOG_TIMER_CONFIG_MS   = 30000;
48
49 class CSysMemoryMonitor {
50  public:
51                      CSysMemoryMonitor(void);
52
53   virtual           ~CSysMemoryMonitor(void);
54
55   EFrameworkunifiedStatus         Initialize(HANDLE f_hApp);
56   EFrameworkunifiedStatus         StopAndFreeObjects(HANDLE f_hApp);
57
58   const std::string  GetThreadName(void);
59   void               SetSLMConfigData(SLMConfigParameters &f_ConfigData);  // NOLINT
60
61  private:
62   EFrameworkunifiedStatus CPUMemThreadStart(HANDLE f_hThread);
63   EFrameworkunifiedStatus CPUMemThreadStop(HANDLE f_hThread);
64   EFrameworkunifiedStatus StopTimers(void);
65   EFrameworkunifiedStatus OnMemoryTimerExpiry(HANDLE f_hThread);
66   EFrameworkunifiedStatus OnSystemmanagerlogTimerExpiry(HANDLE f_hThread);
67   EFrameworkunifiedStatus OnAvailability(HANDLE f_hThread);
68
69   UI_32      GetSystemRamSize(void);
70   UI_32      BitReverse32(UI_32  f_val);
71
72   HANDLE              m_hThread;
73   HANDLE              m_hParentApp;
74   Timer               m_memMonitorTimer;
75   Timer               m_systemmanagerlogTimer;
76   SLMConfigParameters m_SLMConfig;
77   SI_32               m_SLMCheckCounter;
78   SI_32               m_siPriority;
79   UI_32               m_NbrSamplesBeforeSystemmanagerlog;
80   SysMem              m_sysMemInfoLast;
81   std::string         m_memMonitorThreadName;
82   uint32_t            m_resmSession;
83 };
84
85 #endif // __SS_SYSTEM_MEMORY_MONITOR_H__  // NOLINT