#!/usr/local/bin/python -i
#==============================================================================
#
#  $Id: dopyserver,v 1.4 1999/04/24 20:58:13 mike Exp $
#
"""
   Sample DOPY server program.
   
   Usage:
      doyserver
   
   dopyserver publishes the "test" object, which contains some very
   basic methods for testing the protocol.
"""
#
#  Copyright (C) 1999 Michael A. Muller
#
#  Permission is granted to use, modify and redistribute this code,
#  providing that the following conditions are met:
#
#  1) This copyright/licensing notice must remain intact.
#  2) If the code is modified and redistributed, the modifications must 
#  include documentation indicating that the code has been modified.
#  3) The author(s) of this code must be indemnified and held harmless
#  against any damage resulting from the use of this code.
#
#  This code comes with ABSOLUTELY NO WARRANTEE, not even the implied 
#  warrantee of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
#  $Log: dopyserver,v $
#  Revision 1.4  1999/04/24 20:58:13  mike
#  Cleaned up for distribution.
#
#
#==============================================================================

import os, sys

# remove the current directory from the search path so that this runs ok
# from the dopy library directory
if sys.path[0] in ('', os.curdir):
   del sys.path[0]

import dopy
from dopy import tcp

class Test:
   
   def hello(self, str):
      print 'hello', str
      print 'received from', hub.getContext().protocol().getProtocolId()
      return 'hello ' + str

   def kwparms(self, p1, p2):
      print 'kwparms =', p1, p2
      print 'received from', hub.getContext().protocol().getProtocolId()
      return (p1, p2)
   
   def raiseException(self):
      print 'raiseException received from', \
         hub.getContext().protocol().getProtocolId()
      raise Exception("Something bad happened")

tcp.makeServer(9600)
hub = dopy.getHub()
hub.addObject('test', Test())
# hub.mainloop()
