Tizen 2.1 base
[platform/framework/web/wrt-plugins-common.git] / src / modules / tizen / Cpu / Unit.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #ifndef WRTDEVICEAPIS_CPU_UNIT_H_
17 #define WRTDEVICEAPIS_CPU_UNIT_H_
18
19 #include <string>
20 #include <Cpu/IUnit.h>
21
22 namespace WrtDeviceApis {
23 namespace Cpu {
24
25 class Manager;
26
27 class Unit : public Api::IUnit
28 {
29     friend class Manager;
30
31   public:
32     unsigned int getUtilizationPercent() const;
33
34   private:
35     /**
36      * Stores processor utilization statistics.
37      */
38     struct UtilizationStats
39     {
40         unsigned int m_user;
41         unsigned int m_nice;
42         unsigned int m_system;
43         unsigned int m_idle;
44     };
45
46   private:
47     explicit Unit(std::size_t index);
48
49     /**
50      * Gets processor utilization statistics.
51      * @return Processor utilization statistics.
52      * @throw UnsupportedException If data could not be retrieved.
53      */
54     UtilizationStats getUtilization() const;
55
56   private:
57     std::size_t m_index; ///< Index of CPU interface to represent.
58
59     /**
60      * Regex pattern used to get processor utilization statistics from
61      * stat file.
62      */
63     std::string m_utilizationPattern;
64 };
65
66 } // Cpu
67 } // WrtDeviceApis
68
69 #endif // WRTDEVICEAPIS_CPU_UNIT_H_