[NUI] Add license, delete unnecessary code (#2679)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / FrameBroker / FrameData.cs
1 /*
2  * Copyright (c) 2021 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;
18 using Tizen.Applications;
19
20 namespace Tizen.NUI
21 {
22     /// <summary>
23     /// Represents the Frame Data.
24     /// </summary>
25     internal class FrameData
26     {
27         private const string logTag = "NUI";
28         private readonly IntPtr frame;
29         private int fd = -1;
30         private uint size = 0;
31
32         internal FrameData(IntPtr frame)
33         {
34             this.frame = frame;
35         }
36
37         /// <summary>
38         /// Checks whether the direction of the frame is forward or not.
39         /// </summary>
40         internal bool DirectionForward
41         {
42             get
43             {
44                 Interop.FrameBroker.FrameDirection direction = Interop.FrameBroker.FrameDirection.Backward + 1;
45                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetDirection(frame, out direction);
46                 if (err != Interop.FrameBroker.ErrorCode.None)
47                 {
48                     Log.Error(logTag, "Failed to get direction");
49                 }
50                 return (direction == Interop.FrameBroker.FrameDirection.Forward);
51             }
52         }
53
54         /// <summary>
55         /// Gets the extra data.
56         /// </summary>
57         internal Bundle Extra
58         {
59             get
60             {
61                 SafeBundleHandle safeBundle;
62                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetExtraData(frame, out safeBundle);
63                 if (err != Interop.FrameBroker.ErrorCode.None)
64                 {
65                     Log.Error(logTag, "Failed to get extra data");
66                     return null;
67                 }
68                 return new Bundle(safeBundle);
69             }
70         }
71
72         /// <summary>
73         /// Enumeration for the frame type.
74         /// </summary>
75         internal enum FrameType
76         {
77             /// <summary>
78             /// The tbm surface of the remote surface.
79             /// </summary>
80             RemoteSurfaceTbmSurface,
81
82             /// <summary>
83             /// The image file of the remote surface.
84             /// </summary>
85             RemoteSurfaceImageFile,
86
87             /// <summary>
88             /// The image of the splash screen.
89             /// </summary>
90             SplashScreenImage,
91
92             /// <summary>
93             /// The edje of the splash screen.
94             /// </summary>
95             SPlashScreenEdje,
96         }
97
98         /// <summary>
99         /// Enumeration for the direction of the frame.
100         /// </summary>
101         internal enum FrameDirection
102         {
103             /// <summary>
104             /// The direction that is from the caller to the other application.
105             /// </summary>
106             Forward,
107
108             /// <summary>
109             /// The direction that is from the other application to the caller.
110             /// </summary>
111             Backward,
112         }
113
114         /// <summary>
115         /// Gets the tbm surface of the remote surface.
116         /// </summary>
117         /// <value>
118         /// The TbmSurface type is tbm_surface_h.
119         /// </value>
120         internal IntPtr TbmSurface
121         {
122             get
123             {
124                 IntPtr tbmSurface = IntPtr.Zero;
125                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetTbmSurface(frame, out tbmSurface);
126
127                 if (err != Interop.FrameBroker.ErrorCode.None)
128                 {
129                     Log.Error(logTag, "Failed to get tbm surface");
130                 }
131                 return tbmSurface;
132             }
133         }
134
135         /// <summary>
136         /// Gets the file descriptor of the image file of the remote surface.
137         /// </summary>
138         internal int Fd
139         {
140             get
141             {
142                 if (fd != -1)
143                     return fd;
144
145                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetImageFile(frame, out fd, out size);
146                 if (err != Interop.FrameBroker.ErrorCode.None)
147                 {
148                     Log.Error(logTag, "Failed to get fd of image file");
149                 }
150                 return fd;
151             }
152         }
153
154         /// <summary>
155         /// Gets the size of the image file of the remote surface.
156         /// </summary>
157         internal uint Size
158         {
159             get
160             {
161                 if (size != 0)
162                     return size;
163
164                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetImageFile(frame, out fd, out size);
165                 if (err != Interop.FrameBroker.ErrorCode.None)
166                 {
167                     Log.Error(logTag, "Failed to get size of image file");
168                 }
169                 return size;
170             }
171         }
172
173         /// <summary>
174         /// Gets the file path.
175         /// </summary>
176         internal string FilePath
177         {
178             get
179             {
180                 string filePath = string.Empty;
181                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetFilePath(frame, out filePath);
182                 if (err != Interop.FrameBroker.ErrorCode.None)
183                 {
184                     Log.Error(logTag, "Failed to get file path");
185                 }
186                 return filePath;
187             }
188         }
189
190         /// <summary>
191         /// Gets the file group.
192         /// </summary>
193         internal string FileGroup
194         {
195             get
196             {
197                 string fileGroup = string.Empty;
198                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetFileGroup(frame, out fileGroup);
199                 if (err != Interop.FrameBroker.ErrorCode.None)
200                 {
201                     Log.Error(logTag, "Failed to get file group");
202                 }
203                 return fileGroup;
204             }
205         }
206
207         /// <summary>
208         /// Gets the type of the frame.
209         /// </summary>
210         internal FrameType Type
211         {
212             get
213             {
214                 Interop.FrameBroker.FrameType type = Interop.FrameBroker.FrameType.SplashScreenImage + 1;
215                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetType(frame, out type);
216                 if (err != Interop.FrameBroker.ErrorCode.None)
217                 {
218                     Log.Error(logTag, "Failed to get frame type");
219                 }
220                 return (FrameType)type;
221             }
222         }
223
224         /// <summary>
225         /// Gets the position X.
226         /// </summary>
227         internal int PositionX
228         {
229             get
230             {
231                 int x = -1;
232                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetPositionX(frame, out x);
233                 if (err != Interop.FrameBroker.ErrorCode.None)
234                 {
235                     Log.Error(logTag, "Failed to get position X");
236                 }
237                 return x;
238             }
239         }
240
241         /// <summary>
242         /// Gets the position Y.
243         /// </summary>
244         internal int PositionY
245         {
246             get
247             {
248                 int y = -1;
249                 Interop.FrameBroker.ErrorCode err = Interop.FrameBroker.GetPositionY(frame, out y);
250                 if (err != Interop.FrameBroker.ErrorCode.None)
251                 {
252                     Log.Error(logTag, "Failed to get position Y");
253                 }
254                 return y;
255             }
256         }
257     }
258 }