summaryrefslogtreecommitdiffstats
path: root/languages/cpp/app_templates/tdeioslave/slave.cpp
blob: d8c7fcb48aada4732993849213a8e2ab58c7b1a0 (plain)
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
83
84
85
86
87
88

#include <tqcstring.h>
#include <tqsocket.h>
#include <tqdatetime.h>
#include <tqbitarray.h>

#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <tdeapplication.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kinstance.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <klocale.h>
#include <kurl.h>
#include <ksock.h>

#include "%{APPNAMELC}.h"

using namespace TDEIO;


tdeio_%{APPNAMELC}Protocol::tdeio_%{APPNAMELC}Protocol(const TQCString &pool_socket, const TQCString &app_socket)
    : SlaveBase("tdeio_%{APPNAMELC}", pool_socket, app_socket)
{
    kdDebug() << "tdeio_%{APPNAMELC}Protocol::tdeio_%{APPNAMELC}Protocol()" << endl;
}


tdeio_%{APPNAMELC}Protocol::~tdeio_%{APPNAMELC}Protocol()
{
    kdDebug() << "tdeio_%{APPNAMELC}Protocol::~tdeio_%{APPNAMELC}Protocol()" << endl;
}


void tdeio_%{APPNAMELC}Protocol::get(const KURL& url )
{
    kdDebug() << "tdeio_%{APPNAMELC}::get(const KURL& url)" << endl ;
    
    kdDebug() << "Seconds: " << url.query() << endl;
    TQString remoteServer = url.host();
    int remotePort = url.port();
    kdDebug() << "myURL: " << url.prettyURL() << endl;
    
    infoMessage(i18n("Looking for %1...").arg( remoteServer ) );
    // Send the mimeType as soon as it is known
    mimeType("text/plain");
    // Send the data
    TQString theData = "This is a test of tdeio_%{APPNAMELC}";
    data(TQCString(theData.local8Bit()));
    data(TQByteArray()); // empty array means we're done sending the data
    finished();
}


void tdeio_%{APPNAMELC}Protocol::mimetype(const KURL & /*url*/)
{
    mimeType("text/plain");
    finished();
}


extern "C"
{
    int kdemain(int argc, char **argv)
    {
        TDEInstance instance( "tdeio_%{APPNAMELC}" );
        
        kdDebug(7101) << "*** Starting tdeio_%{APPNAMELC} " << endl;
        
        if (argc != 4) {
            kdDebug(7101) << "Usage: tdeio_%{APPNAMELC}  protocol domain-socket1 domain-socket2" << endl;
            exit(-1);
        }
        
        tdeio_%{APPNAMELC}Protocol slave(argv[2], argv[3]);
        slave.dispatchLoop();
        
        kdDebug(7101) << "*** tdeio_%{APPNAMELC} Done" << endl;
        return 0;
    }
}