Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:lunchtimemama/Mono.Upnp
Browse files Browse the repository at this point in the history
  • Loading branch information
lunchtimemama committed Jul 14, 2010
2 parents 24623a8 + 5bb0d45 commit 7fd9a9f
Show file tree
Hide file tree
Showing 133 changed files with 4,732 additions and 533 deletions.
6 changes: 6 additions & 0 deletions AUTHORS
@@ -0,0 +1,6 @@
Mono.Ssdp:
Aaron Bockover
Scott Thomas

Mono.Upnp:
Scott Thomas
19 changes: 19 additions & 0 deletions COPYING
@@ -0,0 +1,19 @@
Copyright (C) 2008-2010 Novell

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
106 changes: 106 additions & 0 deletions HACKING
@@ -0,0 +1,106 @@
Follow these simple guidelines when hacking on Mono.Upnp and you too will loose weight and find happiness!

C# Style Guidelines
===================

1. Indent with 4 spaces. Tabs are bad. Obviously.

2. Leave room for the Holy Ghost; put a space before parenthesis, like so:

this.ToString ();

2. With namespaces, types, and methods, Ms. Brace gets her own line, like so:

namespace Foo
{ // This
class Bar
{ // Is
public void Bat ()
{ // Stylish
}
}
}

3. Ms. Brace shares a line with statements, however. Now you try sharing:

if (foo != null) {
foo.Bar ();
}

Statements such as else, else-if, catch, and do-while share a line with Ms. Closing Brace. Know what I mean?

if (something) {
...
} else { // This is what I mean
...
}

Always use braces with statements. Always use braces with statements. Always use braces with statements.

4. Properties look like this:

public string Foo { get; set; } // Automatic property

public string Bar { // 1-line accessor
get { return "bar"; }
}

public string Bat { // Multi-line accessor
get {
/* Your
Code
Here */
}
}

5. Private fileds and local variables look_like_this:

string all_lower_case_with_underscores = null;

Method parameters lookLikeThis:

public void Foo (string lowerCaseAndThenUpperCase) // Camal casing
{
}

Everything else (namespaces, types, methods, properties, events, and non-private fields) LookLikeThis:

public class MyClass // Pascal casing
{
protected string NonPrivateField; // Pascal casing

void PrivateMethod () // Pascal casing
{
}

public string PublicProperty { get; set; } // You get the idea
}

6. Lines should not exceed 120 columns. Overlong method and constructor definitions should break for EACH parameter
and indent to the opening parenthesis, like so:

public void CrazySuperLongMethodNameOhEmGeeThisThingIsPracticallyANovel (string parameter1,
string parameter2,
string parameter3)
{
}

Overlong expressions should break at a logical location and indent 4 spaces, like so:

throw new InvalidOperationExceltion (string.Format (
"There is no action named {0} and the device {1}.", actionName, deviceName));

Overlong expressions in a statement declaration should break logically and indent to the opening parenthesis.
In these cases, Ms. Brace gets her own line, like so:

while (parameter1 == null ||
parameter2 == null ||
parameter3 == null)
{
...
}

7. Use the var keyword and array type-inference as much as you possible can!

8. Use NEITHER the "private" visibility modifier on members, NOR the "internal" visibility modifier on types; those
are the default visibility levels. Github is paying for these bits, you know.
23 changes: 21 additions & 2 deletions Mono.Upnp.sln
Expand Up @@ -33,6 +33,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Upnp.Dcp.MediaServer1.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Upnp.Dcp.MSMediaServerRegistrar1", "src\Mono.Upnp.Dcp\Mono.Upnp.Dcp.MediaServer1\Mono.Upnp.Dcp.MSMediaServerRegistrar1\Mono.Upnp.Dcp.MSMediaServerRegistrar1.csproj", "{1203E9D4-B1F3-4838-8275-91782C8EC6E4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DEA343EA-6B89-4360-B169-F0474A32B259}"
ProjectSection(SolutionItems) = preProject
README = README
AUTHORS = AUTHORS
COPYING = COPYING
HACKING = HACKING
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,7 +137,7 @@ Global
{1203E9D4-B1F3-4838-8275-91782C8EC6E4} = {E2789A20-B336-4121-8C5A-2EC6DBD031CA}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = src\Mono.Upnp.Dcp\Mono.Upnp.Dcp.MediaServer1\Mono.Upnp.Dcp.MediaServer1.FileSystem.ConsoleServer\Mono.Upnp.Dcp.MediaServer1.FileSystem.ConsoleServer.csproj
StartupItem = src\Mono.Upnp\Mono.Upnp.GtkClient\Mono.Upnp.GtkClient.csproj
Policies = $0
$0.DotNetNamingPolicy = $1
$1.DirectoryNamespaceAssociation = Flat
Expand All @@ -141,9 +149,20 @@ Global
$3.inheritsSet = VisualStudio
$3.inheritsScope = text/plain
$0.TextStylePolicy = $4
$4.inheritsSet = null
$4.FileWidth = 120
$4.NoTabsAfterNonTabs = True
$4.RemoveTrailingWhitespace = True
$4.EolMarker = Unix
$4.inheritsSet = VisualStudio
$4.inheritsScope = text/plain
$4.scope = text/x-csharp
$0.CSharpFormattingPolicy = $5
$5.IfElseBraceForcement = AddBraces
$5.ForBraceForcement = AddBraces
$5.ForEachBraceForcement = AddBraces
$5.WhileBraceForcement = AddBraces
$5.UsingBraceForcement = AddBraces
$5.FixedBraceForcement = AddBraces
$5.inheritsSet = Mono
$5.inheritsScope = text/x-csharp
$5.scope = text/x-csharp
Expand Down
31 changes: 31 additions & 0 deletions README
@@ -0,0 +1,31 @@
Mono.Upnp is set of client/server libraries for the Universal Plug 'n Play specifications. See http://www.upnp.org.

To build with Visual Studio or MonoDevelop, open Mono.Upnp.sln and build the solution.

To build with from the command line with Mono:
xbuild Mono.Upnp.sln

To build with from the command line with .NET:
msbuild Mono.Upnp.sln

About the projects:
Mono.Ssdp:
An implementation of the Simple Discovery Protocol (see UPnP Device Architecture 1.1, Section 1).

Mono.Upnp:
An implementation of the UPnP Device Archetecture 1.1, Secions 2-5.

Mono.Upnp.GtkClient:
An executable GTK+ user interface for inspecting UPnP devices and services on the network.

Mono.Upnp.Dcp.MediaServer1:
An implementation of the UPnP Audio/Video MediaServer1 Device Control Protocol.

Mono.Upnp.Dcp.MediaServer1.FileSystem:
A MediaServer1 implementation which serves media from the file system.

Mono.Upnp.Dcp.MediaServer1.FileSystem.ConsoleServer:
An executable console program which serves media from the file system.

Mono.Upnp.Dcp.MSMediaServerRegistrar1:
An implementation of the Microsoft MSMediaServerRegistrar1 Device Control Protocol.
Expand Up @@ -32,10 +32,12 @@ namespace Mono.Upnp.Dcp.MSMediaServerRegistrar1
{
public abstract class MSMediaServerRegistrar
{
public static readonly ServiceType ServiceType = new ServiceType ("urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1");
public static readonly ServiceType ServiceType =
new ServiceType ("microsoft.com", "X_MS_MediaReceiverRegistrar", new Version (1, 0));

[UpnpAction]
public virtual void IsAuthorized ([UpnpArgument ("DeviceId")] string deviceId, [UpnpArgument ("Result")] out long result)
public virtual void IsAuthorized ([UpnpArgument ("DeviceId")] string deviceId,
[UpnpArgument ("Result")] out long result)
{
result = IsAuthorized (deviceId);
}
Expand All @@ -44,17 +46,18 @@ public virtual void IsAuthorized ([UpnpArgument ("DeviceId")] string deviceId, [

[UpnpAction]
public virtual void RegisterDevice ([UpnpArgument ("RegistrationRegMsg")]
[UpnpRelatedStateVariable (DataType = "bin.base64")] byte[] registrationRequestMessage,
[UpnpArgument ("RegistrationRespMsg")]
[UpnpRelatedStateVariable (DataType = "bin.base64")] out byte [] registrationResponseMessage)
[UpnpRelatedStateVariable (DataType = "bin.base64")] byte[] registrationRequestMessage,
[UpnpArgument ("RegistrationRespMsg")]
[UpnpRelatedStateVariable (DataType = "bin.base64")] out byte [] registrationResponseMessage)
{
registrationResponseMessage = RegisterDevice (registrationRequestMessage);
}

protected abstract byte[] RegisterDevice (byte[] registrationRequestMessage);

[UpnpAction]
public virtual void IsValidated ([UpnpArgument ("DeviceId")] string deviceId, [UpnpArgument ("Result")] out long result)
public virtual void IsValidated ([UpnpArgument ("DeviceId")] string deviceId,
[UpnpArgument ("Result")] out long result)
{
result = IsAuthorized (deviceId);
}
Expand Down
Expand Up @@ -20,7 +20,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Commandlineparameters>-f "FOOBAR: upnp:" -n "Windows Media Player Sharing" "/home/scott/glee"</Commandlineparameters>
<Commandlineparameters>-f "mac: upnp" "/home/scott/Music/Starfucker - Starfucker (V0)"</Commandlineparameters>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand Down
Expand Up @@ -32,7 +32,7 @@ namespace Mono.Upnp.Dcp.MediaServer1.ConnectionManager1
{
public abstract class ConnectionManager
{
public static readonly ServiceType ServiceType = new ServiceType ("urn:schemas-upnp-org:service:ConnectionManager:1");
public static readonly ServiceType ServiceType = new ServiceType ("schemas-upnp-org", "ConnectionManager", new Version (1, 0));

[UpnpAction]
public virtual void GetProtocolInfo ([UpnpArgumentAttribute ("Source")]
Expand Down
Expand Up @@ -61,7 +61,7 @@ public virtual void Stop ()
}

public static readonly ServiceType ServiceType = new ServiceType (
"urn:schemas-upnp-org:service:ContentDirectory:1");
"schemas-upnp-org", "ContentDirectory", new Version (1, 0));

[UpnpAction]
public virtual void GetSearchCapabilities ([UpnpArgument ("SearchCaps")]
Expand Down
Expand Up @@ -77,9 +77,15 @@ public void SerializeMembersOnly (XmlSerializationContext context)

readonly XmlSerializer serializer = new XmlSerializer ();

protected override string Browse (string objectId, BrowseFlag browseFlag, string filter, int startIndex,
int requestCount, string sortCriteria, out int numberReturned,
out int totalMatches, out string updateId)
protected override string Browse (string objectId,
BrowseFlag browseFlag,
string filter,
int startIndex,
int requestCount,
string sortCriteria,
out int numberReturned,
out int totalMatches,
out string updateId)
{
updateId = "0";
if (browseFlag == BrowseFlag.BrowseDirectChildren) {
Expand All @@ -103,8 +109,11 @@ public void SerializeMembersOnly (XmlSerializationContext context)
}
}

protected abstract IEnumerable<IXmlSerializable> GetChildren (string objectId, int startIndex, int requestCount,
string sortCriteria, out int totalMatches);
protected abstract IEnumerable<IXmlSerializable> GetChildren (string objectId,
int startIndex,
int requestCount,
string sortCriteria,
out int totalMatches);

protected abstract IXmlSerializable GetObject (string objectId);
}
Expand Down
@@ -0,0 +1,74 @@
//
// ObjectBasedQueryProvider.cs
//
// Author:
// Scott Thomas <lunchtimemama@gmail.com>
//
// Copyright (c) 2010 Scott Thomas
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using System.Collections.Generic;

namespace Mono.Upnp.Dcp.MediaServer1.ContentDirectory1
{
public class ObjectBasedQueryProvider
{
Dictionary<Type, ObjectQueryContext> queryContexts = new Dictionary<Type, ObjectQueryContext>();

public IEnumerable<Object> Query (Query query, IEnumerable<Object> objects)
{
if (query == null) {
throw new ArgumentNullException ("query");
} else if (objects == null) {
throw new ArgumentNullException ("objects");
}

foreach (var @object in objects) {
if (Matches (query, @object)) {
yield return @object;
}
}
}

bool Matches (Query query, Object @object)
{
var match = false;
query (new ObjectQueryVisitor (GetQueryContext (@object.GetType ()), @object, result => match = result));
return match;
}

ObjectQueryContext GetQueryContext (Type type)
{
if (type == null) {
return null;
}

ObjectQueryContext context;
if (!queryContexts.TryGetValue (type, out context)) {
context = new ObjectQueryContext (type, GetQueryContext (type.BaseType));
queryContexts[type] = context;
}

return context;
}
}
}

0 comments on commit 7fd9a9f

Please sign in to comment.