[zeromq-dev] [Midly OT] Seeking advice on generic message definition for abstract classes
Claudio Carbone
erupter at libero.it
Mon Dec 17 13:48:26 CET 2012
I've done a bit of work.
Here is an example main with the new class
int main(int argc, char** argv) {
Saetta::Context mycontext;
Saetta::Publisher mypubber(mycontext); //=new Saetta::Server;
Saetta::Subscriber mysubber(mycontext); //=new Saetta::Client;
mysubber.SubscribeTopic("B");
for(int i=0;i<10;i++)
{
mypubber.PubMessage(3,"A","We don't want to see this","1");
mypubber.PubMessage(3,"B","We would like to see this","1");
//mypuber.worker();
usleep(100);
cout << mysubber.worker();
usleep(1500000);
}
mypubber.~Publisher();
mysubber.~Subscriber();
return (EXIT_SUCCESS);
}
I'm seeking help here: the constructors can work like it's depicted
above, or providing them with an external context.
The above mentioned piece of code does not work: when the Publisher
constructor attempts to create the socket, ZMQ_SOCKET returns EFAULT.
I checked with GDB and the context pointer is absolutely correct, so I
can't see where is the problem.
A version that actually works is this
int main(int argc, char** argv) {
void *mycontext = zmq_init(1);
Saetta::Publisher mypubber(mycontext); //=new Saetta::Server;
Saetta::Subscriber mysubber(mycontext); //=new Saetta::Client;
mysubber.SubscribeTopic("B");
for(int i=0;i<10;i++)
{
mypubber.PubMessage(3,"A","We don't want to see this","1");
mypubber.PubMessage(3,"B","We would like to see this","1");
//mypuber.worker();
usleep(100);
cout << mysubber.worker();
usleep(1500000);
}
mypubber.~Publisher();
mysubber.~Subscriber();
return (EXIT_SUCCESS);
}
Attached you'll find the source of the class (currently testing only Pub
and Sub).
As you can see the variables passed are the same, yet when I just pass
the pointer it works, when I pass the whole class it doesn't work.
Hope someone can chime in.
Claudio
On 16/12/12 15:01, Claudio Carbone wrote:
> Hello all.
>
> Recently I've been moving from C to C++ and I'd really like to exploit
> the capabilities of this language.
> One of the scenario I've been thinking about is a ZMQ generic class able
> to do all the work.
>
> Generally speaking abstracting from the socket and context creation is
> easy: you just need to tell the constructor what kind of socket you
> want, and where you want it.
> What would be much more useful and powerful (and complex) would be to
> design a way to pass message syntax in an abstract form, so you can add
> as many messages you want to the class.
>
> That way a sender subclass would create as many sending hooks as message
> types, while a receiver class would create as many callbacks as message
> types.
> I think this would be a nice design, thus I'm asking here for advices
> and ideas about such an implementation.
>
> Thank you
> Claudio
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121217/ea6d6e1f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: saetta.cpp
Type: text/x-c++src
Size: 5894 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121217/ea6d6e1f/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: saetta.h
Type: text/x-chdr
Size: 2528 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121217/ea6d6e1f/attachment.h>
More information about the zeromq-dev
mailing list