property.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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__PROPERTY_H__
  24. #define __FUSION__PROPERTY_H__
  25. #include <pthread.h>
  26. #include <fusion/types.h>
  27. typedef enum {
  28. FUSION_PROPERTY_AVAILABLE,
  29. FUSION_PROPERTY_LEASED,
  30. FUSION_PROPERTY_PURCHASED
  31. } FusionPropertyState;
  32. typedef union {
  33. /* multi app */
  34. struct {
  35. int id;
  36. const FusionWorldShared *shared;
  37. /* builtin impl */
  38. struct {
  39. FusionPropertyState state;
  40. pid_t owner;
  41. bool requested;
  42. bool destroyed;
  43. } builtin;
  44. } multi;
  45. /* single app */
  46. struct {
  47. pthread_mutex_t lock;
  48. pthread_cond_t cond;
  49. FusionPropertyState state;
  50. } single;
  51. } FusionProperty;
  52. /*
  53. * Initializes the property
  54. */
  55. DirectResult fusion_property_init (FusionProperty *property,
  56. const FusionWorld *world);
  57. /*
  58. * Lease the property causing others to wait before leasing or purchasing.
  59. *
  60. * Waits as long as property is leased by another party.
  61. * Returns DR_BUSY if property is/gets purchased by another party.
  62. *
  63. * Succeeds if property is available,
  64. * puts the property into 'leased' state.
  65. */
  66. DirectResult fusion_property_lease (FusionProperty *property);
  67. /*
  68. * Purchase the property disallowing others to lease or purchase it.
  69. *
  70. * Waits as long as property is leased by another party.
  71. * Returns DR_BUSY if property is/gets purchased by another party.
  72. *
  73. * Succeeds if property is available,
  74. * puts the property into 'purchased' state and wakes up any waiting party.
  75. */
  76. DirectResult fusion_property_purchase (FusionProperty *property);
  77. /*
  78. * Cede the property allowing others to lease or purchase it.
  79. *
  80. * Puts the property into 'available' state and wakes up one waiting party.
  81. */
  82. DirectResult fusion_property_cede (FusionProperty *property);
  83. /*
  84. * Kills the owner of the property.
  85. *
  86. * Tries to make a purchased property available again by killing
  87. * the process that purchased it.
  88. */
  89. DirectResult fusion_property_holdup (FusionProperty *property);
  90. /*
  91. * Destroys the property
  92. */
  93. DirectResult fusion_property_destroy (FusionProperty *property);
  94. #endif