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