# Copyright (c) 2000-2001 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

"""PlanListener module.

Defines the PlanListenerInterface and two trivial implementations.
"""

__revision__ = "$Id: PlanListener.py,v 1.10 2001/11/06 13:30:39 alf Exp $"

class PlanListenerInterface :
    """PlanListener Interface"""
    
    def fireTransition(self,planId,transitionId):
        raise NameError("method not implemented in implementing class")

    def transitionStatusChanged(self,planId,transitionId,status):
        raise NameError("method not implemented in implementing class")

    def stepStatusChanged(self,planId,stepId,status):
        raise NameError("method not implemented in implementing class")

    def planStatusChanged(self,planId,status):
        raise NameError("method not implemented in implementing class")

    def instanciateRecipe(self,planId,recipeName):
        raise NameError("method not implemented in implementing class")

    def planAddElement(self,planId,elementId):
        raise NameError("method not implemented in implementing class")
        
    def planRemoveElement(self,planId,elementId):
        raise NameError("method not implemented in implementing class")


class PlanListenerImplementation(PlanListenerInterface) :
    """PlanListener Implementation (pass on everything)"""
    
    def fireTransition(self,planId,transitionId):
        pass

    def transitionStatusChanged(self,planId,transitionId,status):
        pass

    def stepStatusChanged(self,planId,stepId,status):
        pass

    def planStatusChanged(self,planId,status):
        pass

    def instanciateRecipe(self,planId,recipeName):
        pass

    def planAddElement(self,planId,elementId):
        pass
        
    def planRemoveElement(self,planId,elementId):
        pass


class PlanListenerPrintImplementation(PlanListenerInterface) :
    """PlanListener Implementation (print everything)"""
    def __init__(self):
        self.plans_dict = {}
        
    def fireTransition(self,planId,transitionId):
        print "Plan %s (%s) firing transition %s" % (planId, self.plans_dict[planId], transitionId)

    def transitionStatusChanged(self,planId,transitionId,status):
        print "Plan %s (%s) transition %s changed to %s" % \
              (planId, self.plans_dict[planId], transitionId,status)

    def stepStatusChanged(self,planId,stepId,status):
        print "Plan %s (%s) step %s changed to %s" % \
              (planId,self. plans_dict[planId],stepId, status)

    def planStatusChanged(self,planId,status):
        print "Plan %s (%s) changed to %s" % (planId, self.plans_dict[planId],status)

    def instanciateRecipe(self,planId,recipeName):
        self.plans_dict[planId] = recipeName
        print "New plan %s made from recipe %s" % (planId, recipeName)

    def planAddElement(self,planId,elementId):
        print "Added element %s to plan %s" % (elementId, planId)
        
    def planRemoveElement(self,planId,elementId):
        print "Removed element %s from plan %s" % (elementId, planId)

