View Full Version : Suggestions on implementing a gethostbyname() function...

Farmer Scott
03-21-2009, 07:35 AM
So, I'm working on 'dns.spin', well, actually just the gethostbyname() function.и Before I get too far along, I've got some question about object interaction.и I'm wondering if what I have in mind will work...

Here's the code and object relationship...

иии |- dns.spin
иии |- api_telnet_serial.spin
иииииииииии |- driver_socket.spin
иииииииииииииииииии |- driver_enc28j60.spin

The big question is, if I call the api_telnet_serial.start() function from main.spin, which will of course call the same function in driver_socket and driver_enc28j60, can I still call the api_telnet_serial.connect() function from dns.spin?

Sorry, I realize this is probably a little confusing, at least I am certainly confusing myself, but not exactly sure how to proceed.и I can usually get by with SPIN, but this is one conundrum that's got me perplexed...

Or, does anyone have any suggestions on a good way to implement this function?



Mike Green
03-21-2009, 08:13 AM
It's possible to write the lower level objects so they can be called as you want. You have to put the global variables in each object into a DAT section rather than a VAR section because each instance of an object has its own VAR area, but the DAT areas are shared. Main would then call api_telnet_serial and dns could also have api_telnet_serial. There would be only one copy of the code and of the DAT section(s).

Do keep in mind that the object structure in Spin is not really designed for this kind of use, but people have done it using DAT sections. Look in the ObEx for a version of FullDuplexSerial that was designed for shared use for debugging. That'll give you an idea of what's involved. It's pretty straightforward.