0

Please help me understand the concepts of APIs and call back functions. As far as I know the following are the key points:

  1. APIs are exposed by a 3rd party application (callee), so that the application using the 3rd party (caller), can use the exposed APIs to communicate to callee. Here IPC is used to exchange information between the two processes. They run in different process address space.

  2. Call back functions are exposed by a 3rd party application (callee), so that the application using the 3rd party (caller) can be made aware of any event that have taken place in calee and the caller needs to take some action based on the same. This is generally achieved using function pointers. They run in the same process address space.

Please correct me if I am wrong, and also add your valuable points regarding the same.

Upayan
  • 83
  • 2
  • 7

2 Answers2

1
  1. is orange. API is a very generic term, related more to architecture, or design. You have to make a difference language specific API (i.e. C API, python API) and Web API (REST, SOAP).
  2. is apple. Is a a SOA Pattern to allow asynchronous communication.

read more: #design-pattern-callback

Community
  • 1
  • 1
azbarcea
  • 3,323
  • 1
  • 20
  • 25
0

An api of a 3rd party library is used by an application to perform action as described by the API and that api would mostly return a value to indicate a success or failure or some times error code of the failure to the caller.

eg: createFile()

A call back function is a mechanism by which the application would try to register a function to the 3rd party library using function pointers in order to get notified asynchronously when ever an specific event occurs.

eg: if our application has to pop up to the end user on low battery,we register a function to the os framework to call our function whenever the system battery is low. when this happens we can implement some power saving routines or a popup to a user to warn on low battery in our callback function.

GingerJack
  • 3,044
  • 1
  • 17
  • 19