forked from webinos/Webinos-Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebinos_pzp.js
executable file
·173 lines (160 loc) · 4.74 KB
/
webinos_pzp.js
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
#!/usr/bin/env node
/*******************************************************************************
* Code contributed to the webinos project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*******************************************************************************/
var pzp = require("./webinos/pzp/lib/pzp");
var debug = require("./webinos/pzp/lib/session").common.debug;
var log = new debug("pzp_start");
var fs = require("fs"),
path = require("path");
var options = {};
var pzpInstance;
function help() {
console.log("Usage: webinos_pzp [options]");
console.log("Options:");
console.log("--pzh-host=[ipaddress] host of the pzh (default localhost)");
console.log("--pzh-name=[name] name of the pzh (default \"\")");
console.log("--pzp-name=[name] name of the pzp (default WebinosPzp)");
console.log("--pzp-host=[name] host of the pzp (default localhost)");
console.log("--auth-code=[code] context debug flag (default DEBUG)");
console.log("--preference=[option] preference option (default hub, other option peer)");
process.exit();
}
process.argv.forEach(function (arg) {
var parts;
if (arg.indexOf("--") > -1) {
parts = arg.split("=");
if (parts.length > 1) {
switch (parts[0]) {
case "--pzh-host":
options.pzhHost = parts[1];
break;
case "--pzh-name":
options.pzhName = parts[1];
break;
case "--pzp-host":
options.pzpHost = parts[1];
break;
case "--pzp-name":
options.pzpName = parts[1];
break;
case "--preference":
options.preference = parts[1];
break;
case "--auth-code":
options.code = parts[1]+"="; // added as last letter in qrcode is = but above "split" removes this info
break;
default:
console.log("unknown option: " + parts[0]);
break;
}
}
else if (parts[0] === "--help") {
help();
}
}
});
var fileParams = {},
pzpModules = [
{name: "get42", params: {num: "21"}},
{name: "file", params: fileParams},
{name: "geolocation", params: {connector : "geoip"}},
{name: "applauncher", params: {}},
{name: "sensors", params: {}},
{name: "payment", params: {}},
{name: "tv", params: {}},
{name: "oauth", params: {}},
{name: "deviceorientation", params: {connector : "simulator"}},
{name: "vehicle", params: {connector : "simulator"}},
{name: "context", params: {}},
{name: "authentication", params: {}},
{name: "contacts", params: {}},
{name: "devicestatus", params: {}},
{name: "discovery", params: {}}
];
fs.readFile(path.join(__dirname, "config-pzp.json"), function(err, data) {
var config;
if (err) {
config = {};
}
else {
config = JSON.parse(data);
}
if (!config.pzhHost) {
config.pzhHost = "localhost";
}
if (!config.pzhName) {
config.pzhName = "";
}
if (!config.pzpHost) {
config.pzpHost="localhost";
}
if (!config.pzpName) {
config.pzpName = "";
}
if (!config.code) {
config.code = "DEBUG";
}
if (!config.preference) {
config.prefence = "hub";
}
if (options.pzhHost) {
config.pzhHost = options.pzhHost;
}
if (options.pzhName) {
config.pzhName = options.pzhName;
}
if (options.pzpHost) {
config.pzpHost = options.pzpHost;
}
if (options.pzpName) {
config.pzpName = options.pzpName;
}
if (options.code) {
config.code = options.code;
}
if (options.preference) {
config.preference = options.preference;
}
fileParams.pzpHost = config.pzpHost;
initializePzp(config, pzpModules);
});
function initializePzp(config, pzpModules) {
pzpInstance = new pzp.session();
pzpInstance.initializePzp(config, pzpModules, function(result) {
if (result === "startedPZP"){
log.info("sucessfully started");
}
});
}
//Added in order to be able to get the rpc handler from the current pzp
getPzp = function() {
if (typeof pzpInstance !== "undefined") {
return pzpInstance;
} else {
return null;
}
}
getPzpId = function() {
if (typeof pzpInstance !== "undefined") {
return pzpInstance.sessionId;
}
}
getPzhId = function() {
if (typeof pzpInstance !== "undefined") {
return pzpInstance.config.pzhId;
}
}