File: EchoLinkDirectory_demo.cpp

package info (click to toggle)
svxlink 15.11-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 14,296 kB
  • ctags: 7,558
  • sloc: cpp: 48,996; tcl: 3,273; ansic: 2,831; sh: 1,054; perl: 335; ruby: 160; makefile: 96
file content (82 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <AsyncCppApplication.h>
#include <EchoLinkDirectory.h>

using namespace std;
using namespace Async;
using namespace EchoLink;

class MyClass : public sigc::trackable
{
  public:
    MyClass(const string& mycall, const string& mypass) : mycall(mycall)
    {
      vector<string> servers;
      servers.push_back("servers.echolink.org");
      dir = new Directory(servers, mycall, mypass, "Testing...");
      dir->statusChanged.connect(mem_fun(*this, &MyClass::onStatusChanged));
      dir->stationListUpdated.connect(
	  mem_fun(*this, &MyClass::onStationListUpdated));
      dir->error.connect(mem_fun(*this, &MyClass::onError));
      dir->makeBusy();	// Set status busy so noone think we are really online
    }
    
    ~MyClass(void)
    {
      delete dir;
    }
    
  private:
    string    	mycall;
    Directory * dir;
    
    void onStatusChanged(StationData::Status status)
    {
      cerr << "Status changed to " << StationData::statusStr(status) << endl;
      if (status == StationData::STAT_BUSY)
      {
	dir->getCalls();
      }
      else
      {
	Application::app().quit();
      }
    }
    
    void onStationListUpdated(void)
    {
      const list<StationData>& stations = dir->stations();
      list<StationData>::const_iterator it;
      for (it = stations.begin(); it != stations.end(); ++it)
      {
	cerr << *it << endl;
      }
      
      cerr << endl << "Message:" << endl;
      cerr << dir->message() << endl;
      
      const StationData *mydata = dir->findCall(mycall);
      cerr << endl << "My station data:" << endl << *mydata << endl;
      dir->makeOffline();
    }
    
    void onError(const string& msg)
    {
      cerr << "ERROR: " << msg << endl;
      Application::app().quit();
    }
};

int main(int argc, char **argv)
{
  CppApplication app; // or QtApplication
  if (argc < 3)
  {
    cerr << "Usage: EchoLinkDispatcher_demo <callsign> <password>\n";
    exit(1);
  }
  MyClass my_class(argv[1], argv[2]);
  app.exec();
}