1 /* 2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef MESSAGING_SERVICE_H 6 #define MESSAGING_SERVICE_H 7 8 9 //! kernel-side implementation-private definitions for the messaging service 10 11 12 #include <MessagingServiceDefs.h> 13 14 #include <lock.h> 15 16 17 namespace BPrivate { 18 19 // MessagingArea 20 class MessagingArea { 21 public: 22 ~MessagingArea(); 23 24 static MessagingArea *Create(sem_id lockSem, sem_id counterSem); 25 26 static bool CheckCommandSize(int32 dataSize); 27 28 void InitHeader(); 29 30 bool Lock(); 31 void Unlock(); 32 33 area_id ID() const; 34 int32 Size() const; 35 bool IsEmpty() const; 36 37 void *AllocateCommand(uint32 commandWhat, int32 dataSize, bool &wasEmpty); 38 void CommitCommand(); 39 40 void SetNextArea(MessagingArea *area); 41 MessagingArea *NextArea() const; 42 43 private: 44 MessagingArea(); 45 46 messaging_command *_CheckCommand(int32 offset, int32 &size); 47 48 messaging_area_header *fHeader; 49 area_id fID; 50 int32 fSize; 51 sem_id fLockSem; 52 sem_id fCounterSem; 53 MessagingArea *fNextArea; 54 }; 55 56 // MessagingService 57 class MessagingService { 58 public: 59 MessagingService(); 60 ~MessagingService(); 61 62 status_t InitCheck() const; 63 64 bool Lock(); 65 void Unlock(); 66 67 status_t RegisterService(sem_id lockingSem, sem_id counterSem, 68 area_id &areaID); 69 status_t UnregisterService(); 70 71 status_t SendMessage(const void *message, int32 messageSize, 72 const messaging_target *targets, int32 targetCount); 73 74 private: 75 status_t _AllocateCommand(int32 commandWhat, int32 size, 76 MessagingArea *&area, void *&data, bool &wasEmpty); 77 78 recursive_lock fLock; 79 team_id fServerTeam; 80 sem_id fLockSem; 81 sem_id fCounterSem; 82 MessagingArea *fFirstArea; 83 MessagingArea *fLastArea; 84 }; 85 86 } // namespace BPrivate 87 88 using BPrivate::MessagingArea; 89 using BPrivate::MessagingService; 90 91 #endif // MESSAGING_SERVICE_H 92