edelib 2.1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

Functions
Foreign callbacks

## Functions
void | foreign_callback_add (Fl_Window *win, const char *id, void(*cb)(Fl_Window *, void *), void *data=0)
void | foreign_callback_remove (void(*cb)(Fl_Window *, void *))
void | foreign_callback_call (const char *id)

## Detailed Description

## Function Documentation

void edelib::foreign_callback_add | ( | Fl_Window * | win,
|  | const char * | id,
|  | void(*)(Fl_Window *, void *) | cb,
|  | void * | data = `0`
| ) |  |

foreign_callback_add(), foreign_callback_remove() and foreign_callback_call() functions provides a simple and lightweight mechanism for calling functions in other applications. For example, one application can change some settings and store it in known file and request other application to update itself by reading it.

These functions can be used as alternative to D-BUS calls in simple cases (and reduce dependency on D-BUS libraries), but should not be used where D-BUS is appropriate, like sending additional data to remote functions.

Each foreign callback is associated with id, a some string value used as calling method from external application. That value can be anything, ranging from application name to some random character; the only requirement is that external caller has the same string value. Here is one example that will print some text in receiver file:

// receiver.cpp
void receive_cb(Fl_Window *win) {
puts("Function called");
}
int main() {
Fl_Window *win = new Fl_Window(300, 300, "Sample foreign callback");
// initialization code and etc.
foreign_callback_add(win, "my-cool-app", receive_cb);
return Fl::run();
}
// sender.cpp
int main() {
foreign_callback_call("my-cool-app");
return 0;
}

Todo:
  Add some better examples

Because foreign callback functions shares static internal data and the data is not locked, the best way to initialize foreign callbacks is before windows are shown in single application; with this no X messages will be sent and you are assured nothing will be called unexpectedly.

foreign_callback_add() and foreign_callback_call() will open X display if not so.

Because these functions depends on FLTK and X, they are part of libedelib_gui library.

void edelib::foreign_callback_call | ( | const char * | id | ) |

Call foreign function by registered string id.

void edelib::foreign_callback_remove | ( | void(*)(Fl_Window *, void *) | cb | ) |

Remove already registered callback if exists.