OpenHome Forum
ohNet Beginner example - Printable Version

+- OpenHome Forum (http://forum.openhome.org)
+-- Forum: OpenHome (/forumdisplay.php?fid=1)
+--- Forum: Net (/forumdisplay.php?fid=5)
+--- Thread: ohNet Beginner example (/showthread.php?tid=1131)



ohNet Beginner example - lion87 - 26-07-2013 09:36 PM

Hi, I just wanted to get started with ohNet and tried to compile some code from the devicestack tutorial.

here are the first lines of the code:

Code:
#include <iostream>
//#include <ohNet/OpenHome/Net/Core/DvDevice.h>
#include <OpenHome/Net/Cpp/DvDevice.h>
#include <string>

using namespace std;
using namespace OpenHome;
using namespace OpenHome::Net;

int main() {

    string k = "uid";
    InitialisationParams* init_params = InitialisationParams::Create();
    UpnpLibrary::Initialise(init_params);
    UpnpLibrary::StartDv();

    std::cout << "!!!END!!!" << std::endl;
    return 0;
}

But when i call UpnpLibrary::StartDv(); the programm terminates without reaching the next line (std::cout...). Is this a normal behaivor?

Where could i find a simple "Hello World" example for ohNet?

regards


RE: ohNet Beginner example - simonc - 27-07-2013 12:44 PM

(26-07-2013 09:36 PM)lion87 Wrote:  Hi, I just wanted to get started with ohNet and tried to compile some code from the devicestack tutorial.

But when i call UpnpLibrary::StartDv(); the programm terminates without reaching the next line (std::cout...). Is this a normal behaivor?

No, this isn't normal behaviour. I can't reproduce it either; the program exits normally for me. What compile/link options are you using?

One other issue with your program is that it exits immediately, probably before the stack has even fully initialised. You'll need to block the main thread until you want your program to terminate. An easy way to do this would be to call getch() in a loop until the user enters say 'q'.

(26-07-2013 09:36 PM)lion87 Wrote:  Where could i find a simple "Hello World" example for ohNet?
If you're using C++, the contents of ohNet/OpenHome/Net/Bindings/Cpp/Device/Test should include some useful examples. You can build these via make [test name] on the command line


RE: ohNet Beginner example - lion87 - 27-07-2013 01:59 PM

(27-07-2013 12:44 PM)simonc Wrote:  
(26-07-2013 09:36 PM)lion87 Wrote:  Hi, I just wanted to get started with ohNet and tried to compile some code from the devicestack tutorial.

But when i call UpnpLibrary::StartDv(); the programm terminates without reaching the next line (std::cout...). Is this a normal behaivor?

No, this isn't normal behaviour. I can't reproduce it either; the program exits normally for me. What compile/link options are you using?

One other issue with your program is that it exits immediately, probably before the stack has even fully initialised. You'll need to block the main thread until you want your program to terminate. An easy way to do this would be to call getch() in a loop until the user enters say 'q'.

(26-07-2013 09:36 PM)lion87 Wrote:  Where could i find a simple "Hello World" example for ohNet?
If you're using C++, the contents of ohNet/OpenHome/Net/Bindings/Cpp/Device/Test should include some useful examples. You can build these via make [test name] on the command line

hi,
I am using eclipse CDT for development on Linux.
i installed ohNet using make install. This seemed to work.
The files were installed into "/usr/local/lib" and "/usr/local/include".

So i set the gcc c++ Linker option in eclipse to:
Library search path (-L): /usr/local/lib/ohNet
and
Libraries (-l): ohNet and ohNetCore

I think more libraries are not necessary for this example right?

Where do i have to put the loop with getch()?


RE: ohNet Beginner example - simonc - 27-07-2013 07:44 PM

(27-07-2013 01:59 PM)lion87 Wrote:  hi,
I am using eclipse CDT for development on Linux.
i installed ohNet using make install. This seemed to work.
The files were installed into "/usr/local/lib" and "/usr/local/include".

So i set the gcc c++ Linker option in eclipse to:
Library search path (-L): /usr/local/lib/ohNet
and
Libraries (-l): ohNet and ohNetCore

I think more libraries are not necessary for this example right?
You shouldn't need to link to anything extra. In fact, I think it should be possible to build linking to ohNetCore only.

I don't have a linux box handy though so it'll be Monday before I can confirm this. (My test build was on Windows.)

(27-07-2013 01:59 PM)lion87 Wrote:  Where do i have to put the loop with getch()?

It needs to go after the call to StartDv(). When you enter the getch() loop, the device stack will be running. You won't be able to usefully interact with it though unless you create a DvDeviceStandard. See the Tests directory referenced in my previous post for some examples on how to create a device.


RE: ohNet Beginner example - simonc - 29-07-2013 04:11 PM

(27-07-2013 07:44 PM)simonc Wrote:  
(27-07-2013 01:59 PM)lion87 Wrote:  hi,
I am using eclipse CDT for development on Linux.
i installed ohNet using make install. This seemed to work.
The files were installed into "/usr/local/lib" and "/usr/local/include".

So i set the gcc c++ Linker option in eclipse to:
Library search path (-L): /usr/local/lib/ohNet
and
Libraries (-l): ohNet and ohNetCore

I think more libraries are not necessary for this example right?
You shouldn't need to link to anything extra. In fact, I think it should be possible to build linking to ohNetCore only.

I don't have a linux box handy though so it'll be Monday before I can confirm this. (My test build was on Windows.)

Your code works for me on linux (debian 2.6.32). I built your code using

Code:
g++ -Wall -pthread -I ohNet/Build/Include/ ohnetdv.cpp ohNet/Build/Obj/Posix/Debug/libohNetCore.a -o ohnet-test

This runs and prints !!!END!!! before exiting cleanly.