2008-03-05 09:52:00 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// File: TulipController.sg
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
using Microsoft.Singularity.Channels;
|
|
|
|
using Microsoft.Singularity.Io;
|
|
|
|
using Microsoft.Singularity.Io.Net;
|
|
|
|
using Microsoft.Singularity.Directory;
|
|
|
|
using Microsoft.Singularity.Extending;
|
|
|
|
using Microsoft.Singularity.V1.Services;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace Microsoft.Singularity.Drivers.Network.Tulip
|
|
|
|
{
|
|
|
|
internal class TulipController
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
public static int DriverMain(PnicResources! resources)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
ExtensionContract.Exp! ep = (resources.ec).Acquire();
|
|
|
|
ServiceProviderContract.Exp! sp = (resources.nicsp).Acquire();
|
2008-11-17 18:29:00 -05:00
|
|
|
Tulip! device = new Tulip(resources.csr, resources.mem, resources.irq);
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
try {
|
2008-11-17 18:29:00 -05:00
|
|
|
return SharedMain(ep, sp, device);
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
delete ep;
|
|
|
|
delete sp;
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
public static int DriverMain(TulipResources! resources)
|
|
|
|
{
|
|
|
|
ExtensionContract.Exp! ep = (resources.ec).Acquire();
|
|
|
|
ServiceProviderContract.Exp! sp = (resources.nicsp).Acquire();
|
|
|
|
Tulip! device = new Tulip(resources.csr, resources.mem, resources.irq);
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
try {
|
|
|
|
return SharedMain(ep, sp, device);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
finally {
|
|
|
|
delete ep;
|
|
|
|
delete sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
public static int SharedMain(ExtensionContract.Exp! ep,
|
|
|
|
ServiceProviderContract.Exp! sp,
|
|
|
|
Tulip! device)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
device.Initialize();
|
|
|
|
|
|
|
|
ep.SendSuccess();
|
|
|
|
for (bool run = true; run;) {
|
|
|
|
switch receive {
|
|
|
|
case sp.Connect(ServiceContract.Exp:Start! exp):
|
|
|
|
NicDeviceContract.Exp nd = exp as NicDeviceContract.Exp;
|
|
|
|
if (nd != null) {
|
|
|
|
Tracing.Log(Tracing.Debug, "Connect success.");
|
|
|
|
sp.SendAckConnect();
|
|
|
|
TulipDeviceChannel.CreateThread(device, nd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Tracing.Log(Tracing.Error, "Connect failed.");
|
|
|
|
sp.SendNackConnect(exp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sp.ChannelClosed():
|
|
|
|
device.Shutdown();
|
|
|
|
run = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ep.Shutdown():
|
|
|
|
device.Shutdown();
|
|
|
|
ep.SendAckShutdown();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ep.ChannelClosed():
|
|
|
|
device.Shutdown();
|
|
|
|
run = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case unsatisfiable:
|
|
|
|
DebugStub.Break();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|