singrdk/base/Services/Tests/Dummy/Dummy.sg

90 lines
2.5 KiB
Plaintext

///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: Service\Dummy\Dummy.sg
//
// Note:
//
using System;
using System.Threading;
using Microsoft.SingSharp;
using Microsoft.SingSharp.Reflection;
using Microsoft.Singularity;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.ServiceManager;
using Microsoft.Singularity.Configuration;
using Microsoft.Singularity.Services;
[assembly: Transform(typeof(ServiceResourceTransform))]
namespace Microsoft.Singularity.Services
{
[Category("Service")]
internal sealed class Parameters
{
[Endpoint]
public readonly TRef<ManagedServiceContract.Exp:Start> serviceContractRef;
reflective private Parameters();
}
internal sealed class Dummy : IRunnable
{
private TRef<ThreadTerminationContract.Exp:Start> signalRef;
public void Signal([Claims]ThreadTerminationContract.Exp:Start! ep)
{
signalRef = new TRef<ThreadTerminationContract.Exp:Start>(ep);
}
public void Run()
{
ThreadTerminationContract.Exp:Start signal;
DebugStub.Print("-- Start Dummy Service\n");
assert signalRef != null;
signal = signalRef.Acquire();
for (;;) {
switch receive {
case signal.Stop():
goto exit;
break;
case signal.ChannelClosed():
goto exit;
break;
}
Thread.Sleep(1000);
DebugStub.Print("Dummy\n");
}
exit:
signalRef.Release(signal);
DebugStub.Print("-- End Dummy Service\n");
}
internal static int AppMain(Parameters! config)
{
IRunnable dummy;
IRunnable manageExec;
Thread thread;
ManagedServiceContract.Exp mep;
mep = ((!)config.serviceContractRef).Acquire();
if (mep == null) {
delete mep;
return -1;
}
dummy = new Dummy();
manageExec = new ManagementExec(mep, dummy);
thread = new Thread(new ThreadStart(manageExec.Run));
thread.Start();
return 0;
}
}
}