Skip to content

Commit

Permalink
Add frn connection states
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Dec 22, 2014
1 parent 7a5d8fe commit 6eadd0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/svxlink/modules/frn/QsoFrn.cpp
Expand Up @@ -130,6 +130,7 @@ using namespace sigc;
QsoFrn::QsoFrn(ModuleFrn *module)
: init_ok(false)
, tcp_client(new TcpClient())
, state(STATE_DISCONNECTED)
{
assert(module != 0);

Expand Down Expand Up @@ -241,6 +242,7 @@ bool QsoFrn::initOk(void)
void QsoFrn::connect(void)
{
tcp_client->connect(opt_server, atoi(opt_port.c_str()));
setState(STATE_CONNECTING);
}


Expand Down Expand Up @@ -288,16 +290,28 @@ void QsoFrn::allSamplesFlushed(void)
* Private member functions
*
****************************************************************************/
void QsoFrn::setState(State newState)
{
if (newState != state)
{
state = newState;
stateChange(newState);
}
}


void QsoFrn::onConnected(void)
{
cout << __FUNCTION__ << endl;
setState(STATE_CONNECTED);
}


void QsoFrn::onDisconnected(TcpConnection *conn,
TcpConnection::DisconnectReason reason)
{
cout << __FUNCTION__ << " ";
setState(STATE_DISCONNECTED);
switch (reason)
{
case TcpConnection::DR_HOST_NOT_FOUND:
Expand Down
11 changes: 11 additions & 0 deletions src/svxlink/modules/frn/QsoFrn.h
Expand Up @@ -129,6 +129,12 @@ class QsoFrn
: public Async::AudioSink, public Async::AudioSource, public sigc::trackable
{
public:
typedef enum {
STATE_DISCONNECTED,
STATE_CONNECTING,
STATE_CONNECTED
} State;

/**
* @brief Default constuctor
*/
Expand Down Expand Up @@ -183,6 +189,8 @@ class QsoFrn
*/
virtual void resumeOutput(void);

sigc::signal<void, State> stateChange;

protected:
/**
* @brief The registered sink has flushed all samples
Expand All @@ -201,9 +209,12 @@ class QsoFrn
int onDataReceived(Async::TcpConnection *con, void *data, int len);
void onSendBufferFull(bool is_full);

void setState(State newState);

private:
bool init_ok;
Async::TcpClient *tcp_client;
State state;

std::string opt_server;
std::string opt_port;
Expand Down

0 comments on commit 6eadd0a

Please sign in to comment.