singrdk/base/Kernel/Singularity/Io/CategoryAttributes.cs

389 lines
12 KiB
C#
Raw Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: CategoryAttributes.cs
//
// Warning: This file is compiled into the kernel, and into the runtime.
// In order to get the visibility correct in all cases, some #ifs
// are needed
//
// New Design:
// This now conforms with the ideas presented in the Genesis papers,
// chapter 3. In particular, a device driver is simply a Category,
// and anything that is in an app manifest is either intrinsic to
// apps/installations (and hence not a decoration), or else a
// PropertySet or Category.
using System;
2008-11-17 18:29:00 -05:00
2008-03-05 09:52:00 -05:00
namespace Microsoft.Singularity.Configuration
{
//
// The master Category declaration
//
// Configuration are optional. If none are specified, then the app should
// be thought of as only having one (default) Category.
//
// A class that declares a Category must descend from this class
//
public class CategoryDeclaration
{
}
//////////////////////////////////////////////////////////////////////////
//
// CategoryAttribute
//
// Purpose: Decorates a class derived from CategoryDeclaration to
// indicate that the metadata parser should declare a category
// from the fields in this class
//
// Usage: Must decorate a class derived from CategoryDeclaration
//
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class CategoryAttribute : System.Attribute
{
// <<name>> is the name for this category, to distinguish between
// multiple categories in the manifest
private string name;
public CategoryAttribute(string name)
{
this.name = name;
}
}
//
// The Console Category
//
// Console apps are apps that run in a special Category. We will designate this
// by deriving a new class from CategoryDeclaration to represent this
// special Category, and then creating special field annotations that only
// apply to this Category.
//
public abstract class ConsoleCategoryDeclaration : CategoryDeclaration
{
internal abstract int AppMain();
}
//////////////////////////////////////////////////////////////////////////
//
// ConsoleCategoryAttribute
//
// Purpose: Top-level metadata indicating that an assembly implements the
// Console Category
//
// Usage: Must be applied to a class derived from
// ConsoleCategoryDeclaration
//
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class ConsoleCategoryAttribute : System.Attribute
{
public ConsoleCategoryAttribute()
{
}
2008-11-17 18:29:00 -05:00
private string action;
2008-03-05 09:52:00 -05:00
private string helpMessage;
private bool defaultAction;
public string HelpMessage
{
2008-11-17 18:29:00 -05:00
get {return helpMessage;}
2008-03-05 09:52:00 -05:00
set {helpMessage = value;}
}
public string Action
{
2008-11-17 18:29:00 -05:00
get {return action;}
2008-03-05 09:52:00 -05:00
set {action = value;}
}
public bool DefaultAction
{
2008-11-17 18:29:00 -05:00
get {return defaultAction;}
2008-03-05 09:52:00 -05:00
set {defaultAction = value;}
}
}
//////////////////////////////////////////////////////////////////////////
//
// InputEndpointAttribute
//
2008-11-17 18:29:00 -05:00
// Purpose: Console Input Unicode Pipe declaration
// kinds are "data" and "control". Control is used for a 2nd
2008-03-05 09:52:00 -05:00
// input pipe such as in More and replaces the "keyboard"
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class InputEndpointAttribute : EndpointAttribute {
2008-11-17 18:29:00 -05:00
private string kind;
2008-03-05 09:52:00 -05:00
public InputEndpointAttribute(string kind) {
this.kind = kind;
}
public string Kind {
get {return kind;}
set {kind = value;}
}
}
//////////////////////////////////////////////////////////////////////////
//
// OutputEndpointAttribute
//
2008-11-17 18:29:00 -05:00
// Purpose: Console Input Unicode Pipe declaration
// kinds are "data" and "control". Control is used for a 2nd
2008-03-05 09:52:00 -05:00
// input pipe such as in More and replaces the "keyboard"
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class OutputEndpointAttribute : EndpointAttribute {
2008-11-17 18:29:00 -05:00
private string kind;
2008-03-05 09:52:00 -05:00
public OutputEndpointAttribute(string kind) {
this.kind = kind;
}
public string Kind {
get {return kind;}
set {kind = value;}
}
}
//////////////////////////////////////////////////////////////////////////
//
// EndpointAttribute
//
// Purpose: Any non-ServiceProvider that is a requirement ought to be
// declared with this attribute. This will tell CTR to pre-bind
// the endpoint and will tell the config the type of the channel
// so that names can be resolved without the assembly declaring
// them
//
// Usage: Decorates a field within a class decorated with
// [DriverCategory]. The field should be an endpoint.
//
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class EndpointAttribute : System.Attribute {
2008-11-17 18:29:00 -05:00
public string bindPath;
2008-03-05 09:52:00 -05:00
public EndpointAttribute() {
}
public string Path {
get {return bindPath;}
set {bindPath = value;}
}
}
2008-11-17 18:29:00 -05:00
//////////////////////////////////////////////////////////////////////////
//
// CustomEndpointAttribute
//
// Purpose: Any endpoint that an app does not want the Binder.LoadManifest
// to fill in should be declared with this attribute.
// This will tell CTR to pre-bind
// the endpoint and will tell the config the type of the channel
// so that names can be resolved without the assembly declaring
// them
//
// Usage: Decorates a field within a class decorated with
// [DriverCategory]. The field should be an endpoint.
//
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class CustomEndpointAttribute : EndpointAttribute
{
public CustomEndpointAttribute() {
}
}
2008-03-05 09:52:00 -05:00
//////////////////////////////////////////////////////////////////////////
//
// ExtensionEndpointAttribute
//
// Purpose: Decorate an extension endpoint and indicate that CTR should bind
// the endpoint before client code is invoked.
//
// Usage: Decorates an ExtensionEndpoint field within a class
// decorated with [DriverCategory]
//
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class ExtensionEndpointAttribute : EndpointAttribute
{
public ExtensionEndpointAttribute()
{
}
}
//////////////////////////////////////////////////////////////////////////
//
// ServiceEndpointAttribute
//
// Purpose: Decorate a ServiceProvider endpoint. This indicates that the
// endpoint will be pre-bound, so that the kernel can determine
// names and drivers cannot. The parameter indicates the type of
// channel that is created (second order) from this
// ServiceProvider.
//
// Usage: Decorates a ServiceProvider field within a class decorated
// with [DriverCategory]
//
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class ServiceEndpointAttribute : EndpointAttribute
{
// <<serviceContractType>> is a required parameter. It gives the type
// of the contract that is served over this ServiceProvider
// The Exp is implicit, that is, we can just specify the contract type
//
private System.Type serviceContractType;
2008-11-17 18:29:00 -05:00
//private string bindPath;
2008-03-05 09:52:00 -05:00
public ServiceEndpointAttribute(System.Type epType)
{
serviceContractType = epType;
}
2008-11-17 18:29:00 -05:00
2008-03-05 09:52:00 -05:00
// public string Path
// {
// get {return bindPath;}
// set {bindPath = value;}
// }
#if SINGULARITY_KERNEL
// <<customname>> is a kernel-only hack to let the Hal console set a
// special name for itself.
private string customName;
public string CustomName
{
get { return customName; }
set { customName = value; }
}
#endif
}
//////////////////////////////////////////////////////////////////////////
///
2008-11-17 18:29:00 -05:00
/// Parameter Attributes
2008-03-05 09:52:00 -05:00
///
//////////////////////////////////////////////////////////////////////////
2008-11-17 18:29:00 -05:00
2008-03-05 09:52:00 -05:00
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class StringParameterAttribute : ParameterAttribute
{
2008-11-17 18:29:00 -05:00
private string defaultValue;
2008-03-05 09:52:00 -05:00
//[NotDelayed]
public StringParameterAttribute(string ArgumentName)
2008-11-17 18:29:00 -05:00
:base(ArgumentName)
2008-03-05 09:52:00 -05:00
{
}
public string Default
{
get { return defaultValue; }
set { defaultValue = value; }
}
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class StringArrayParameterAttribute : ParameterAttribute
{
2008-11-17 18:29:00 -05:00
private string[] defaultValue;
2008-03-05 09:52:00 -05:00
//[NotDelayed]
public StringArrayParameterAttribute(string ArgumentName)
2008-11-17 18:29:00 -05:00
:base(ArgumentName)
2008-03-05 09:52:00 -05:00
{
}
public string[] Default
{
get { return defaultValue; }
set { defaultValue = value; }
}
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class LongParameterAttribute : ParameterAttribute
{
2008-11-17 18:29:00 -05:00
private long defaultValue;
2008-03-05 09:52:00 -05:00
public LongParameterAttribute(string ArgumentName)
2008-11-17 18:29:00 -05:00
:base(ArgumentName)
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
defaultValue = -1;
Position = -1;
2008-03-05 09:52:00 -05:00
}
public long Default
{
get { return defaultValue; }
set { defaultValue = value; }
}
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class BoolParameterAttribute : ParameterAttribute
{
2008-11-17 18:29:00 -05:00
private bool defaultValue;
2008-03-05 09:52:00 -05:00
public BoolParameterAttribute(string name)
2008-11-17 18:29:00 -05:00
:base(name)
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
defaultValue = false;
Position = -1;
2008-03-05 09:52:00 -05:00
}
public bool Default
{
get { return defaultValue; }
set { defaultValue = value; }
}
}
2008-11-17 18:29:00 -05:00
2008-03-05 09:52:00 -05:00
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class ParameterAttribute : System.Attribute
{
2008-11-17 18:29:00 -05:00
private int position;
private string helpMessage;
private bool mandatory;
private string name;
2008-03-05 09:52:00 -05:00
public ParameterAttribute(string Name)
{
2008-11-17 18:29:00 -05:00
this.name = Name;
2008-03-05 09:52:00 -05:00
}
public bool Mandatory
{
get { return mandatory; }
set { mandatory = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
2008-11-17 18:29:00 -05:00
public int Position
2008-03-05 09:52:00 -05:00
{
get { return position; }
set { position = value; }
}
public string HelpMessage
{
get { return helpMessage; }
set { helpMessage = value; }
}
2008-11-17 18:29:00 -05:00
}
2008-03-05 09:52:00 -05:00
}