Go to the documentation of this file.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 java.util.ArrayList;
00053
00054 import roboearth.wp5.conn.REInterface;
00055 import ros.NodeHandle;
00056 import ros.Ros;
00057 import ros.RosException;
00058 import ros.ServiceServer;
00059 import ros.pkg.re_srvs.srv.DelActionRecipe;
00060 import ros.pkg.re_srvs.srv.GetActionRecipe;
00061 import ros.pkg.re_srvs.srv.QueryActionRecipes;
00062 import ros.pkg.re_srvs.srv.SearchActionRecipes;
00063 import ros.pkg.re_srvs.srv.SetActionRecipe;
00064 import ros.pkg.re_srvs.srv.UpdateActionRecipe;
00065
00066 public class ActionRecipeHandler extends AbstractHandler {
00067
00074 public ActionRecipeHandler(Ros ros, NodeHandle n) throws RosException {
00075
00076 super(ros, n);
00077
00078 this.n.advertiseService("/re_comm/get_action_recipe", new GetActionRecipe(), new GetActionRecipeCallback());
00079 this.n.advertiseService("/re_comm/set_action_recipe", new SetActionRecipe(), new SetActionRecipeCallback());
00080 this.n.advertiseService("/re_comm/del_action_recipe", new DelActionRecipe(), new DelActionRecipeCallback());
00081 this.n.advertiseService("/re_comm/update_action_recipe", new UpdateActionRecipe(), new UpdateActionRecipeCallback());
00082 this.n.advertiseService("/re_comm/search_action_recipes", new SearchActionRecipes(), new SearchActionRecipesCallback());
00083 this.n.advertiseService("/re_comm/query_action_recipes", new QueryActionRecipes(), new QueryActionRecipesCallback());
00084
00085 ros.logInfo("Module 'ActionRecipeHandler' loaded.");
00086
00087 }
00088
00096 class GetActionRecipeCallback implements ServiceServer.Callback<GetActionRecipe.Request, GetActionRecipe.Response> {
00097
00098 @Override
00099 public GetActionRecipe.Response call(GetActionRecipe.Request req) {
00100
00101 GetActionRecipe.Response res = new GetActionRecipe.Response();
00102 REInterface con = getREConnection(guestInterfaceKey);
00103 String ont = con.requestActionRecipe(req.recipeUID);
00104 if (ont != null) {
00105 res.recipe = ont;
00106 res.success = true;
00107 ros.logInfo("GetActionRecipe (UID: " + req.recipeUID + "): Done");
00108 } else {
00109 res.success = false;
00110 ros.logInfo("GetActionRecipe (UID: " + req.recipeUID + "): Failed");
00111 }
00112
00113 return res;
00114
00115 }
00116
00117 }
00118
00126 class SetActionRecipeCallback implements ServiceServer.Callback<SetActionRecipe.Request, SetActionRecipe.Response> {
00127
00128 @Override
00129 public SetActionRecipe.Response call(SetActionRecipe.Request req) {
00130
00131 SetActionRecipe.Response res = new SetActionRecipe.Response();
00132 res.success = false;
00133
00134 if (req.apiKey != null && req.apiKey.length() > 0) {
00135
00136 REInterface con = getREConnection(req.apiKey);
00137 res.success = con.submitActionRecipe(req.recipe, req.cls, req.id, req.description);
00138 if (res.success) {
00139 ros.logInfo("SetActionRecipe (UID: " + req.cls+"."+req.id + "): Done");
00140 } else {
00141 ros.logInfo("SetActionRecipe (UID: " + req.cls+"."+req.id + "): Failed");
00142 }
00143
00144 } else {
00145 ros.logError("SetActionRecipe (UID: " + req.cls+"."+req.id + "): API key is missing!");
00146 }
00147
00148 return res;
00149
00150 }
00151
00152 }
00153
00161 class DelActionRecipeCallback implements ServiceServer.Callback<DelActionRecipe.Request, DelActionRecipe.Response> {
00162
00163 @Override
00164 public DelActionRecipe.Response call(DelActionRecipe.Request req) {
00165
00166 DelActionRecipe.Response res = new DelActionRecipe.Response();
00167 res.success = false;
00168
00169 if (req.apiKey != null && req.apiKey.length() > 0) {
00170
00171 REInterface con = getREConnection(req.apiKey);
00172 res.success = con.deleteActionRecipe(req.recipeUID);
00173 if (res.success) {
00174 ros.logInfo("DelActionRecipe (UID: " + req.recipeUID + "): Done");
00175 } else {
00176 ros.logInfo("DelActionRecipe (UID: " + req.recipeUID + "): Failed");
00177 }
00178
00179 } else {
00180 ros.logError("DelActionRecipe (UID: " + req.recipeUID + "): API key is missing!");
00181 }
00182
00183 return res;
00184
00185 }
00186
00187 }
00188
00196 class UpdateActionRecipeCallback implements ServiceServer.Callback<UpdateActionRecipe.Request, UpdateActionRecipe.Response> {
00197
00198 @Override
00199 public UpdateActionRecipe.Response call(UpdateActionRecipe.Request req) {
00200
00201 UpdateActionRecipe.Response res = new UpdateActionRecipe.Response();
00202 res.success = false;
00203
00204 if (req.apiKey != null && req.apiKey.length() > 0) {
00205
00206 REInterface con = getREConnection(req.apiKey);
00207 res.success = con.updateActionRecipe(req.uid, req.recipe, req.description);
00208 if (res.success) {
00209 ros.logInfo("UpdateActionRecipe (UID: " + req.uid + "): Done");
00210 } else {
00211 ros.logInfo("UpdateActionRecipe (UID: " + req.uid + "): Failed");
00212 }
00213
00214 } else {
00215 ros.logError("UpdateActionRecipe (UID: " + req.uid + "): API key is missing!");
00216 }
00217
00218 return res;
00219
00220 }
00221
00222 }
00223
00231 class SearchActionRecipesCallback implements ServiceServer.Callback<SearchActionRecipes.Request, SearchActionRecipes.Response> {
00232
00233 @Override
00234 public SearchActionRecipes.Response call(SearchActionRecipes.Request req) {
00235
00236 SearchActionRecipes.Response res = new SearchActionRecipes.Response();
00237 res.success = false;
00238
00239 REInterface con = getREConnection(guestInterfaceKey);
00240 ArrayList<String> uids = new ArrayList<String>();
00241 String[] onts = con.searchActionRecipes(req.searchID, uids);
00242 if (onts != null) {
00243 for (String ont : onts) {
00244 res.recipes.add(ont);
00245 }
00246 res.uids = uids;
00247 res.success = true;
00248 ros.logInfo("SearchActionRecipes (search: " + req.searchID + "): Done");
00249 } else {
00250 res.success = false;
00251 ros.logInfo("SearchActionRecipes (search: " + req.searchID + "): Failed");
00252 }
00253
00254 return res;
00255
00256 }
00257
00258 }
00259
00267 class QueryActionRecipesCallback implements ServiceServer.Callback<QueryActionRecipes.Request, QueryActionRecipes.Response> {
00268
00269 @Override
00270 public QueryActionRecipes.Response call(QueryActionRecipes.Request req) {
00271
00272 QueryActionRecipes.Response res = new QueryActionRecipes.Response();
00273 res.result = "";
00274
00275 REInterface con = getREConnection(guestInterfaceKey);
00276 String result = con.queryActionRecipeDB(req.query);
00277 if (result != null) {
00278 res.result = result;
00279 ros.logInfo("QueryActionRecipe (query:\n" + req.query + "): Done");
00280 } else {
00281 ros.logInfo("QueryActionRecipe (query:\n" + req.query + "): Failed");
00282 }
00283
00284 return res;
00285
00286 }
00287
00288 }
00289
00290 }