Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick start?
05-02-2013, 12:58 PM (This post was last modified: 05-02-2013 01:13 PM by J4N.)
Post: #11
RE: Quick start?
Yeah, I saw the EnableAction, but I don't see what should be the parameter:

In the constructor
Code:
EnableAction(GetPort, GetPortDelegate, ???);

Code:
public delegate ulong GetPortDelegate() ;
public ulong GetPort(){...}

It doesn't accept any of my parameters. I think that Action doesn't accept to have return values.

Either with return value or out parameter.
I saw that I should use

Code:
delegate int OpenHome::Net::Device::DvProvider::ActionDelegate    (    IntPtr     aPtr,
IntPtr     aInvocation    
)

as method, but I just have no idea( and no documentation) about what are those pointer, and how should I use them, and what represent the returned int. And it's very weird to have to deal with pointer in c#, no?
Find all posts by this user
05-02-2013, 01:21 PM (This post was last modified: 05-02-2013 01:28 PM by simonc.)
Post: #12
RE: Quick start?
(05-02-2013 12:58 PM)J4N Wrote:  Yeah, I saw the EnableAction, but I don't see what should be the parameter:

Can you confirm which service you're trying to add please? And whether you have generated your own provider or are using one included with ohNet.

Edit: some more notes on use

The auto-generated provider code provides a base class you derive from.
You need to pass a DvDevice-derived class into its ctor while the device is not in enabled state.

Inside your class ctor, you need to call EnableAction[action_name]() for each action you want your service to offer and EnableProperty[var_name]() for each evented state variable it should provide.

To implement each action, over-ride the virtual action_name() function. To update an evented state variable use SetProperty[var_name]().
Find all posts by this user
05-02-2013, 01:27 PM
Post: #13
RE: Quick start?
(05-02-2013 01:21 PM)simonc Wrote:  
(05-02-2013 12:58 PM)J4N Wrote:  Yeah, I saw the EnableAction, but I don't see what should be the parameter:

Can you confirm which service you're trying to add please? And whether you have generated your own provider or are using one included with ohNet.

Edit: some more notes on use

The auto-generated provider code provides a base class you derive from.
You need to pass a DvDevice-derived class into its ctor while the device is not in enabled state.

Each action in a UPnP service is registered by calling EnableAction[action_name]() and implemented by over-riding a action_name() function.

Each evented state variable is registered by calling EnableProperty[var_name]() and updated by calling SetProperty[var_name]().

Since all your provider where implementing something I didn't need, I just created a "CustomServiceProvider, which extend DvProvider:

Code:
//!! Doesn't compile:
public class CustomServiceProvider:DvProvider
    {
        private Random random = new Random();

        public delegate ulong GetPortDelegate() ;

        public  CustomServiceProvider(DvDevice aDevice, string aDomain, string aType, uint aVersion)
            : base(aDevice, aDomain, aType, aVersion)
        {
            Action func = new Action("GetPort");
            ActionDelegate tt = new ActionDelegate(GetPort);
            EnableAction(func, tt, null);
        }

        private int GetPort(IntPtr aptr, IntPtr ainvocation)
        {
            
        }

        public ulong GetPort()
        {
            return (ulong)random.Next();
        }
        
    }
Find all posts by this user
05-02-2013, 01:33 PM
Post: #14
RE: Quick start?
(05-02-2013 01:27 PM)J4N Wrote:  Since all your provider where implementing something I didn't need, I just created a "CustomServiceProvider, which extend DvProvider:

Ah, there's a much easier way to do this Smile

ohNet provides a tool - OhNetGen - which will translate UPnP service xml into a provider for you. Use of this tool is slightly fiddly but the command line should be something like

ohNetGen.exe --language=cs --stack=dv --xml=[relative path to your service xml] --output=[output dir with trailing backslash] --domain=[yourcompany.com] --type=[your service name] --version=1

If this doesn't work for you, the code is available in OpenHome/Net/T4/OhNetGen.cs. The best way to debug it for now is to add print statements. Or post your service xml, domain etc and I'll give you better instructions.
Find all posts by this user
05-02-2013, 01:39 PM (This post was last modified: 05-02-2013 01:39 PM by J4N.)
Post: #15
RE: Quick start?
I don't have yet my service xml(since I've to create the service first), so how could I do this?

I'm not an huge fan to have a tools to run(and if we forgot, to have nothing that works, on runtime).

For my test, I'm only looking to have a method that has the following signature: ulong GetPort();
Find all posts by this user
05-02-2013, 01:46 PM
Post: #16
RE: Quick start?
(05-02-2013 01:39 PM)J4N Wrote:  I don't have yet my service xml(since I've to create the service first), so how could I do this?

Create a short xml file with the actions / state variables you want for now then extend it as you develop your service.

(05-02-2013 01:39 PM)J4N Wrote:  I'm not an huge fan to have a tools to run(and if we forgot, to have nothing that works, on runtime).

I don't understand this reservation. In case it makes you feel any better, you can treat your service xml as a source file and auto-generate the provider as part of your build process.

(05-02-2013 01:39 PM)J4N Wrote:  For my test, I'm only looking to have a method that has the following signature: ulong GetPort();

Here you go. Look at the UPnP forum docs or xml files in ohNet for examples of how to extend this later.

Code:
<scpd>
    <serviceStateTable>
        <stateVariable>
            <name>A_ARG_Port_Number</name>
            <sendEventsAttribute>no</sendEventsAttribute>
            <dataType>ui4</dataType>
        </stateVariable>
    </serviceStateTable>
    <actionList>
        <action>
            <name>GetPort</name>
            <argumentList>
                <argument>
                    <name>Port</name>
                    <direction>out</direction>
                    <relatedStateVariable>A_ARG_Port_Number</relatedStateVariable>
                </argument>
            </argumentList>
        </action>
    </actionList>
</scpd>
Find all posts by this user
05-02-2013, 02:22 PM
Post: #17
RE: Quick start?
(05-02-2013 01:46 PM)simonc Wrote:  
(05-02-2013 01:39 PM)J4N Wrote:  I'm not an huge fan to have a tools to run(and if we forgot, to have nothing that works, on runtime).

I don't understand this reservation. In case it makes you feel any better, you can treat your service xml as a source file and auto-generate the provider as part of your build process.

We have a solution with something like 250 sub projects, imagine if we have to think to build this because the signature has potentially changed, it's not maintainable for me. I would be more comfortable with something that can be compiled, explored and searched. In addition, some data will comes from the program using this library(like the version).
Find all posts by this user
06-02-2013, 09:56 AM
Post: #18
RE: Quick start?
Do you have some links about how to build this xml file correctly?
Find all posts by this user
06-02-2013, 10:19 AM
Post: #19
RE: Quick start?
(06-02-2013 09:56 AM)J4N Wrote:  Do you have some links about how to build this xml file correctly?

The Service description XML format is specified by the UPnP forum. Try this link:

http://upnp.org/resources/upnpresources.zip

Inside that archive, have a look at "documents/UPnP-arch-DeviceArchitecture-v1.1-20081015.pdf". See the section "2.5 Service description" starting on page 48.
Visit this user's website Find all posts by this user
06-02-2013, 10:50 AM (This post was last modified: 06-02-2013 11:03 AM by simonc.)
Post: #20
RE: Quick start?
(06-02-2013 09:56 AM)J4N Wrote:  Do you have some links about how to build this xml file correctly?

Post #14 basically covers it. Saving the xml as J4N.xml in my onNet directory, I can run

C:\work\ohnet>Build\Tools\ohNetGen.exe --language=cs --stack=dv --xml=J4N.xml --output=Build\ --domain=test.com --type=J4N --version=1

to generate DvTestComJ4N1.cs in my Build directory.
Find all posts by this user


Forum Jump: