Author: remi
Date: 2009-03-17 10:29:52 +0100 (Tue, 17 Mar 2009)
New Revision: 4104
Modified:
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py
software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Gadget.py
Log:
* moved gadget start and stop methods
Modified:
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
===================================================================
---
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
2009-03-17 09:01:15 UTC (rev 4103)
+++
software_suite_v2/tuxware/tuxdroidserver/trunk/resources/01_robot_system/resourceGadgetFramework.py
2009-03-17 09:29:52 UTC (rev 4104)
@@ -385,8 +385,11 @@
param = paramStruct.split("=")
if len(param) == 2:
params[param[0]] = param[1]
- if not resourceGadgetFramework.getFramework().startGadgetByUuid(uuid,
- command, params):
+ gadgetStarted = False
+ gadget =
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByUuid(uuid)
+ if gadget != None:
+ gadgetStarted = gadget.start(command, params)
+ if not gadgetStarted:
contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
return headersStruct, contentStruct
@@ -421,8 +424,11 @@
param = paramStruct.split("=")
if len(param) == 2:
params[param[0]] = param[1]
- if not resourceGadgetFramework.getFramework().startGadgetByName(name,
- command, params):
+ gadgetStarted = False
+ gadget =
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByName(name)
+ if gadget != None:
+ gadgetStarted = gadget.start(command, params)
+ if not gadgetStarted:
contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
return headersStruct, contentStruct
@@ -448,7 +454,11 @@
contentStruct = self.getDefaultContentStruct()
contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
uuid = parameters['uuid']
- if not resourceGadgetFramework.getFramework().stopGadgetByUuid(uuid):
+ gadgetStopped = False
+ gadget =
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByUuid(uuid)
+ if gadget != None:
+ gadgetStopped = gadget.stop()
+ if not gadgetStopped:
contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
else:
resourceTTS.stackRemoveByUuid(uuid)
@@ -476,10 +486,13 @@
contentStruct = self.getDefaultContentStruct()
contentStruct['root']['result'] = getStrError(E_TDREST_SUCCESS)
name = parameters['name']
- if not resourceGadgetFramework.getFramework().stopGadgetByName(name):
+ gadgetStopped = False
+ gadget =
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadgetByName(name)
+ if gadget != None:
+ gadgetStopped = gadget.stop()
+ if not gadgetStopped:
contentStruct['root']['result'] = getStrError(E_TDREST_FAILED)
else:
- gadget =
resourceGadgetFramework.getFramework().getGadgetsContainer().getGadget(name)
resourceTTS.stackRemoveByUuid(gadget.getDescription().getUuid())
return headersStruct, contentStruct
Modified:
software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py
===================================================================
--- software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py
2009-03-17 09:01:15 UTC (rev 4103)
+++ software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Framework.py
2009-03-17 09:29:52 UTC (rev 4104)
@@ -317,35 +317,6 @@
self.__onGagdetStoppedCallback = funct
#
--------------------------------------------------------------------------
- # Start a gadget by it uuid.
- # TODO : Move this to the Gadget class.
- #
--------------------------------------------------------------------------
- def startGadgetByUuid(self, gadgetUuid, gadgetCommand, parameters = {}):
- """Start a gadget by it uuid.
- @param gadgetUuid: Gadget uuid.
- @param gadgetCommand: Gadget command.
- @param parameters: Parameters dictionary.
- @return: The success of the gadget starting.
- - When the parameters are not defined the gadget is started with the
- default ones.
- - If a parameter is wrong the default one is set.
- - If a parameter is missing the default one is set.
- """
- if not self.__frameworkBridge.isStarted():
- return False
- cmd = "GADGET"
- subCmd = "START_BY_UUID"
- args = [gadgetUuid, gadgetCommand,]
- for key in parameters:
- args.append(key)
- args.append(parameters[key])
- ret = self.__frameworkBridge.sendCommand(cmd, subCmd, args)
- if ret[0] == "FAILED":
- return False
- else:
- return True
-
- #
--------------------------------------------------------------------------
# Generate a web gadget structure.
# TODO : Move this to the Gadget class.
#
--------------------------------------------------------------------------
@@ -432,40 +403,11 @@
return result
#
--------------------------------------------------------------------------
- # Start a gadget by it name.
- # TODO : Move this to the Gadget class.
- #
--------------------------------------------------------------------------
- def startGadgetByName(self, gadgetName, gadgetCommand, parameters = {}):
- """Start a gadget by it name.
- @param gadgetName: Gadget name.
- @param gadgetCommand: Gadget command.
- @param parameters: Parameters dictionary.
- @return: The success of the gadget starting.
- - When the parameters are not defined the gadget is started with the
- default ones.
- - If a parameter is wrong the default one is set.
- - If a parameter is missing the default one is set.
- """
- if not self.__frameworkBridge.isStarted():
- return False
- cmd = "GADGET"
- subCmd = "START_BY_NAME"
- args = [gadgetName, gadgetCommand,]
- for key in parameters:
- args.append(key)
- args.append(parameters[key])
- ret = self.__frameworkBridge.sendCommand(cmd, subCmd, args)
- if ret[0] == "FAILED":
- return False
- else:
- return True
-
- #
--------------------------------------------------------------------------
# Kill sub-process of a gadget.
# TODO : This functionality must be moved to the java gadget-framework,
# directly at the method "abort" of the "GadgetInstance.java" source.
#
--------------------------------------------------------------------------
- def __killSubProcessOfAGadget(self, gadgetUuid):
+ def _killSubProcessOfAGadget(self, gadgetUuid):
"""Kill sub-process of a gadget.
@param gadgetUuid: Gadget uuid.
"""
@@ -492,50 +434,6 @@
pass
#
--------------------------------------------------------------------------
- # Stop a gadget by it uuid.
- # TODO : Move this to the Gadget class.
- #
--------------------------------------------------------------------------
- def stopGadgetByUuid(self, gadgetUuid):
- """Stop a gadget by it uuid.
- @param gadgetUuid: Gadget uuid.
- @return: The success.
- """
- if not self.__frameworkBridge.isStarted():
- return False
- cmd = "GADGET"
- subCmd = "STOP_BY_UUID"
- args = [gadgetUuid,]
- ret = self.__frameworkBridge.sendCommand(cmd, subCmd, args)
- if ret[0] != "SUCCESS":
- return False
- else:
- self.__killSubProcessOfAGadget(gadgetUuid)
- return True
-
- #
--------------------------------------------------------------------------
- # Stop a gadget by it name.
- # TODO : Move this to the Gadget class.
- #
--------------------------------------------------------------------------
- def stopGadgetByName(self, gadgetName):
- """Stop a gadget by it name.
- @param gadgetName: Gadget name.
- @return: The success.
- """
- if not self.__frameworkBridge.isStarted():
- return False
- cmd = "GADGET"
- subCmd = "STOP_BY_NAME"
- args = [gadgetName,]
- ret = self.__frameworkBridge.sendCommand(cmd, subCmd, args)
- if ret[0] != "SUCCESS":
- return False
- else:
- gadget = self.getGadgetsContainer().getGadgetByName(gadgetName)
- if gadget != None:
-
self.__killSubProcessOfAGadget(gadget.getDescription().getUuid())
- return True
-
- #
--------------------------------------------------------------------------
# Stop all started gadgets.
# TODO : Move this to the GadgetsContainer class.
#
--------------------------------------------------------------------------
@@ -552,7 +450,7 @@
return False
else:
for gadget in self.getGadgetsContainer().getGadgets():
-
self.__killSubProcessOfAGadget(gadget.getDescription().getUuid())
+
self._killSubProcessOfAGadget(gadget.getDescription().getUuid())
return True
#
--------------------------------------------------------------------------
Modified: software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Gadget.py
===================================================================
--- software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Gadget.py
2009-03-17 09:01:15 UTC (rev 4103)
+++ software_suite_v2/tuxware/tuxdroidserver/trunk/util/gadgets/Gadget.py
2009-03-17 09:29:52 UTC (rev 4104)
@@ -128,3 +128,52 @@
for parameter in self.__parameters:
result.append(parameter.getName())
return result
+
+ #
--------------------------------------------------------------------------
+ # Start this gadget.
+ #
--------------------------------------------------------------------------
+ def start(self, command, parameters = {}):
+ """Start this gadget.
+ @param command: Command name to start the gadget.
+ @param parameters: Parameters of the gadget as dictionary.
+ @return: The success of the gadget starting.
+ - When the parameters are not defined the gadget is started with the
+ default ones.
+ - If a parameter is wrong the default one is set.
+ - If a parameter is missing the default one is set.
+ """
+ frameworkBridge =
self.getContainer().getFramework().getFrameworkBridge()
+ if not frameworkBridge.isStarted():
+ return False
+ cmd = "GADGET"
+ subCmd = "START_BY_UUID"
+ args = [self.getDescription().getUuid(), command,]
+ for key in parameters:
+ args.append(key)
+ args.append(parameters[key])
+ ret = frameworkBridge.sendCommand(cmd, subCmd, args)
+ if ret[0] == "FAILED":
+ return False
+ else:
+ return True
+
+ #
--------------------------------------------------------------------------
+ # Stop the gadget.
+ #
--------------------------------------------------------------------------
+ def stop(self):
+ """Stop the gadget.
+ """
+ framework = self.getContainer().getFramework()
+ frameworkBridge = framework.getFrameworkBridge()
+ if not frameworkBridge.isStarted():
+ return False
+ cmd = "GADGET"
+ subCmd = "STOP_BY_UUID"
+ args = [self.getDescription().getUuid(),]
+ ret = frameworkBridge.sendCommand(cmd, subCmd, args)
+ if ret[0] != "SUCCESS":
+ return False
+ else:
+ # TODO : Will be removed
+ framework._killSubProcessOfAGadget(self.getDescription().getUuid())
+ return True
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn