/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Threading;
namespace ElmSharp
{
///
/// Provides a synchronization context for the efl application.
///
public class EcoreSynchronizationContext : SynchronizationContext
{
///
/// Initializes a new instance of the EcoreSynchronizationContext class.
///
public EcoreSynchronizationContext()
{
}
///
/// Initilizes a new EcoreSynchronizationContext and install into current thread
///
///
/// It is equivalent
///
/// SetSynchronizationContext(new EcoreSynchronizationContext());
///
///
public static void Initialize()
{
SetSynchronizationContext(new EcoreSynchronizationContext());
}
///
/// Dispatches an asynchronous message to a Ecore main loop.
///
/// The SendOrPostCallback delegate to call.
/// The object passed to the delegate.
/// The Post method starts an asynchronous request to post a message.
public override void Post(SendOrPostCallback d, object state)
{
EcoreMainloop.PostAndWakeUp(() =>
{
d(state);
});
}
///
/// Dispatches a synchronous message to a Ecore main loop
///
/// The SendOrPostCallback delegate to call.
/// The object passed to the delegate.
///
/// The Send method starts a synchronous request to send a message.
public override void Send(SendOrPostCallback d, object state)
{
EcoreMainloop.Send(() =>
{
d(state);
});
}
}
}