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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#!/usr/bin/perl -T
################################################################################
# _____ _
# |_ _| |_ ___
# | | | ' \/ -_)
# |_| |_||_\___|
# _ _ ____ _ _
# / \ _ __ ___| |_(_) ___ __ _ | _ \ _ __ ___ (_) ___ ___| |_
# / _ \ | '__/ __| __| |/ __/ _` | | |_) | '__/ _ \| |/ _ \/ __| __|
# / ___ \| | | (__| |_| | (_| (_| | | __/| | | (_) | | __/ (__| |_
# /_/ \_\_| \___|\__|_|\___\__,_| |_| |_| \___// |\___|\___|\__|
# |__/
# The Arctica Modular Remote Computing Framework
#
################################################################################
#
# Copyright (C) 2015-2017 The Arctica Project
# http://http://arctica-project.org/
#
# This code is licensed under AGPL-3+.
#
# AGPL-3+
# -------
# This programm is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This programm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Copyright (C) 2015-2017 Guangzhou Nianguan Electronics Technology Co.Ltd.
# <opensource@gznianguan.com>
# Copyright (C) 2015-2017 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
#
# Note: As this project is licensed under AGPL-3+, all linked-in
# shared libraries derived from the Arctica Project must be
# considered as licensed under AGPL-3+ in this context, too
# (they are normally dual licensed under GPL-2 or AGPL-3+).
#
# Please consider this, when offering a modified version of
# Arctica Browser as a serivce. To comply with AGPL-3+, you have
# to make the modified source code of all components of Arctica
# Browser available to your users.
#
################################################################################
use Data::Dumper;
use X11::Protocol;
use Glib::Object::Introspection;
use Arctica::Core::JABus::Socket;
use Arctica::Core::eventInit qw( genARandom BugOUT );
my $ACO = Arctica::Core::eventInit->new({
app_name=>'arctica-tekicmd',
app_class =>'tekicmd',
app_version=>'0.0.1.2'});
my %args;
foreach my $arg (@ARGV) {
if ($arg =~ /-suspend/) {
if ($args{'do'} eq "") {
$args{'do'} = "suspend";
} else {
BugOUT(0,"Only do one action....");
}
} elsif ($arg =~ /-resume/) {
if ($args{'do'} eq "") {
$args{'do'} = "resume";
} else {
BugOUT(0,"Only do one action....");
}
} elsif ($arg =~ /-clientnxwid\=([\da-zA-Z]{4,})/) {
my $wid = $1;
if ($args{'do'} eq "") {
$args{'do'} = "clientnxwid";
$args{'val'} = $wid;
} else {
BugOUT(0,"Only do one action....");
}
} elsif ($arg =~ /-audiobitrate\=([\d\:]{1,})/) {
my $bitrate = $1;
if ($args{'do'} eq "") {
$args{'do'} = "audiobitrate";
$args{'val'} = $bitrate;
} else {
BugOUT(0,"Only do one action....");
}
} elsif ($arg =~ /-display\=(\:[\d\.]{1,})/) {
my $display_no = $1;
if ($display_no) {
$args{'display'} = $display_no;
}
}
}
if ($args{'display'} eq "") {
if ($ENV{'DISPLAY'}) {
$args{'display'} = $ENV{'DISPLAY'};
} else {
BugOUT(0,"No DISPLAY env or cmd line '-display'?!");
}
} else {
$ENV{'DISPLAY'} = $args{'display'};
}
if ($args{'do'} eq "") {
BugOUT(0,"Do WHAT?");
}
my $teki_socket_id = get_tmp_local_socket_id();
BugOUT(9,"Got TeKi Socket ID: $teki_socket_id");
my $teki_socket = Arctica::Core::JABus::Socket->new($ACO,{
type => "unix",
destination => "local",
is_client => 1,
connect_to => $teki_socket_id,
handle_in_dispatch => {
tekicmd => \&got_response,
},
hooks => {
on_ready => \&do_something,
},
});
$ACO->{'Glib'}{'MainLoop'}->run;
sub do_something {
if ($args{'do'} ne "") {
BugOUT(9,"Sending: $args{'do'} $args{'val'}");
$teki_socket->client_send('tekicmd',{
do => $args{'do'},
val => $args{'val'},
});
sleep 1;
exit 0;#FIXME.... in the future we may want to hang around for something to return...
} else {
BugOUT(0,"This Should never ever happen, EVER!");
}
}
################################################################################
# FIX ME! TMP STUFF, REMOVE IN FINAL VERSION!
sub got_response {
# print Dump(@_);
}
sub get_tmp_local_socket_id {
my $retry_cnt = 0;
my $x11;
while ($retry_cnt < 25) {
$retry_cnt++;
eval {
$x11 = X11::Protocol->new($ENV{'DISPLAY'});
} or warn("NO X11 SERVER '$ENV{'DISPLAY'}'?");
BugOUT(9,"Getting local_socket_id... POST EVAL");
if ($x11) {
my $retry_cnt2 = 0;
while ($retry_cnt2 < 25) {
$retry_cnt2++;
my ($teki_sock_id,undef) = $x11->GetProperty($x11->root, $x11->atom('TEKI_SOCKET'), $x11->atom('STRING'), 0, ~0, 0);
if ($teki_sock_id =~ /^([0-9a-zA-Z]{16,})$/) {
$teki_sock_id = $1;
return $teki_sock_id;
}
warn("No Telekinesis service connected to display '$ENV{'DISPLAY'}'? Retrying in a bit...");
sleep 1;
# else {die("No Telekinesis service connected to display '$ENV{'DISPLAY'}'?");}
}
}
BugOUT(9,"Retrying in a bit...");
sleep 1;
}
BugOUT(0,"We may have given up on contacting X11 server '$ENV{'DISPLAY'}'");
}
|