1 /// Copyright 2016 by Samsung Electronics, Inc.,
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
11 using System.Collections.Generic;
12 using System.Runtime.InteropServices;
13 using Tizen.Internals.Errors;
15 namespace Tizen.Applications
18 /// The AppControl to launch other application or an actor or a service.
20 public class AppControl
22 private const string LogTag = "Tizen.Applications";
24 internal Interop.AppControl.SafeAppControlHandle _handle;
26 private string _operation = null;
27 private string _mime = null;
28 private string _uri = null;
29 private string _category = null;
30 private string _applicationId = null;
32 private ExtraDataCollection _extraData = null;
37 public event EventHandler<AppControlReplyReceivedEventArgs> AppControlReplyReceived;
44 ErrorCode err = Interop.AppControl.Create(out _handle);
45 if (err != ErrorCode.None)
47 throw new InvalidOperationException("Failed to create the appcontrol handle. Err = " + err);
51 #region Public Properties
54 /// The operation to be performed.
56 public string Operation
60 if (String.IsNullOrEmpty(_operation))
62 ErrorCode err = Interop.AppControl.GetOperation(_handle, out _operation);
63 if (err != ErrorCode.None)
65 Log.Warn(LogTag, "Failed to get the operation from the appcontrol. Err = " + err);
72 ErrorCode err = Interop.AppControl.SetOperation(_handle, value);
73 if (err == ErrorCode.None)
79 Log.Warn(LogTag, "Failed to set the operation to the appcontrol. Err = " + err);
85 /// The explicit MIME type of the data.
91 if (String.IsNullOrEmpty(_mime))
93 ErrorCode err = Interop.AppControl.GetMime(_handle, out _mime);
94 if (err != ErrorCode.None)
96 Log.Warn(LogTag, "Failed to get the mime from the appcontrol. Err = " + err);
103 ErrorCode err = Interop.AppControl.SetMime(_handle, value);
104 if (err == ErrorCode.None)
110 Log.Warn(LogTag, "Failed to set the mime to the appcontrol. Err = " + err);
116 /// The URI of the data.
122 if (String.IsNullOrEmpty(_uri))
124 ErrorCode err = Interop.AppControl.GetUri(_handle, out _uri);
125 if (err != ErrorCode.None)
127 Log.Warn(LogTag, "Failed to get the uri from the appcontrol. Err = " + err);
134 ErrorCode err = Interop.AppControl.SetUri(_handle, value);
135 if (err == ErrorCode.None)
141 Log.Warn(LogTag, "Failed to set the uri to the appcontrol. Err = " + err);
149 public string Category
153 if (String.IsNullOrEmpty(_category))
155 ErrorCode err = Interop.AppControl.GetCategory(_handle, out _category);
156 if (err != ErrorCode.None)
158 Log.Warn(LogTag, "Failed to get the category from the appcontrol. Err = " + err);
165 ErrorCode err = Interop.AppControl.SetCategory(_handle, value);
166 if (err == ErrorCode.None)
172 Log.Warn(LogTag, "Failed to set the category to the appcontrol. Err = " + err);
180 public string ApplicationId
184 if (String.IsNullOrEmpty(_applicationId))
186 ErrorCode err = Interop.AppControl.GetAppId(_handle, out _applicationId);
187 if (err != ErrorCode.None)
189 Log.Warn(LogTag, "Failed to get the appId from the appcontrol. Err = " + err);
192 return _applicationId;
196 ErrorCode err = Interop.AppControl.SetAppId(_handle, value);
197 if (err == ErrorCode.None)
199 _applicationId = value;
203 Log.Warn(LogTag, "Failed to set the appId to the appcontrol. Err = " + err);
211 public AppControlLaunchMode LaunchMode
216 ErrorCode err = Interop.AppControl.GetLaunchMode(_handle, out value);
217 if (err != ErrorCode.None)
219 Log.Warn(LogTag, "Failed to get the launchMode from the appcontrol. Err = " + err);
221 return (AppControlLaunchMode)value;
225 ErrorCode err = Interop.AppControl.SetLaunchMode(_handle, (int)value);
226 if (err != ErrorCode.None)
228 Log.Warn(LogTag, "Failed to set the launchMode to the appcontrol. Err = " + err);
233 public ExtraDataCollection ExtraData
237 if (_extraData == null)
239 _extraData = new ExtraDataCollection();
245 #endregion // Public Properties
250 /// <returns></returns>
251 public static IEnumerable<string> GetMatchedApplicationIds(AppControl control)
253 List<string> ids = new List<string>();
254 Interop.AppControl.AppMatchedCallback callback = new Interop.AppControl.AppMatchedCallback(
255 (handle, applicationId, userData) =>
257 List<string> idsList = Marshal.GetObjectForIUnknown(userData) as List<string>;
260 idsList.Add(applicationId);
269 IntPtr pointerToApplicationIds = Marshal.GetIUnknownForObject(ids);
270 if (pointerToApplicationIds != null)
272 ErrorCode err = Interop.AppControl.ForeachAppMatched(control._handle, callback, pointerToApplicationIds);
273 if (err != ErrorCode.None)
275 throw new InvalidOperationException("Failed to get matched appids. err = " + err);
286 /// <param name="request"></param>
287 public static void SendLaunchRequest(AppControl request)
289 throw new NotImplementedException();
295 /// <param name="request"></param>
296 public static void SendLaunchRequestForReply(AppControl request)
298 throw new NotImplementedException();
304 public class ExtraDataCollection
309 /// <param name="key"></param>
310 /// <param name="value"></param>
311 public void Add(string key, string value)
313 throw new NotImplementedException();
319 /// <param name="key"></param>
320 /// <param name="value"></param>
321 public void Add(string key, IEnumerable<string> value)
323 throw new NotImplementedException();
329 /// <typeparam name="T"></typeparam>
330 /// <param name="key"></param>
331 /// <returns></returns>
332 public T Get<T>(string key)
334 throw new NotImplementedException();
340 /// <param name="key"></param>
341 /// <returns></returns>
342 public object Get(string key)
344 throw new NotImplementedException();
350 /// <param name="key"></param>
351 public void Remove(string key)
353 throw new NotImplementedException();