error on base/sigslot.h file: error: expected ')' before '...' token void emit(Args... args)

225 views
Skip to first unread message

Nabijon Azamov

unread,
Oct 18, 2018, 6:40:07 AM10/18/18
to discuss-webrtc
Hi everone!
I'm trying to use webrtc api  with QT, but I got some errors on base/sigslot.h file while compiling project. Error on this class:

class _opaque_connection
{
private:
typedef void (*emit_t)(const _opaque_connection*);
template< typename FromT, typename ToT >
union union_caster
{
FromT from;
ToT to;
};

emit_t pemit;
has_slots_interface* pdest;
// Pointers to member functions may be up to 16 bytes for virtual classes,
// so make sure we have enough space to store it.
unsigned char pmethod[16];

public:
template< typename DestT, typename ... Args >
_opaque_connection(DestT* pd, void (DestT::*pm)(Args...)) : pdest(pd)
{
typedef void (DestT::*pm_t)(Args...);
static_assert(sizeof(pm_t) <= sizeof(pmethod), "Size of slot function pointer too large.");

std::memcpy(pmethod, &pm, sizeof(pm_t));

typedef void (*em_t)(const _opaque_connection* self, Args...);
union_caster< em_t, emit_t > caster2;
caster2.from = &_opaque_connection::emitter< DestT, Args... >;
pemit = caster2.to;
}

has_slots_interface* getdest() const { return pdest; }

_opaque_connection duplicate(has_slots_interface* newtarget) const
{
_opaque_connection res = *this;
res.pdest = newtarget;
return res;
}

// Just calls the stored "emitter" function pointer stored at construction
// time.
template< typename ... Args >
void emit(Args... args) const
{
typedef void (*em_t)(const _opaque_connection*, Args...);
union_caster< emit_t, em_t > caster;
caster.from = pemit;
(caster.to)(this, args...);
}

private:
template< typename DestT, typename ... Args >
static void emitter(const _opaque_connection* self, Args... args)
{
typedef void (DestT::*pm_t)(Args...);
pm_t pm;
std::memcpy(&pm, self->pmethod, sizeof(pm_t));
(static_cast< DestT* >(self->pdest)->*(pm))(args...);
}
};

error: 
expected ')' before '...' token
   void emit(Args... args) const
                 ^

what is wrong?
HELP

Alexandre GOUAILLARD

unread,
Oct 18, 2018, 8:53:04 AM10/18/18
to discuss...@googlegroups.com
sigslot was ..... 'inspired' by Qt signal-slot mechanism. The consequence is that both define some keywords like "emit".
you need to isolate the Qt headers from the webrtc headers. try for example using the pimpl pattern design / idiom to isolate the webrtc headers in the implementation and the QT headers in the declaration. 



--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/80d08c9e-e7e4-4954-a2f8-e2a59ee04c92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alex. Gouaillard, PhD, PhD, MBA
------------------------------------------------------------------------------------
President - CoSMo Software Consulting, Singapore
------------------------------------------------------------------------------------

Seudin Kasumovic

unread,
Oct 18, 2018, 9:02:57 AM10/18/18
to discuss-webrtc

Simple use undef/define emit.

#undef emit
#include "api/peerconnectioninterface.h"
#define emit

Nabijon Azamov

unread,
Oct 23, 2018, 5:25:20 AM10/23/18
to discuss-webrtc
YES! You are right. It works. Thank you very much  :)

Alexandre GOUAILLARD

unread,
Oct 23, 2018, 5:21:39 PM10/23/18
to discuss...@googlegroups.com
you basically redefined 'emit' to do nothing in the proposed solution.
it surely compiles, but does the application work?

On Tue, Oct 23, 2018 at 11:25 AM Nabijon Azamov <nabijo...@gmail.com> wrote:
YES! You are right. It works. Thank you very much  :)

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Alexandre GOUAILLARD

unread,
Oct 23, 2018, 5:27:02 PM10/23/18
to discuss...@googlegroups.com
at least store the value of the macro before undermining it, and restore it after, even if I'm not sure it will work, it s more likely to:

#ifdef emit
// back-up then undef emit
#define MY_EMIT_STORE emit
#undef emit
#endif

#include "api/peerconnectioninterface.h"

#ifdef MY_EMIT_STORE
// return emit back 
#define emit MY_EMIT_STORE
#undef MY_EMIT_STORE
#endif

Seudin Kasumovic

unread,
Oct 23, 2018, 5:30:47 PM10/23/18
to discuss-webrtc

Alexandre GOUAILLARD

unread,
Oct 25, 2018, 11:31:52 AM10/25/18
to discuss...@googlegroups.com
very interesting, thank you for the information.

So as long as the "emit" defined within webrtc is not used in the calling code, the way you proposed is actually safe. Very nice.


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages