fusion.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __FUSION__FUSION_H__
  24. #define __FUSION__FUSION_H__
  25. #include <sys/types.h>
  26. #include <fusion/types.h>
  27. typedef enum {
  28. FER_ANY,
  29. FER_MASTER,
  30. FER_SLAVE
  31. } FusionEnterRole;
  32. typedef enum {
  33. FFA_CLOSE,
  34. FFA_FORK
  35. } FusionForkAction;
  36. typedef enum {
  37. FFS_PREPARE,
  38. FFS_PARENT,
  39. FFS_CHILD
  40. } FusionForkState;
  41. typedef void (*FusionForkCallback) ( FusionForkAction action, FusionForkState state );
  42. typedef void (*FusionLeaveCallback)( FusionWorld *world,
  43. FusionID fusion_id,
  44. void *ctx );
  45. /*
  46. * Enters a fusion world by joining or creating it.
  47. *
  48. * If <b>world_index</b> is negative, the next free index is used to create a new world.
  49. * Otherwise the world with the specified index is joined or created.
  50. */
  51. DirectResult fusion_enter( int world_index,
  52. int abi_version,
  53. FusionEnterRole role,
  54. FusionWorld **ret_world );
  55. /*
  56. * Exits the fusion world.
  57. *
  58. * If 'emergency' is true the function won't join but kill the dispatcher thread.
  59. */
  60. DirectResult fusion_exit( FusionWorld *world,
  61. bool emergency );
  62. DirectResult fusion_stop_dispatcher( FusionWorld *world,
  63. bool emergency );
  64. /*
  65. * Sets the fork() action of the calling Fusionee within the world.
  66. */
  67. void fusion_world_set_fork_action( FusionWorld *world,
  68. FusionForkAction action );
  69. /*
  70. * Gets the current fork() action.
  71. */
  72. FusionForkAction fusion_world_get_fork_action( FusionWorld *world );
  73. /*
  74. * Registers a callback called upon fork().
  75. */
  76. void fusion_world_set_fork_callback( FusionWorld *world,
  77. FusionForkCallback callback );
  78. /*
  79. * Registers a callback called when a slave exits.
  80. */
  81. void fusion_world_set_leave_callback( FusionWorld *world,
  82. FusionLeaveCallback callback,
  83. void *ctx );
  84. /*
  85. * Return the index of the specified world.
  86. */
  87. int fusion_world_index( const FusionWorld *world );
  88. /*
  89. * Return the own Fusion ID within the specified world.
  90. */
  91. FusionID fusion_id( const FusionWorld *world );
  92. /*
  93. * Return if the world is a multi application world.
  94. */
  95. bool fusion_is_multi( const FusionWorld *world );
  96. /*
  97. * Return the thread ID of the Fusion Dispatcher within the specified world.
  98. */
  99. pid_t fusion_dispatcher_tid( const FusionWorld *world );
  100. /*
  101. * Return true if this process is the master.
  102. */
  103. bool fusion_master( const FusionWorld *world );
  104. /*
  105. * Wait until all pending messages are processed.
  106. */
  107. DirectResult fusion_sync( const FusionWorld *world );
  108. /*
  109. * Sends a signal to one or more fusionees and optionally waits
  110. * for their processes to terminate.
  111. *
  112. * A fusion_id of zero means all fusionees but the calling one.
  113. * A timeout of zero means infinite waiting while a negative value
  114. * means no waiting at all.
  115. */
  116. DirectResult fusion_kill( FusionWorld *world,
  117. FusionID fusion_id,
  118. int signal,
  119. int timeout_ms );
  120. /* Check if a pointer points to the shared memory. */
  121. bool fusion_is_shared( FusionWorld *world,
  122. const void *ptr );
  123. const char *fusion_get_tmpfs( FusionWorld *world );
  124. /*
  125. * Get the executable path of the Fusionee
  126. *
  127. * Returns DR_LIMITEXCEEDED when buf_size too small,
  128. * with the required number of bytes returned in ret_size.
  129. */
  130. DirectResult fusion_get_fusionee_path( const FusionWorld *world,
  131. FusionID fusion_id,
  132. char *buf,
  133. size_t buf_size,
  134. size_t *ret_size );
  135. #endif