Generic communications module with a little help from classes...



Hi,
What I want to do is create a module that offers a generic set of
functions (send, recieve, etc...) and reffers the request to the
correct module (rs-232, tcp/ip, etc..).
I want all this to be unseen by the script that calls this module.
I want the script to specify the communication type, and then be able
to use the functions. In the future, when the whole script will work on
a different type of communication all that will be changed is the type
of communication property.
How do I do this?

I thought of a few possibilities:
1. all communication modules will have the same function names and same
number of params (problematic), and then it will look like this:

class module1:
def send(self):
# send one way

class module2:
def send(self):
# send the other
if X:
selected = module1
else:
selected = module2

class main(selected):
pass

m = main()
m.send()

2. the other option is creating a "wrapper" class for each module. this
class takes the generic params of the function "send" and organizes the
params and name so it will be compatible with the comm module:

class a:
def send(self, what):
module1.sendCMD(what)

class b:
def send(self, what):
module2.SEND(what)

if X:
selected = a
else:
selected = b

class main(selected):
pass

m = main()
m.send()

#############
which way is better? any better ideas?

thanks.

.



Relevant Pages

  • Re: subprocess.Popen(cmd) question
    ... independent and dont need any communication between each other. ... memory issues I need to limit the number of running processes to around ... import subprocess ... def info: ...
    (comp.lang.python)
  • First Ruby Program
    ... def initialize(name, idx) ... def initialize(workers) ... The information contained in this communication is confidential, ...
    (comp.lang.ruby)
  • Re: who to call a list of method inside the class itself
    ... It is working but the call to mwithout a reference to self seems ... def method1: ... distribution or copying of this communication is strictly prohibited. ...
    (comp.lang.python)
  • instance_eval, yield, C extensions
    ... # Assume Foo is a subclass of String ... def my_meth ... Unauthorized use of this communication is strictly prohibited and may be unlawful. ...
    (comp.lang.ruby)