2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Note: Simple Singularity test program.
|
|
|
|
//
|
2008-11-17 18:29:00 -05:00
|
|
|
using System; // Console, String etc
|
|
|
|
using Microsoft.Singularity.Applications; // ApplicationResourceTransform
|
|
|
|
using Microsoft.Singularity.Channels; // TRef
|
|
|
|
using Microsoft.Singularity.Configuration; // ConsoleCategory, InputEndpoint, OutputEndpoint
|
|
|
|
using Microsoft.Singularity.Directory; // DirectoryServiceContract, ErrorCode, DirectoryService, SdsUtils
|
|
|
|
using Microsoft.Singularity.Io; // UnicodePipeContract, DiskDeviceContract
|
|
|
|
using Microsoft.SingSharp.Reflection; // Transform namespace
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
// change "public static int Main(String[] args)" to "internal static int Main(DefaultConfig! config)"
|
|
|
|
[assembly: Transform(typeof(ApplicationResourceTransform))]
|
2008-03-05 09:52:00 -05:00
|
|
|
namespace Microsoft.Singularity.Applications
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
[ConsoleCategory(HelpMessage="Classic Hello World app", DefaultAction=true)]
|
|
|
|
internal class DefaultConfig {
|
|
|
|
[InputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Exp:READY> Stdin;
|
|
|
|
|
|
|
|
[OutputEndpoint("data")]
|
|
|
|
public readonly TRef<UnicodePipeContract.Imp:READY> Stdout;
|
|
|
|
|
|
|
|
reflective internal DefaultConfig();
|
|
|
|
|
|
|
|
internal int AppMain() {
|
|
|
|
return CHello.Main(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
public class CHello
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
public static DiskDeviceContract.Imp:Ready OpenDevice(String! devname)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
DiskDeviceContract.Exp! exp;
|
|
|
|
DiskDeviceContract.Imp! imp;
|
|
|
|
DiskDeviceContract.NewChannel(out imp, out exp);
|
|
|
|
DirectoryServiceContract.Imp ns;
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
// get NS endpoint
|
2008-11-17 18:29:00 -05:00
|
|
|
ns = DirectoryService.NewClientEndpoint();
|
2008-03-05 09:52:00 -05:00
|
|
|
bool success = false;
|
2008-11-17 18:29:00 -05:00
|
|
|
ErrorCode error;
|
|
|
|
success = SdsUtils.Bind(devname, ns, exp, out error);
|
|
|
|
if (!success) {
|
2008-03-05 09:52:00 -05:00
|
|
|
Console.WriteLine("Bind of {0} failed\n", devname);
|
|
|
|
delete imp;
|
|
|
|
delete ns;
|
|
|
|
return null;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
switch receive {
|
|
|
|
case imp.Success():
|
|
|
|
break;
|
|
|
|
case imp.ContractNotSupported():
|
|
|
|
Console.WriteLine("{0} does not support DiskDevice", devname);
|
|
|
|
delete imp;
|
|
|
|
delete ns;
|
|
|
|
return null;
|
|
|
|
case imp.ChannelClosed():
|
|
|
|
Console.WriteLine("DiskDevice channel to {0} closed unexpectedly", devname);
|
|
|
|
delete imp;
|
|
|
|
delete ns;
|
|
|
|
return null;
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
delete ns;
|
|
|
|
return imp;
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
internal static int Main(DefaultConfig! config)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
Console.WriteLine("Hello World!");
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
DiskDeviceContract.Imp device = OpenDevice("/dev/disk0");
|
2008-03-05 09:52:00 -05:00
|
|
|
if (device == null) {
|
|
|
|
Console.WriteLine("Couldn't open disk0");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
delete device;
|
|
|
|
Console.WriteLine("Opened disk0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|