LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Creating APIs (https://www.linuxquestions.org/questions/programming-9/creating-apis-454795/)

blackhock 06-14-2006 04:11 PM

Creating APIs
 
Hi,

We are developing an application for which we want to create an API. The API should allow client applications to call functions in a daemon process. A simple scenario: A client would call a function in the API binding and pass it some objects, these objects and some control information would be transferred to the daemon process, which would then execute the appropriate function passing it the objects it received.

Note: This client-server model is local, and development is in C++.

We evaluated all the IPC methods for moving data between the client application and the daemon, and in each of them, found that they lack some features in another and impose restrictions not found in others. And thus, to achieve the scenario above, we would have to hack our way and use several IPC mechanisms together to achieve the desired behaviour.

For example, with Unix Domain Sockets, we would have to convert each object from and to a string representation, which sounds like too much overhead. Shared Memory would impose many problems, specifically in releasing the memory, and with dynamically expanding objects, and similarly, FIFOs and Pipes have their share of problems.

Now the question is, how do APIs are generally designed? We looked at D-BUS, but it doesn't have a (usable) C++ binding. Are there other libraries available? Is it really the only way to mix several IPCs together, aren't there any "prettier" ways?

So, to put it in another way, we are not looking for just any way to implement an API, we're looking for an efficient way. We can come up easily with straightforward, inefficient methods, like converting the objects to string or XML and passing them around, but we would rather use a library that is commonly used, and tested.

grumpf 06-15-2006 10:49 AM

you will transfer some binary code to a server an execute it ? localy ?
why should anyone want this ? use a shared lib or rpc if anything else break.
(actualy you could use a shared lib, see ldopen() )

the client-server model basicly say: take this and send me result. easy to implement easy to debug (e.g. with telnet).
X11 let you redefine some functions noone uses it. why ? because you end in unpleasant places.

95se 06-15-2006 01:25 PM

I would think CORBA or SOAP would be good candidates.

Randux 06-15-2006 02:20 PM

An API is the code interface between service consumer and service provider. It sounds like what you're talking about here is the back-end code implementation (of the service provider code) and not an API- and this problem is not specific to APIs. You might get more help if you change the topic (is that possible?) to target your actual question which sounds like a question on how to choose an optimal IPC technique for your situation.

Hko 06-15-2006 03:34 PM

There's no strict need to do conversion to strings or even XML in order to use any IPC. If the objects contain references (i.e. pointers to other objects or block of data), you will need to serialize the entire tree of linked object of course, because it doesn't make sense to pass a literal memory address (pointer). But you can do this all binary without problem, with any IPC method.

Quote:

We evaluated all the IPC methods for moving data between the client application and the daemon, and in each of them, found that they lack some features in another and impose restrictions not found in others.
Did you think of message queue's? If your objects are not too big, a message queue may be a suitable method in your case.


All times are GMT -5. The time now is 03:24 AM.