[Mono-dev] sigc++ signal C# wraper

buhochileno at gmail.com buhochileno at gmail.com
Mon Oct 29 19:58:50 EDT 2007


Hi Jon:

Sorry again for all the mail troubles and for write you directly to your 
mail, but I trying to resum the post from my previous mono-devel mail 
account.

About the sigc++ C# wraper, please be patient with me, I love 
programming and I really want to learn this kind of wraper (in other 
situation I write little wraper for common inpout/output function), and 
you must know that this is a very difcult subject to find 
documentation...and also recently I learn how manipulate signal/slot in 
C++ code (I know how to work and define Delegates and Events in C#).

First I try to write your test code only to see if I can understad and 
compile the code, so I write the aliendetector.cc class like:
struct AlienDetector { sigc::signal<void> signal_detected;};
extern "C" void* CreateAlienDetector (){ return new AlienDetector ();}
void (*SignalDetectedHandler) ();
extern "C" void AlienDetector_AddSignalDetected (AlienDetector* 
detector, SignalDetectedHandler handler)
{detector->signal_detected.connect (sigc::ptr_fun(handler));
}

And I add a little dummy "main" only to see if a traditional compiling 
command work:
g++ aliendetector.cc -o aliendetector `pkg-config --cflags --libs 
sigc++-2.0`
//I get...
aliendetector.cc:15: error: ‘SignalDetectedHandler’ is not a type
aliendetector.cc: In function ‘void 
AlienDetector_AddSignalDetected(AlienDetector*, int)’:
aliendetector.cc:17: error: no matching function for call to ‘ptr_fun(int&)’
The second error may be is related to the firs ‘SignalDetectedHandler’ 
is not a type, I try diferent stuff, but I don't know exactly what can I 
change...
Anyway and only to move forward in the building procees of a shared 
library, I comment the "void (*SignalDetectedHandler) ();" stuff and the 
compilation work, but I have some doubts about it:

I use the following command to get the object code:
g++ -fpic -c aliendetector.cc -Wall -g `pkg-config --cflags --libs 
sigc++-2.0` //for the object code without main
gcc: -lsigc-2.0: linker input file unused because linking not done 
//warning output from the compiler
I think that the warning is correct becouse the linking part of the 
process is not done at this stage, or do I miss something??, becouse if 
I don't add the `pkg-config --cflags --libs sigc++-2.0` I don't get the 
.o file.
So later I do a :
g++ -o libaliendetector.so aliendetector.o -shared -Wl,-Bsymbolic -g 
-lsigc-2.0
At least later the C# code only claim about the
missing entry point "AlienDetector_AddSignalDetected" becouse is 
commented for compilation porpuses...

I'm doing the correct compilation steps?, how can I solve the 
‘SignalDetectedHandler’ is not a type problem?

Also I want to show you a little of my work:
I write this little test header WebCamOrbit.h:
#include <sigc++/sigc++.h>
class WebCamOrbit
{public:
WebCamOrbit(); virtual ~WebCamOrbit();
virtual void SetPanTilt(int, int);
//signal accessor:
typedef sigc::signal<void, int, int> type_OnMove;
type_OnMove OnMove();
protected:
type_OnMove m_OnMove;
};
and the implementation WebCamOrbit.cc:
#include "WebCamOrbit.h"
#include <iostream>
WebCamOrbit::WebCamOrbit(){}
WebCamOrbit::~WebCamOrbit(){}
WebCamOrbit::type_OnMove WebCamOrbit::OnMove()
{ return m_OnMove;}
void WebCamOrbit::SetPanTilt(int pan, int tilt)
{ std::cout << "WebCamOrbit::SetPanTilt(int, int) : " << pan << ", " << 
tilt << std::endl;
m_OnMove.emit(pan, tilt);}

Then a "Consumers" class like this:

...//WebCamOrbit wcOrbit;
wcOrbit.OnMove().connect(sigc::mem_fun(this, 
&ImageAnalysis::wcOrbit_OnMove));}
void ImageAnalysis::wcOrbit_OnMove(int pan, int tilt)
{ std::cout << "the class WebCamOrbit trigger the OnMove signal: " << 
pan << ", " << tilt << std::endl;
}

this work like a charm in C++, and I need to write a wrapper for the 
signal exposed by the WebCamOrbit class, so I understend that I have to 
build a shared library with this class right?, and then in some how 
write the C# wrapper to allow to a C# programmer to access to this event 
in a traditional .NET/mono way (with delegates and events). Do you have 
any documentation?, sugestion?.
I understend that may be this is to much easy for someone with your 
experience, but this is a really dificult subject to find 
documentation...so Help me Obi-Wan Kenoby..you are my only hope :-).

sincerely, you new Padawan :-)

Mauricio





More information about the Mono-devel-list mailing list