# Path: swfconduit/event.py
# class Event( object ):
#     id = 0
#     timestamp = None
# 
#     def __init__( self ):
#         self.id         = getrandbits(29) # Size of an AMF3 integer field
#         self.timestamp  = datetime.now()
#         pass
# 
#     def fire( self, server, session ):
#         """ Perform the event's task """
#         pass
# 
#     # Tried this for AS3 readObject problem. May need in future
#     #def __readamf__( self, input ):
#     #    self.timestamp = input.readObject()
#     #    self.payload   = input.readObject()
#     #
#     #def __writeamf__( self, output ):
#     #    output.writeObject( self.timestamp )
#     #    output.writeObject( self.payload )
# 
#     def reply( self, cls, *args ):
#         """ Create a reply with the given class. Will set the reply's id field appropriately """
#         reply = cls(*args)
#         reply.id = self.id
#         return reply


import pyamf
import swfconduit.server
import swfconduit.session
from swfconduit.event import Event
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------

"""
This server tests the event handling of swfconduit. It also serves as a 
reference for your own plugins

"""


class Session(swfconduit.session.Session):
    def open(self):
        """ Initialize periodic events """
        self.ticker = LoopingCall( self.tick )
        self.ticker.start(10)

    def tick(self):
        event = HelloEvent()
        print "TICK! %s" % event.timestamp
        self.sendEvent( event )

    def close(self):
        self.ticker.stop()
        super(Session, self).close()


class Server(swfconduit.server.Server):
    session     = Session


# Path: swfconduit/event.py
# class Event( object ):
#     id = 0
#     timestamp = None
# 
#     def __init__( self ):
#         self.id         = getrandbits(29) # Size of an AMF3 integer field
#         self.timestamp  = datetime.now()
#         pass
# 
#     def fire( self, server, session ):
#         """ Perform the event's task """
#         pass
# 
#     # Tried this for AS3 readObject problem. May need in future
#     #def __readamf__( self, input ):
#     #    self.timestamp = input.readObject()
#     #    self.payload   = input.readObject()
#     #
#     #def __writeamf__( self, output ):
#     #    output.writeObject( self.timestamp )
#     #    output.writeObject( self.payload )
# 
#     def reply( self, cls, *args ):
#         """ Create a reply with the given class. Will set the reply's id field appropriately """
#         reply = cls(*args)
#         reply.id = self.id
#         return reply


# Path: swfconduit/test.py
import pyamf
import swfconduit.server
import swfconduit.session
from swfconduit.event import Event
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------

"""
This server tests the event handling of swfconduit. It also serves as a 
reference for your own plugins

"""


class Session(swfconduit.session.Session):
    def open(self):
        """ Initialize periodic events """
        self.ticker = LoopingCall( self.tick )
        self.ticker.start(10)

    def tick(self):
        event = HelloEvent()
        print "TICK! %s" % event.timestamp
        self.sendEvent( event )

    def close(self):
        self.ticker.stop()
        super(Session, self).close()


class Server(swfconduit.server.Server):
    session     = Session


class TickEvent( Event ):