The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Apache on Solaris10 configured with loadable module support? kavera SUN Solaris 2 10-17-2007 11:15 PM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 06:52 PM
Custom pam module mhm4 SUN Solaris 1 10-02-2006 03:33 PM
LWP module ? Beto UNIX for Dummies Questions & Answers 4 07-12-2001 05:17 AM
PHP Module ComTec UNIX for Dummies Questions & Answers 10 02-13-2001 11:41 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-29-2006
Registered User
 

Join Date: Feb 2006
Posts: 6
Module Support! How does it work?

ey everyone,

I have been working on an application for a while, and would like others to
be able to add modules for it. The problem is, I don't know how to implement
them.

I am using the dlopen() library set. I understand how to load modules into t
he program and how to execute the code. The problem is, I want these modules
to be able to modify ANY part of the program. For example, if there are 100
functions in my application, I want the program to be able to modify any si
ngle one of those functions to do something different. Is there a way to do
this, without having to make every single function in my code a function poi
nter?

Btw, im writing this on Unix :-)

Thanks a lot!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-30-2006
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
u can do it by making object file separately for each function and bind them with main program.

say :

make a foo.so for function foo()

while building your application use foo.so
Reply With Quote
  #3 (permalink)  
Old 05-31-2006
Registered User
 

Join Date: May 2006
Posts: 95
I am not sure that i understand what you are talking about.
Your ptogram contains an array of functionpointers and you want to change it on run time ?

can you give an example why on earth someone would do it ?
Reply With Quote
  #4 (permalink)  
Old 06-02-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
I don't think you can do that with dlopen. You'll have to do this hardcore -- libelf to parse the so files, and mmap to map executable pages into memory from it. If you figure it out let me know, since that's one secret I haven't yet managed to penetrate, libelf has got to be among the most important and least documented libraries on earth...
Reply With Quote
  #5 (permalink)  
Old 06-02-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Quote:
Originally Posted by grumpf
Your program contains an array of functionpointers and you want to change it on run time ?

can you give an example why on earth someone would do it ?
Plugins work this way. That way, things like codecs don't have to be hardcoded -- or even linked -- into the program, they can be loaded on command. it's usually blocks of functions that get loaded though.
Reply With Quote
  #6 (permalink)  
Old 06-05-2006
Registered User
 

Join Date: Oct 2003
Posts: 69
First you'd have to define an interface to which the module writers would conform. My guess is that "modify every function in my program" does not really explain what and how to modify it. You are at the incorrect level of abstraction to make this work if you're going to have everything be function pointers.

Basically, you first want to define a concrete set of functionality that module writers should be able to hook into. Then you have to specify an interface agreement that the module writers can conform to.

One of the first things I think you may want to define is a procedure to initialize the module. Part of this could be that the module passes you back a set of function pointers (into itself) that you can call. You define the datastructure that gets passed and the module conforms and uses it to tell you want it wants to overload or hook into and passes you the callback or overload routine it wants you to call.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0