--- /dev/null
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
-\r
-Microsoft Visual Studio Solution File, Format Version 12.00\r
-# Visual Studio 14\r
-VisualStudioVersion = 14.0.24720.0\r
-MinimumVisualStudioVersion = 10.0.40219.1\r
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Application", "Tizen.Application\Tizen.Application.csproj", "{859AB097-882E-41F8-A70F-F7C531608FFE}"\r
-EndProject\r
-Global\r
- GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
- Debug|Any CPU = Debug|Any CPU\r
- Release|Any CPU = Release|Any CPU\r
- EndGlobalSection\r
- GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
- {859AB097-882E-41F8-A70F-F7C531608FFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r
- {859AB097-882E-41F8-A70F-F7C531608FFE}.Debug|Any CPU.Build.0 = Debug|Any CPU\r
- {859AB097-882E-41F8-A70F-F7C531608FFE}.Release|Any CPU.ActiveCfg = Release|Any CPU\r
- {859AB097-882E-41F8-A70F-F7C531608FFE}.Release|Any CPU.Build.0 = Release|Any CPU\r
- EndGlobalSection\r
- GlobalSection(SolutionProperties) = preSolution\r
- HideSolutionNode = FALSE\r
- EndGlobalSection\r
-EndGlobal\r
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.24720.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Application", "Tizen.Application\Tizen.Application.csproj", "{663C5A3D-E631-4987-AEE7-F498C56A40FC}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {663C5A3D-E631-4987-AEE7-F498C56A40FC}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
{
internal static partial class AppControl
{
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_create(out SafeAppControlHandle handle);
+ [DllImport(Libraries.Application, EntryPoint = "app_control_create", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int Create(out SafeAppControlHandle handle);
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_destroy(IntPtr handle);
+ [DllImport(Libraries.Application, EntryPoint = "app_control_destroy", CallingConvention = CallingConvention.Cdecl)]
+ private static extern int DangerousDestroy(IntPtr handle);
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_clone(out IntPtr clone, IntPtr handle);
+ [DllImport(Libraries.Application, EntryPoint = "app_control_get_app_id", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetAppId(IntPtr app_control, out IntPtr app_id);
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_get_app_id(IntPtr app_control, out IntPtr app_id);
+ [DllImport(Libraries.Application, EntryPoint = "app_control_get_operation", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetOperation(SafeAppControlHandle handle, out string operation);
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_get_operation(SafeAppControlHandle handle, out IntPtr operation);
-
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_get_uri(SafeAppControlHandle handle, out IntPtr uri);
-
- [DllImport(Libraries.Application, CallingConvention = CallingConvention.Cdecl)]
- private static extern int app_control_get_mime(SafeAppControlHandle handle, out IntPtr mime);
-
- internal static SafeAppControlHandle CreateHandle()
- {
- SafeAppControlHandle handle;
- int err = app_control_create(out handle);
- if (err == 0)
- {
- return handle;
- }
- else
- {
- Debug.WriteLine("Failed to create app_control handle. err = {0}", err);
- return null;
- }
- }
-
- internal static string GetOperation(SafeAppControlHandle handle)
- {
- IntPtr value = IntPtr.Zero;
- try
- {
- int err = app_control_get_operation(handle, out value);
- if (err == 0)
- {
- return Marshal.PtrToStringAuto(value);
- }
- }
- finally
- {
- if (value != IntPtr.Zero)
- {
- Sys.Free(value);
- }
- }
- return null;
- }
-
- internal static string GetMime(SafeAppControlHandle handle)
- {
- IntPtr value = IntPtr.Zero;
- try
- {
- int err = app_control_get_mime(handle, out value);
- if (err == 0)
- {
- return Marshal.PtrToStringAuto(value);
- }
- }
- finally
- {
- if (value != IntPtr.Zero)
- {
- Sys.Free(value);
- }
- }
- return null;
- }
-
- internal static string GetScheme(SafeAppControlHandle handle)
- {
- IntPtr value = IntPtr.Zero;
- try
- {
- int err = app_control_get_uri(handle, out value);
- if (err == 0)
- {
- return Marshal.PtrToStringAuto(value);
- }
- }
- finally
- {
- if (value != IntPtr.Zero)
- {
- Sys.Free(value);
- }
- }
- return null;
- }
+ [DllImport(Libraries.Application, EntryPoint = "app_control_get_uri", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetUri(SafeAppControlHandle handle, out string uri);
+ [DllImport(Libraries.Application, EntryPoint = "app_control_get_mime", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int GetMime(SafeAppControlHandle handle, out string mime);
+
internal sealed class SafeAppControlHandle : SafeHandle
{
public SafeAppControlHandle() : base(IntPtr.Zero, true)
protected override bool ReleaseHandle()
{
- app_control_destroy(handle);
+ DangerousDestroy(handle);
SetHandle(IntPtr.Zero);
return true;
}
{
internal static partial class Application
{
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate bool AppCreateCallback(IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void AppPauseCallback(IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void AppResumeCallback(IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void AppTerminateCallback(IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void AppControlCallback(IntPtr appControl, IntPtr userData);
[StructLayoutAttribute(LayoutKind.Sequential)]
--- /dev/null
+/// Copyright 2016 by Samsung Electronics, Inc.,
+///
+/// This software is the confidential and proprietary information
+/// of Samsung Electronics, Inc. ("Confidential Information"). You
+/// shall not disclose such Confidential Information and shall use
+/// it only in accordance with the terms of the license agreement
+/// you entered into with Samsung.
+
+using System;
+using System.Text;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Aul
+ {
+ private const int MaxMimeLength = 128;
+ private const string FileSchemaPrefix = "file://";
+
+ [DllImport(Libraries.Aul, CallingConvention = CallingConvention.Cdecl)]
+ private static extern int aul_get_mime_from_file(string filename, StringBuilder mimetype, int len);
+
+ internal static string GetMimeFromUri(string uri)
+ {
+ StringBuilder sb = new StringBuilder(MaxMimeLength);
+ int err = aul_get_mime_from_file(
+ uri.StartsWith(FileSchemaPrefix) ? uri.Substring(FileSchemaPrefix.Length) : uri,
+ sb, MaxMimeLength);
+ if (err == 0)
+ {
+ return sb.ToString();
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
/// you entered into with Samsung.
using System;
+using System.Text;
using System.Runtime.InteropServices;
internal static partial class Interop
{
- internal static partial class Sys
+ internal static partial class Glib
{
- [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
- public static extern void Free(IntPtr ptr);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool GSourceFunc(IntPtr userData);
+
+ [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern uint IdleAdd(GSourceFunc d, IntPtr data);
}
}
{
internal static partial class Libraries
{
- public const string Libc = "libc.so.6";
+ public const string Aul = "libaul.so.0";
public const string Application = "libcapi-appfw-application.so.0";
+ public const string Glib = "libglib-2.0.so.0";
}
}
-<?xml version="1.0" encoding="utf-8"?>\r
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />\r
- <PropertyGroup>\r
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
- <ProjectGuid>{859AB097-882E-41F8-A70F-F7C531608FFE}</ProjectGuid>\r
- <OutputType>Library</OutputType>\r
- <AppDesignerFolder>Properties</AppDesignerFolder>\r
- <RootNamespace>Tizen.Application</RootNamespace>\r
- <AssemblyName>Tizen.Application</AssemblyName>\r
- <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>\r
- <FileAlignment>512</FileAlignment>\r
- </PropertyGroup>\r
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
- <DebugSymbols>true</DebugSymbols>\r
- <DebugType>full</DebugType>\r
- <Optimize>false</Optimize>\r
- <OutputPath>bin\Debug\</OutputPath>\r
- <DefineConstants>DEBUG;TRACE</DefineConstants>\r
- <ErrorReport>prompt</ErrorReport>\r
- <WarningLevel>4</WarningLevel>\r
- </PropertyGroup>\r
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
- <DebugType>pdbonly</DebugType>\r
- <Optimize>true</Optimize>\r
- <OutputPath>bin\Release\</OutputPath>\r
- <DefineConstants>TRACE</DefineConstants>\r
- <ErrorReport>prompt</ErrorReport>\r
- <WarningLevel>4</WarningLevel>\r
- </PropertyGroup>\r
- <ItemGroup>\r
- <Reference Include="System" />\r
- <Reference Include="System.Core" />\r
- <Reference Include="System.Xml.Linq" />\r
- <Reference Include="System.Data.DataSetExtensions" />\r
- <Reference Include="Microsoft.CSharp" />\r
- <Reference Include="System.Data" />\r
- <Reference Include="System.Net.Http" />\r
- <Reference Include="System.Xml" />\r
- </ItemGroup>\r
- <ItemGroup>\r
- <Compile Include="Interop\Interop.AppControl.cs" />\r
- <Compile Include="Interop\Interop.Application.cs" />\r
- <Compile Include="Interop\Interop.Libraries.cs" />\r
- <Compile Include="Interop\Interop.Sys.cs" />\r
- <Compile Include="Properties\AssemblyInfo.cs" />\r
- <Compile Include="Tizen.Application\Actor.cs" />\r
- <Compile Include="Tizen.Application\AppControl.cs" />\r
- <Compile Include="Tizen.Application\AppControlFilter.cs" />\r
- <Compile Include="Tizen.Application\Application.cs" />\r
- <Compile Include="Tizen.Application\ApplicationContext.cs" />\r
- <Compile Include="Tizen.Application\CodeExample.cs" />\r
- <Compile Include="Tizen.Application\Page.cs" />\r
- <Compile Include="Tizen.Application\TizenSynchronizationContext.cs" />\r
- </ItemGroup>\r
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
- Other similar extension points exist, see Microsoft.Common.targets.\r
- <Target Name="BeforeBuild">\r
- </Target>\r
- <Target Name="AfterBuild">\r
- </Target>\r
- -->\r
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{663C5A3D-E631-4987-AEE7-F498C56A40FC}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Tizen.Application</RootNamespace>
+ <AssemblyName>Tizen.Application</AssemblyName>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SignAssembly>true</SignAssembly>
+ </PropertyGroup>
+ <PropertyGroup>
+ <AssemblyOriginatorKeyFile>Tizen.Application.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Interop\Interop.AppControl.cs" />
+ <Compile Include="Interop\Interop.Application.cs" />
+ <Compile Include="Interop\Interop.Aul.cs" />
+ <Compile Include="Interop\Interop.Glib.cs" />
+ <Compile Include="Interop\Interop.Libraries.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Tizen.Application\Actor.cs" />
+ <Compile Include="Tizen.Application\AppControl.cs" />
+ <Compile Include="Tizen.Application\AppControlFilter.cs" />
+ <Compile Include="Tizen.Application\Application.cs" />
+ <Compile Include="Tizen.Application\ApplicationContext.cs" />
+ <Compile Include="Tizen.Application\CodeExample.cs" />
+ <Compile Include="Tizen.Application\Page.cs" />
+ <Compile Include="Tizen.Application\TizenSynchronizationContext.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Tizen.Application.snk" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
</Project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <ProjectView>ProjectFiles</ProjectView>
+ </PropertyGroup>
+</Project>
\ No newline at end of file
{
private string _operation;
private string _mime;
- private string _scheme;
+ private string _uri;
private Dictionary<string, object> _data;
public static class Operations
public string Operation { get { return _operation; } }
public string Mime { get { return _mime; } }
- public string Scheme { get { return _scheme; } }
+ public string Uri { get { return _uri; } }
internal AppControl(IntPtr appControlHandle)
{
var handle = new Interop.AppControl.SafeAppControlHandle(appControlHandle);
- _operation = Interop.AppControl.GetOperation(handle);
- _mime = Interop.AppControl.GetMime(handle);
- _scheme = Interop.AppControl.GetScheme(handle);
+ Interop.AppControl.GetOperation(handle, out _operation);
+ Interop.AppControl.GetMime(handle, out _mime);
+ Interop.AppControl.GetUri(handle, out _uri);
}
- public AppControl(string operation, string mime, string scheme)
+ public AppControl(string operation, string mime, string uri)
{
_operation = operation;
_mime = mime;
- _scheme = scheme;
+ _uri = uri;
}
public bool IsLaunchOperation()
using System;
+using System.Text.RegularExpressions;
namespace Tizen.Application
{
{
private readonly string _operation;
private readonly string _mime;
- private readonly string _scheme;
+ private readonly string _uri;
public string Operation { get { return _operation; } }
public string Mime { get { return _mime; } }
- public string Scheme { get { return _scheme; } }
+ public string Uri { get { return _uri; } }
- public AppControlFilter(string operation, string mime = null, string scheme = null)
+ public AppControlFilter(string operation, string mime = null, string uri = null)
{
_operation = operation;
_mime = mime;
- _scheme = scheme;
+ _uri = uri;
}
public override bool Equals(object obj)
AppControlFilter f = obj as AppControlFilter;
if (f == null) return false;
- return (_operation == f._operation) & (_mime == f._mime) & (_scheme == f._scheme);
+ return (_operation == f._operation) & (_mime == f._mime) & (_uri == f._uri);
}
public override int GetHashCode()
{
hash ^= _mime.GetHashCode();
}
- if (_scheme != null)
+ if (_uri != null)
{
- hash ^= _scheme.GetHashCode();
+ hash ^= _uri.GetHashCode();
}
return hash;
}
- public bool IsMatched(AppControl e)
+ private bool IsMimeMatched(string mime)
{
- throw new NotImplementedException();
+ if (_mime == "*" || _mime == "*/*")
+ {
+ return true;
+ }
+ if (String.IsNullOrEmpty(_mime))
+ {
+ return String.IsNullOrEmpty(mime);
+ }
+ Regex pat = new Regex(_mime.Replace("*", ".*"));
+ return pat.IsMatch(mime);
+ }
+
+ private bool IsUriMatched(string uri)
+ {
+ if (_uri == "*")
+ {
+ return true;
+ }
+ if (String.IsNullOrEmpty(_uri))
+ {
+ return String.IsNullOrEmpty(uri);
+ }
+ string schema = _uri.Split(':')[0];
+ if (schema == _uri || _uri.EndsWith("://") || _uri.EndsWith("://*"))
+ {
+ return schema == uri.Split(':')[0];
+ }
+ if (_uri.EndsWith("*"))
+ {
+ return uri.StartsWith(_uri.Substring(0, _uri.Length - 1));
+ }
+ return _uri == uri;
+ }
+
+ public bool IsMatch(AppControl e)
+ {
+ string mime = e.Mime;
+ if (String.IsNullOrEmpty(mime) && !String.IsNullOrEmpty(e.Uri))
+ {
+ mime = Interop.Aul.GetMimeFromUri(e.Uri);
+ }
+ return _operation == e.Operation && IsMimeMatched(mime) && IsUriMatched(e.Uri);
}
}
AppControl appControl = new AppControl(appControlHandle);
foreach (var item in _filterMap)
{
- if (item.Key.IsMatched(appControl))
+ if (item.Key.IsMatch(appControl))
{
// Relaunch?
if (appControl.IsLaunchOperation() && CurrentContext != null && !CurrentContext.Empty())
using System;
using System.Collections.Generic;
-using System.Runtime.InteropServices;
using System.Threading;
-namespace Tizen.Application {
- public class TizenSynchronizationContext : SynchronizationContext {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate bool GSourceFunc(IntPtr userData);
-
- [DllImport("libglib-2.0.so.0 ", CallingConvention = CallingConvention.Cdecl)]
- static extern uint g_idle_add(GSourceFunc d, IntPtr data);
-
- public static void Initialize() {
- SynchronizationContext.SetSynchronizationContext(new TizenSynchronizationContext());
+namespace Tizen.Application
+{
+ internal class TizenSynchronizationContext : SynchronizationContext
+ {
+ public static void Initialize()
+ {
+ SetSynchronizationContext(new TizenSynchronizationContext());
}
- private GSourceFunc wrapperHandler;
+ private Interop.Glib.GSourceFunc wrapperHandler;
private Object transactionLock = new Object();
private int transactionID = 0;
private Dictionary<int, Action> handlerMap = new Dictionary<int, Action>();
- TizenSynchronizationContext() {
- wrapperHandler = new GSourceFunc(Handler);
+ TizenSynchronizationContext()
+ {
+ wrapperHandler = new Interop.Glib.GSourceFunc(Handler);
}
- public override void Post(SendOrPostCallback d, object state) {
- Post(() => {
+ public override void Post(SendOrPostCallback d, object state)
+ {
+ Post(() =>
+ {
d(state);
});
}
- public override void Send(SendOrPostCallback d, object state) {
+ public override void Send(SendOrPostCallback d, object state)
+ {
var mre = new ManualResetEvent(false);
Exception err = null;
- Post(() => {
- try {
+ Post(() =>
+ {
+ try
+ {
d(state);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
err = ex;
- } finally {
+ }
+ finally
+ {
mre.Set();
}
});
mre.WaitOne();
- if (err != null) {
+ if (err != null)
+ {
throw err;
}
}
- public void Post(Action action) {
+ public void Post(Action action)
+ {
int id = 0;
- lock (transactionLock) {
+ lock (transactionLock)
+ {
id = transactionID++;
}
handlerMap.Add(id, action);
- g_idle_add(wrapperHandler, (IntPtr)id);
+ Interop.Glib.IdleAdd(wrapperHandler, (IntPtr)id);
}
- public bool Handler(IntPtr userData) {
+ public bool Handler(IntPtr userData)
+ {
int key = (int)userData;
- if (handlerMap.ContainsKey(key)) {
+ if (handlerMap.ContainsKey(key))
+ {
handlerMap[key]();
handlerMap.Remove(key);
}