Fix issue for checking return value of Interop (#5491)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.RemoteView / Tizen.Applications / RemoteView.cs
1 /*
2  * Copyright (c) 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 ElmSharp;
18 using System;
19 using System.Runtime.InteropServices;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents the proxy class for the widget application.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     [Obsolete("Deprecated since API10. Will be removed in API12.")]
28     public class RemoteView
29     {
30         /// <summary>
31         /// The event types to send.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         [Obsolete("Deprecated since API10. Will be removed in API12.")]
35         public enum Event
36         {
37             /// <summary>
38             /// Type for feeding the mouse-up event to the widget application.
39             /// </summary>
40             FeedMouseUp,
41
42             /// <summary>
43             /// Type for canceling the click event procedure.
44             /// </summary>
45             CancelClick
46         }
47
48         /// <summary>
49         /// Layout object including preview image, overlay text, loading text, and remote screen image.
50         /// </summary>
51         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
52         /// <since_tizen> 3 </since_tizen>
53         [Obsolete("Deprecated since API10. Will be removed in API12.")]
54         public Layout Layout { get; internal set; }
55
56         /// <summary>
57         /// The widget ID.
58         /// </summary>
59         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
60         /// <since_tizen> 3 </since_tizen>
61         [Obsolete("Deprecated since API10. Will be removed in API12.")]
62         public string Id
63         {
64             get
65             {
66                 IntPtr ptr = Interop.WidgetViewerEvas.GetWidgetId(Layout);
67
68                 return Marshal.PtrToStringAnsi(ptr);
69             }
70         }
71
72         /// <summary>
73         /// The update period.
74         /// </summary>
75         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
76         /// <since_tizen> 3 </since_tizen>
77         [Obsolete("Deprecated since API10. Will be removed in API12.")]
78         public double Period
79         {
80             get
81             {
82                 return Interop.WidgetViewerEvas.GetPeriod(Layout);
83             }
84         }
85
86         /// <summary>
87         /// Contents of the widget.
88         /// </summary>
89         /// <remarks>
90         /// This string can be used for creating contents of the widget again after rebooting a device or it can be recovered from a crash (abnormal status).
91         /// </remarks>
92         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
93         /// <since_tizen> 3 </since_tizen>
94         [Obsolete("Deprecated since API10. Will be removed in API12.")]
95         public string Content
96         {
97             get
98             {
99                 IntPtr ptr = Interop.WidgetViewerEvas.GetContentInfo(Layout);
100
101                 return Marshal.PtrToStringAnsi(ptr);
102             }
103         }
104
105         /// <summary>
106         /// Summarized string of the widget content for accessibility.
107         /// </summary>
108         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
109         /// <since_tizen> 3 </since_tizen>
110         [Obsolete("Deprecated since API10. Will be removed in API12.")]
111         public string Title
112         {
113             get
114             {
115                 IntPtr ptr = Interop.WidgetViewerEvas.GetTitleString(Layout);
116
117                 return Marshal.PtrToStringAnsi(ptr);
118             }
119         }
120
121         internal RemoteView()
122         {
123         }
124
125         internal static void CheckException(Interop.WidgetViewerEvas.ErrorCode err)
126         {
127             if (err != Interop.WidgetViewerEvas.ErrorCode.None)
128             {
129                 switch (err)
130                 {
131                     case Interop.WidgetViewerEvas.ErrorCode.Fault:
132                         throw new InvalidOperationException("Fault at unmanaged code");
133
134                     case Interop.WidgetViewerEvas.ErrorCode.PermissionDenied:
135                         throw new UnauthorizedAccessException();
136
137                     case Interop.WidgetViewerEvas.ErrorCode.NotSupported:
138                         throw new NotSupportedException();
139
140                     case Interop.WidgetViewerEvas.ErrorCode.InvalidParameter:
141                         throw new InvalidOperationException("Invalid parameter error at unmanaged code");
142
143                     case Interop.WidgetViewerEvas.ErrorCode.AlreadyExist:
144                         throw new InvalidOperationException("Already exist");
145
146                     case Interop.WidgetViewerEvas.ErrorCode.MaxExceeded:
147                         throw new InvalidOperationException("Max exceeded");
148
149                     case Interop.WidgetViewerEvas.ErrorCode.Disabled:
150                         throw new InvalidOperationException("Disabled");
151
152                     default:
153                         throw new InvalidOperationException("Invalid Operation");
154                 }
155             }
156         }
157
158         /// <summary>
159         /// Pauses all the connected widget applications.
160         /// </summary>
161         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
162         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
163         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
164         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
165         /// <since_tizen> 3 </since_tizen>
166         [Obsolete("Deprecated since API10. Will be removed in API12.")]
167         public static void PauseAll()
168         {
169             CheckException(Interop.WidgetViewerEvas.NotifyPausedStatusOfViewer());
170         }
171
172         /// <summary>
173         /// Resumes all the connected widget applications.
174         /// </summary>
175         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
176         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
177         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
178         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
179         /// <since_tizen> 3 </since_tizen>
180         [Obsolete("Deprecated since API10. Will be removed in API12.")]
181         public static void ResumeAll()
182         {
183             CheckException(Interop.WidgetViewerEvas.NotifyResumedStatusOfViewer());
184         }
185
186         /// <summary>
187         /// Pauses the widget application which is connected on this proxy.
188         /// </summary>
189         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
190         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
191         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
192         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
193         /// <since_tizen> 3 </since_tizen>
194         [Obsolete("Deprecated since API10. Will be removed in API12.")]
195         public void Pause()
196         {
197             CheckException(Interop.WidgetViewerEvas.PauseWidget(Layout));
198         }
199
200         /// <summary>
201         /// Resumes the widget application which is connected on this proxy.
202         /// </summary>
203         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
204         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
205         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
206         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
207         /// <since_tizen> 3 </since_tizen>
208         [Obsolete("Deprecated since API10. Will be removed in API12.")]
209         public void Resume()
210         {
211             CheckException(Interop.WidgetViewerEvas.ResumeWidget(Layout));
212         }
213
214         /// <summary>
215         /// Sends the event to the widget application which is connected on this proxy.
216         /// </summary>
217         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
218         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
219         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
220         /// <since_tizen> 3 </since_tizen>
221         [Obsolete("Deprecated since API10. Will be removed in API12.")]
222         public void SendEvent(Event ev)
223         {
224             switch (ev)
225             {
226                 case Event.FeedMouseUp:
227                     Interop.WidgetViewerEvas.FeedMouseUpEvent(Layout);
228                     break;
229
230                 case Event.CancelClick:
231                     Interop.WidgetViewerEvas.CancelClickEvent(Layout);
232                     break;
233
234                 default:
235                     throw new NotSupportedException("Not supported event type");
236             }
237
238             int err = Internals.Errors.ErrorFacts.GetLastResult();
239             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
240         }
241
242         internal void HideLoadingMessage()
243         {
244             Interop.WidgetViewerEvas.DisableLoading(Layout);
245             int err = Internals.Errors.ErrorFacts.GetLastResult();
246             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
247         }
248
249         internal void HidePreviewImage()
250         {
251             Interop.WidgetViewerEvas.DisablePreview(Layout);
252             int err = Internals.Errors.ErrorFacts.GetLastResult();
253             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
254         }
255
256         internal void HideOverlayText()
257         {
258             Interop.WidgetViewerEvas.DisableOverlayText(Layout);
259             int err = Internals.Errors.ErrorFacts.GetLastResult();
260             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
261         }
262
263     }
264 }