File: libtest.cpp

package info (click to toggle)
nxcl 0.9-3.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 560 kB
  • ctags: 412
  • sloc: cpp: 3,149; makefile: 114
file content (135 lines) | stat: -rw-r--r-- 3,776 bytes parent folder | download | duplicates (4)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/***************************************************************************
         libtest: A VERY simple command line test for the NXCL library
                             -------------------
    begin                : June 2007
    copyright            : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
                         :     Author: Sebastian James
    email                : seb@esfnet.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

/*
 * NB NB! This probably doesn't work. It shouldn't be hard to fix
 * though. It will be broken because I changed the signal handler
 * scheme. Seb.
 */

#include "nxclientlib.h"
#include <fstream>

using namespace nxcl;
using namespace std;

ofstream debugLogFile;

// Signal handlers
void writeOut (string msg)
{
	cout << "NXCL> " << msg << endl;
}
void stdinInfo (string msg)
{
	cout << "nxssh<-stdin-" << endl << msg << endl;
}
void stdoutInfo (string msg)
{
	cout << "nxssh-stdout->" << endl << msg << endl;
}
void stderrInfo (string msg)
{
	cout << "nxssh-stderr->" << endl << msg << endl;
}

int main (int argc, char **argv)
{
	NXClientLib lib;
	stringstream ss;

	ss << argv[2];
	string un = ss.str();
	ss.str("");
	ss << argv[3];
	string pw = ss.str();
	ss.str("");

	if (argc!=4) {
		cout << "Usage: libtest IP user pass" << endl;
		return -1;
	}

	debugLogFile.open("/tmp/libtest.log", ios::out|ios::trunc);

	lib.invokeNXSSH("default", argv[1], true, "", 22);
	lib.setUsername(un);
	lib.setPassword(pw);
	lib.setResolution(1280,1024); // This is the size of your screen
	lib.setDepth(24);
	lib.setRender(true);

	NXSessionData theSesh;

	// HARDCODED TEST CASE
	theSesh.sessionName = "TEST";
	theSesh.sessionType = "unix-gnome";
	theSesh.cache = 8;
	theSesh.images = 32;
	theSesh.linkType = "adsl";
	theSesh.render = true;
	theSesh.backingstore = "when_requested";
	theSesh.imageCompressionMethod = 2;
	// theSesh.imageCompressionLevel;
	theSesh.geometry = "800x600+0+0"; // This'll be the size of the session
	theSesh.keyboard = "defkeymap";
	theSesh.kbtype = "pc102/defkeymap";
	theSesh.media = false;
	theSesh.agentServer = "";
	theSesh.agentUser = "";
	theSesh.agentPass = "";
	theSesh.cups = 0;
	theSesh.suspended = false;
	theSesh.fullscreen = true; // If true, theSesh.geometry is ignored

	lib.setSessionData(&theSesh);

	// Set the handler you would like to output messages to the user. We'll just use stdout for this test.
	//lib.callbackWriteSignal.connect (&writeOut);

	// If you want a nice quiet session, leave these signals unconnected
	/*
	lib.stdinSignal.connect (&stdinInfo);
	lib.stdoutSignal.connect (&stdoutInfo);
	lib.stderrSignal.connect (&stderrInfo);
	*/

	//notQProcess& p = lib.getNXSSHProcess();
	notQProcess* p;

	while ((lib.getIsFinished()) == false) {
		// We need to repeatedly check if there is any output to parse.
		if (lib.getReadyForProxy() == false) {
			p = lib.getNXSSHProcess();
			p->probeProcess();
		} else {
			p = lib.getNXSSHProcess();
			p->probeProcess();
			p = lib.getNXProxyProcess();
			p->probeProcess();
		}

		usleep (1000);
	}

	writeOut ("Program finished.");

	debugLogFile.close();

	return 0;
}