Okay that sounds good! I try if understand it in the right way:
I call a function in the callback function from the PJSIP (on_incoming_Call);
This function has access to any Widget or to the main window of Qt;
And in this Function I emit a signal;
Have a look at my Pseudo Source Code
uscsippart.cpp: This is the file where the Callbackfunctions of PJSIP are. This callback function is called when someona calls me. And in this function a call another function (incomingCallFunc).
/* Callback called by the library upon receiving incoming call */
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
pjsip_rx_data *rdata)
{
pjsua_call_info ci;
PJ_UNUSED_ARG(acc_id);
PJ_UNUSED_ARG(rdata);
pjsua_call_get_info(call_id, &ci);
PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!",
(int)ci.remote_info.slen,
ci.remote_info.ptr));
/* Automatically answer incoming calls with 200/OK */
pjsua_call_answer(call_id, 200, NULL, NULL);
incomingCallFunc();
}
/* Callback called by the library upon receiving incoming call */
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
pjsip_rx_data *rdata)
{
pjsua_call_info ci;
PJ_UNUSED_ARG(acc_id);
PJ_UNUSED_ARG(rdata);
pjsua_call_get_info(call_id, &ci);
PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!",
(int)ci.remote_info.slen,
ci.remote_info.ptr));
/* Automatically answer incoming calls with 200/OK */
pjsua_call_answer(call_id, 200, NULL, NULL);
incomingCallFunc();
}
To copy to clipboard, switch view to plain text mode
uscinterface.h: here is a "DummyObject" which should has a signal and further here is the prototyp of the function incomingCallFunc();
#ifndef INTERFACE_H
#define INTERFACE_H
#include <QObject>
class IncomingCall
: public QObject{
Q_OBJECT
public:
signals:
void incomingCallsignal();
};
void incomingCallFunc(void);
#endif
#ifndef INTERFACE_H
#define INTERFACE_H
#include <QObject>
class IncomingCall : public QObject
{
Q_OBJECT
public:
IncomingCall(QObject *parent = 0);
signals:
void incomingCallsignal();
};
void incomingCallFunc(void);
#endif
To copy to clipboard, switch view to plain text mode
uscinterface.cpp: looks like this!
#include "uscinterface.h"
IncomingCall
::IncomingCall (QObject *parent
){
}
void incomingCallFunc()
{
// QT Code to emit a signal
}
#include "uscinterface.h"
IncomingCall::IncomingCall (QObject *parent)
: QObject(parent)
{
}
void incomingCallFunc()
{
// QT Code to emit a signal
}
To copy to clipboard, switch view to plain text mode
uscgui.h:
#ifndef USCGUI_H
#define USCGUI_H
#include <QWidget>
{
Q_OBJECT
public:
signals:
private slots:
void makeCall();
void incomingCall();
private:
};
class UscStatusDisplay
: public QWidget{
Q_OBJECT
public:
UscStatusDisplay
(QWidget *parent
= 0);
};
#endif
#ifndef USCGUI_H
#define USCGUI_H
#include <QWidget>
class QLabel;
class QPushButton;
class UscGuiES01 : public QWidget
{
Q_OBJECT
public:
UscGuiES01(QWidget *parent = 0);
signals:
private slots:
void makeCall();
void incomingCall();
private:
QLabel *statusLabel;
QPushButton *acceptButton;
QPushButton *hangupButton;
QPushButton *dialButton;
};
class UscStatusDisplay : public QWidget
{
Q_OBJECT
public:
UscStatusDisplay(QWidget *parent = 0);
};
#endif
To copy to clipboard, switch view to plain text mode
and now uscgui.cpp: Here I generate my GUI I connect Signals and Slots.
#include <pjlib.h>
#include <pjlib-util.h>
#include <pjmedia.h>
#include <pjmedia-codec.h>
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjsip_ua.h>
#include <pjsua-lib/pjsua.h>
#include <QtGui>
#include "uscgui.h"
#include "uscinterface.h"
UscGuiES01
::UscGuiES01(QWidget *parent
){
statusLabel
= new QLabel(tr
("???"));
acceptButton->setDefault(true);
acceptButton->setEnabled(false);
hangupButton->setEnabled(false);
UscStatusDisplay *uscGuiStatusDisplay = new UscStatusDisplay;
IncomingCall *incomingCall = new IncomingCall;
/*
Insert here the connections for the Signals and Slots
System
*/
connect(dialButton, SIGNAL(clicked()),
this, SLOT(makeCall()));
connect(incomingCall, SIGNAL(incomingCallsignal()),
this, SLOT(incomingCall()));
bottomLayout->addWidget(dialButton);
bottomLayout->addWidget(acceptButton);
bottomLayout->addWidget(hangupButton);
topLayout->addWidget(statusLabel);
topLayout->addWidget(uscGuiStatusDisplay);
mainLayout->addLayout(topLayout);
mainLayout->addLayout(bottomLayout);
setLayout(mainLayout);
setWindowTitle(tr("Universal SIP Client"));
emit
}
/*
Insert here the SLOT Functions
*/
void UscGuiES01::makeCall()
{
pj_str_t uri = pj_str("sip:nb100149@10.17.1.17");
pjsua_call_make_call(0, &uri, 0, NULL, NULL, NULL);
}
void UscGuiES01::incomingCall()
{
acceptButton->setEnabled(true);
hangupButton->setEnabled(true);
}
UscStatusDisplay
::UscStatusDisplay(QWidget *parent
){
setAutoFillBackground(true);
}
#include <pjlib.h>
#include <pjlib-util.h>
#include <pjmedia.h>
#include <pjmedia-codec.h>
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjsip_ua.h>
#include <pjsua-lib/pjsua.h>
#include <QtGui>
#include "uscgui.h"
#include "uscinterface.h"
UscGuiES01::UscGuiES01(QWidget *parent)
: QWidget(parent)
{
statusLabel = new QLabel(tr("???"));
dialButton = new QPushButton(tr("Dial"));
acceptButton = new QPushButton(tr("Accept"));
acceptButton->setDefault(true);
acceptButton->setEnabled(false);
hangupButton = new QPushButton(tr("Hang Up"));
hangupButton->setEnabled(false);
UscStatusDisplay *uscGuiStatusDisplay = new UscStatusDisplay;
IncomingCall *incomingCall = new IncomingCall;
/*
Insert here the connections for the Signals and Slots
System
*/
connect(dialButton, SIGNAL(clicked()),
this, SLOT(makeCall()));
connect(incomingCall, SIGNAL(incomingCallsignal()),
this, SLOT(incomingCall()));
QHBoxLayout *bottomLayout = new QHBoxLayout;
bottomLayout->addWidget(dialButton);
bottomLayout->addWidget(acceptButton);
bottomLayout->addWidget(hangupButton);
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(statusLabel);
topLayout->addWidget(uscGuiStatusDisplay);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addLayout(bottomLayout);
setLayout(mainLayout);
setWindowTitle(tr("Universal SIP Client"));
emit
}
/*
Insert here the SLOT Functions
*/
void UscGuiES01::makeCall()
{
pj_str_t uri = pj_str("sip:nb100149@10.17.1.17");
pjsua_call_make_call(0, &uri, 0, NULL, NULL, NULL);
}
void UscGuiES01::incomingCall()
{
acceptButton->setEnabled(true);
hangupButton->setEnabled(true);
}
UscStatusDisplay::UscStatusDisplay(QWidget *parent)
: QWidget(parent)
{
setPalette(QPalette(QColor(Qt::green)));
setAutoFillBackground(true);
}
To copy to clipboard, switch view to plain text mode
Now I want to emit the signal of the class Incomingcall(uscinterface.h) by the function incomingCallFunc() in uscinterface.cpp. but I don't now how??
Or, another possibility, I want to set in this function the Buttons (accept, hangup) enabled and leave the signals and slots out for this part.
So, how can I implement that this function has access to the widget (uscgui.cpp)
I have no idea?
Best Regards...
Bookmarks