Release 4.0.0-preview1-00201
[platform/core/csapi/tizenfx.git] / src / Tizen.System.Information / Usage / SystemMemoryUsage.cs
1 /*
2 * Copyright (c) 2016 - 2017 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
17 using System.IO;
18
19 namespace Tizen.System
20 {
21     /// <summary>
22     /// The class for system memory information.
23     /// </summary>
24     public class SystemMemoryUsage
25     {
26         private Interop.RuntimeInfo.MemoryInfo Info;
27
28         /// <summary>
29         /// The constructor of MemoryInformation class.
30         /// </summary>
31         /// <since_tizen> 4 </since_tizen>
32         /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system.</exception>
33         public SystemMemoryUsage()
34         {
35             Update();
36         }
37
38         /// <summary>
39         /// Total memory (KiB).
40         /// </summary>
41         /// <since_tizen> 4 </since_tizen>
42         public int Total
43         {
44             get
45             {
46                 return Info.Total;
47             }
48         }
49
50         /// <summary>
51         /// Used memory (KiB).
52         /// </summary>
53         /// <since_tizen> 4 </since_tizen>
54         public int Used
55         {
56             get
57             {
58                 return Info.Used;
59             }
60         }
61
62         /// <summary>
63         /// Free memory (KiB).
64         /// </summary>
65         /// <since_tizen> 4 </since_tizen>
66         public int Free
67         {
68             get
69             {
70                 return Info.Free;
71             }
72         }
73
74         /// <summary>
75         /// Cache memory (KiB).
76         /// </summary>
77         /// <since_tizen> 4 </since_tizen>
78         public int Cache
79         {
80             get
81             {
82                 return Info.Cache;
83             }
84         }
85
86         /// <summary>
87         /// Swap memory (KiB).
88         /// </summary>
89         /// <since_tizen> 4 </since_tizen>
90         public int Swap
91         {
92             get
93             {
94                 return Info.Swap;
95             }
96         }
97
98         /// <summary>
99         /// Update the system memory information to the latest.
100         /// </summary>
101         /// <since_tizen> 4 </since_tizen>
102         /// <exception cref="IOException">Thrown when I/O error occurs while reading from the system.</exception>
103         public void Update()
104         {
105             InformationError ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out Info);
106             if (ret != InformationError.None)
107             {
108                 Log.Error(InformationErrorFactory.LogTag, "Interop failed to get System memory information");
109                 InformationErrorFactory.ThrowException(ret);
110             }
111         }
112     }
113 }