00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 package roboearth.wp5.module;
00051
00052 import roboearth.wp5.conn.REInterface;
00053 import ros.NodeHandle;
00054 import ros.Ros;
00055 import ros.RosException;
00056 import ros.ServiceServer;
00057 import ros.pkg.re_srvs.srv.DelEnvironmentBinaryFile;
00058 import ros.pkg.re_srvs.srv.DelObjectBinaryFile;
00059 import ros.pkg.re_srvs.srv.GetEnvironmentBinaryFile;
00060 import ros.pkg.re_srvs.srv.GetObjectBinaryFile;
00061 import ros.pkg.re_srvs.srv.SetEnvironmentBinaryFile;
00062 import ros.pkg.re_srvs.srv.SetObjectBinaryFile;
00063 import ros.pkg.re_srvs.srv.UpdateEnvironmentBinaryFile;
00064 import ros.pkg.re_srvs.srv.UpdateObjectBinaryFile;
00065
00066 public class BinaryFileHandler extends AbstractHandler {
00067
00068 public BinaryFileHandler(Ros ros, NodeHandle n) throws RosException {
00069
00070 super(ros, n);
00071
00072 this.n.advertiseService("/re_comm/get_object_binary_file", new GetObjectBinaryFile(), new GetObjectBinaryFileCallback());
00073 this.n.advertiseService("/re_comm/set_object_binary_file", new SetObjectBinaryFile(), new SetObjectBinaryFileCallback());
00074 this.n.advertiseService("/re_comm/del_object_binary_file", new DelObjectBinaryFile(), new DelObjectBinaryFileCallback());
00075 this.n.advertiseService("/re_comm/update_object_binary_file", new UpdateObjectBinaryFile(), new UpdateObjectBinaryFileCallback());
00076
00077 this.n.advertiseService("/re_comm/get_environment_binary_file", new GetEnvironmentBinaryFile(), new GetEnvironmentBinaryFileCallback());
00078 this.n.advertiseService("/re_comm/set_environment_binary_file", new SetEnvironmentBinaryFile(), new SetEnvironmentBinaryFileCallback());
00079 this.n.advertiseService("/re_comm/del_environment_binary_file", new DelEnvironmentBinaryFile(), new DelEnvironmentBinaryFileCallback());
00080 this.n.advertiseService("/re_comm/update_environment_binary_file", new UpdateEnvironmentBinaryFile(), new UpdateEnvironmentBinaryFileCallback());
00081
00082 ros.logInfo("Module 'BinaryFileHandler' loaded.");
00083
00084 }
00085
00093 class GetObjectBinaryFileCallback implements ServiceServer.Callback<GetObjectBinaryFile.Request, GetObjectBinaryFile.Response> {
00094
00095 @Override
00096 public GetObjectBinaryFile.Response call(GetObjectBinaryFile.Request req) {
00097
00098 GetObjectBinaryFile.Response res = new GetObjectBinaryFile.Response();
00099
00100 REInterface con = getREConnection(guestInterfaceKey);
00101 byte[] data = con.requestObjectBinaryFile(req.objectUID, req.filename);
00102
00103 if (data != null) {
00104 res.file.data = data;
00105 res.file.name = req.filename;
00106 res.success = true;
00107 ros.logInfo("GetBinaryFile (UID: "+req.objectUID+", " +
00108 "file: "+req.filename+"): Done");
00109 } else {
00110 res.success = false;
00111 ros.logInfo("GetBinaryFile (UID: "+req.objectUID+", " +
00112 "file: "+req.filename+"): Failed");
00113 }
00114
00115 return res;
00116
00117 }
00118
00119 }
00120
00128 class SetObjectBinaryFileCallback implements ServiceServer.Callback<SetObjectBinaryFile.Request, SetObjectBinaryFile.Response> {
00129
00130 @Override
00131 public SetObjectBinaryFile.Response call(SetObjectBinaryFile.Request req) {
00132
00133 SetObjectBinaryFile.Response res = new SetObjectBinaryFile.Response();
00134 res.success = false;
00135
00136 if (req.apiKey != null && req.apiKey.length() > 0) {
00137
00138 REInterface con = getREConnection(req.apiKey);
00139 res.success = con.submitObjectBinaryFile(req.objectUID, req.file.data, req.file.name);
00140 if (res.success) {
00141 ros.logInfo("SetBinaryFile (UID: "+req.objectUID+", " +
00142 "file: "+req.file.name+"): Done");
00143 } else {
00144 ros.logInfo("SetBinaryFile (UID: "+req.objectUID+", " +
00145 "file: "+req.file.name+"): Failed");
00146 }
00147
00148 } else {
00149 ros.logError("SetBinaryFile (UID: "+req.objectUID+", " +
00150 "file: "+req.file.name+"): API key is missing!");
00151 }
00152
00153 return res;
00154
00155 }
00156
00157 }
00158
00159
00167 class DelObjectBinaryFileCallback implements ServiceServer.Callback<DelObjectBinaryFile.Request, DelObjectBinaryFile.Response> {
00168
00169 @Override
00170 public DelObjectBinaryFile.Response call(DelObjectBinaryFile.Request req) {
00171
00172 DelObjectBinaryFile.Response res = new DelObjectBinaryFile.Response();
00173 res.success = false;
00174
00175 if (req.apiKey != null && req.apiKey.length() > 0) {
00176
00177 REInterface con = getREConnection(req.apiKey);
00178 res.success = con.deleteObjectBinaryFile(req.objectUID, req.filename);
00179 if (res.success) {
00180 ros.logInfo("DelBinaryFile (UID: "+req.objectUID+", " +
00181 "File: '"+req.filename+"'): Done");
00182 } else {
00183 ros.logInfo("DelBinaryFile (UID: "+req.objectUID+", " +
00184 "File: '"+req.filename+"'): Failed");
00185 }
00186
00187 } else {
00188 ros.logError("DelBinaryFile (UID: " + req.objectUID + ", " +
00189 "File: '"+req.filename+"'): API key is missing!");
00190 }
00191
00192 return res;
00193
00194 }
00195
00196 }
00197
00205 class UpdateObjectBinaryFileCallback implements ServiceServer.Callback<UpdateObjectBinaryFile.Request, UpdateObjectBinaryFile.Response> {
00206
00207 @Override
00208 public UpdateObjectBinaryFile.Response call(UpdateObjectBinaryFile.Request req) {
00209
00210 UpdateObjectBinaryFile.Response res = new UpdateObjectBinaryFile.Response();
00211 res.success = false;
00212
00213 if (req.apiKey != null && req.apiKey.length() > 0) {
00214
00215 REInterface con = getREConnection(req.apiKey);
00216 res.success = con.updateObjectBinaryFile(req.objectUID, req.file.data, req.file.name);
00217 if (res.success) {
00218 ros.logInfo("UpdateBinaryFile (UID: " + req.objectUID + ", " +
00219 "File: '"+req.file.name+"'): Done");
00220 } else {
00221 ros.logInfo("UpdateBinaryFile (UID: " + req.objectUID + ", " +
00222 "File: '"+req.file.name+"'): Failed");
00223 }
00224
00225 } else {
00226 ros.logError("UpdateBinaryFile (UID: " + req.objectUID + ", " +
00227 "File: '"+req.file.name+"'): API key is missing!");
00228 }
00229
00230 return res;
00231
00232 }
00233
00234 }
00235
00243 class GetEnvironmentBinaryFileCallback implements ServiceServer.Callback<GetEnvironmentBinaryFile.Request, GetEnvironmentBinaryFile.Response> {
00244
00245 @Override
00246 public GetEnvironmentBinaryFile.Response call(GetEnvironmentBinaryFile.Request req) {
00247
00248 GetEnvironmentBinaryFile.Response res = new GetEnvironmentBinaryFile.Response();
00249
00250 REInterface con = getREConnection(guestInterfaceKey);
00251 byte[] data = con.requestEnvironmentBinaryFile(req.envUID, req.filename);
00252
00253 if (data != null) {
00254 res.file.data = data;
00255 res.file.name = req.filename;
00256 res.success = true;
00257 ros.logInfo("GetBinaryFile (UID: "+req.envUID+", " +
00258 "file: "+req.filename+"): Done");
00259 } else {
00260 res.success = false;
00261 ros.logInfo("GetBinaryFile (UID: "+req.envUID+", " +
00262 "file: "+req.filename+"): Failed");
00263 }
00264
00265 return res;
00266
00267 }
00268
00269 }
00270
00278 class SetEnvironmentBinaryFileCallback implements ServiceServer.Callback<SetEnvironmentBinaryFile.Request, SetEnvironmentBinaryFile.Response> {
00279
00280 @Override
00281 public SetEnvironmentBinaryFile.Response call(SetEnvironmentBinaryFile.Request req) {
00282
00283 SetEnvironmentBinaryFile.Response res = new SetEnvironmentBinaryFile.Response();
00284 res.success = false;
00285
00286 if (req.apiKey != null && req.apiKey.length() > 0) {
00287
00288 REInterface con = getREConnection(req.apiKey);
00289 res.success = con.submitEnvironmentBinaryFile(req.envUID, req.file.data, req.file.name);
00290 if (res.success) {
00291 ros.logInfo("SetBinaryFile (UID: "+req.envUID+", " +
00292 "file: "+req.file.name+"): Done");
00293 } else {
00294 ros.logInfo("SetBinaryFile (UID: "+req.envUID+", " +
00295 "file: "+req.file.name+"): Failed");
00296 }
00297
00298 } else {
00299 ros.logError("SetBinaryFile (UID: "+req.envUID+", " +
00300 "file: "+req.file.name+"): API key is missing!");
00301 }
00302
00303 return res;
00304
00305 }
00306
00307 }
00308
00309
00317 class DelEnvironmentBinaryFileCallback implements ServiceServer.Callback<DelEnvironmentBinaryFile.Request, DelEnvironmentBinaryFile.Response> {
00318
00319 @Override
00320 public DelEnvironmentBinaryFile.Response call(DelEnvironmentBinaryFile.Request req) {
00321
00322 DelEnvironmentBinaryFile.Response res = new DelEnvironmentBinaryFile.Response();
00323 res.success = false;
00324
00325 if (req.apiKey != null && req.apiKey.length() > 0) {
00326
00327 REInterface con = getREConnection(req.apiKey);
00328 res.success = con.deleteEnvironmentBinaryFile(req.envUID, req.filename);
00329 if (res.success) {
00330 ros.logInfo("DelBinaryFile (UID: "+req.envUID+", " +
00331 "File: '"+req.filename+"'): Done");
00332 } else {
00333 ros.logInfo("DelBinaryFile (UID: "+req.envUID+", " +
00334 "File: '"+req.filename+"'): Failed");
00335 }
00336
00337 } else {
00338 ros.logError("DelBinaryFile (UID: " + req.envUID + ", " +
00339 "File: '"+req.filename+"'): API key is missing!");
00340 }
00341
00342 return res;
00343
00344 }
00345
00346 }
00347
00355 class UpdateEnvironmentBinaryFileCallback implements ServiceServer.Callback<UpdateEnvironmentBinaryFile.Request, UpdateEnvironmentBinaryFile.Response> {
00356
00357 @Override
00358 public UpdateEnvironmentBinaryFile.Response call(UpdateEnvironmentBinaryFile.Request req) {
00359
00360 UpdateEnvironmentBinaryFile.Response res = new UpdateEnvironmentBinaryFile.Response();
00361 res.success = false;
00362
00363 if (req.apiKey != null && req.apiKey.length() > 0) {
00364
00365 REInterface con = getREConnection(req.apiKey);
00366 res.success = con.updateEnvironmentBinaryFile(req.envUID, req.file.data, req.file.name);
00367 if (res.success) {
00368 ros.logInfo("UpdateBinaryFile (UID: " + req.envUID + ", " +
00369 "File: '"+req.file.name+"'): Done");
00370 } else {
00371 ros.logInfo("UpdateBinaryFile (UID: " + req.envUID + ", " +
00372 "File: '"+req.file.name+"'): Failed");
00373 }
00374
00375 } else {
00376 ros.logError("UpdateBinaryFile (UID: " + req.envUID + ", " +
00377 "File: '"+req.file.name+"'): API key is missing!");
00378 }
00379
00380 return res;
00381
00382 }
00383
00384 }
00385
00386 }