Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / EcoreSynchronizationContext.cs
1 /*
2  * Copyright (c) 2016 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.Threading;
18
19 namespace ElmSharp
20 {
21
22     /// <summary>
23     /// Provides a synchronization context for the efl application.
24     /// </summary>
25     public class EcoreSynchronizationContext : SynchronizationContext
26     {
27         /// <summary>
28         /// Initializes a new instance of the EcoreSynchronizationContext class.
29         /// </summary>
30         public EcoreSynchronizationContext()
31         {
32         }
33
34         /// <summary>
35         /// Initilizes a new EcoreSynchronizationContext and install into current thread
36         /// </summary>
37         /// <remarks>
38         /// It is equivalent
39         /// <code>
40         /// SetSynchronizationContext(new EcoreSynchronizationContext());
41         /// </code>
42         /// </remarks>
43         public static void Initialize()
44         {
45             SetSynchronizationContext(new EcoreSynchronizationContext());
46         }
47
48         /// <summary>
49         /// Dispatches an asynchronous message to a Ecore main loop.
50         /// </summary>
51         /// <param name="d"><see cref="System.Threading.SendOrPostCallback"/>The SendOrPostCallback delegate to call.</param>
52         /// <param name="state"><see cref="System.Object"/>The object passed to the delegate.</param>
53         /// <remarks>The Post method starts an asynchronous request to post a message.</remarks>
54         public override void Post(SendOrPostCallback d, object state)
55         {
56             EcoreMainloop.PostAndWakeUp(() =>
57             {
58                 d(state);
59             });
60         }
61
62         /// <summary>
63         /// Dispatches a synchronous message to a Ecore main loop
64         /// </summary>
65         /// <param name="d"><see cref="System.Threading.SendOrPostCallback"/>The SendOrPostCallback delegate to call.</param>
66         /// <param name="state"><see cref="System.Object"/>The object passed to the delegate.</param>
67         /// <remarks>
68         /// The Send method starts a synchronous request to send a message.</remarks>
69         public override void Send(SendOrPostCallback d, object state)
70         {
71             EcoreMainloop.Send(() =>
72             {
73                 d(state);
74             });
75         }
76     }
77 }