unit uROMasterServerEventRepository; {----------------------------------------------------------------------------} { RemObjects SDK Library - Core Library } { } { compiler: Delphi 5 and up, Kylix 2 and up } { platform: Win32, Linux } { } { (c)opyright RemObjects Software. all rights reserved. } { } { Using this code requires a valid license of the RemObjects SDK } { which can be obtained at http://www.remobjects.com. } {----------------------------------------------------------------------------} {$I RemObjects.inc} interface uses Classes, uROEventRepository, uROClientIntf, uROClient, uROTypes, ROMasterServerLibrary_Intf; type { TROMasterServerEventRepository } TROMasterServerEventRepository = class(TROEventRepository) private fChannel: TROTransportChannel; fSessionManager : IROSessionManager; procedure SetChannel(const Value: TROTransportChannel); function GetSessionManager: IROSessionManager; protected procedure Notification(aComponent: TComponent; Operation: TOperation); override; { Overrides } procedure DoStoreEventData(SourceSessionID : TGUID; Data : Binary; const ExcludeSender: Boolean; const ExcludeSessionList: Boolean; const SessionList: String); override; function DoGetEventData(SessionID : TGUID; var TargetStream : Binary) : integer; override; procedure DoAddSession(aSessionID : TGUID); override; procedure DoRemoveSession(aSessionID : TGUID); override; public constructor Create(aOwner : TComponent); override; destructor Destroy; override; procedure CheckProperties; override; property SessionManager : IROSessionManager read GetSessionManager; procedure Assign(Source: TPersistent); override; published property Channel : TROTransportChannel read fChannel write SetChannel; end; implementation uses SysUtils, uROClasses; { TROMasterServerEventRepository } procedure TROMasterServerEventRepository.Assign(Source: TPersistent); var lSource: TROMasterServerEventRepository; begin inherited; if Source is TROMasterServerEventRepository then begin lSource := TROMasterServerEventRepository(Source); Channel := lSource.Channel; end; end; procedure TROMasterServerEventRepository.CheckProperties; begin Check(Channel = nil, Name + '.Channel must be assigned.'); Channel.CheckProperties; inherited; end; constructor TROMasterServerEventRepository.Create(aOwner: TComponent); begin inherited; end; destructor TROMasterServerEventRepository.Destroy; begin Channel := nil; inherited; end; procedure TROMasterServerEventRepository.DoAddSession(aSessionID: TGUID); begin SessionManager.CreateSession(GUIDToAnsiString(aSessionID), NIL); end; function TROMasterServerEventRepository.DoGetEventData(SessionID: TGUID; var TargetStream: Binary): integer; begin TargetStream.Free; result := SessionManager.GetMessages(GUIDToAnsiString(SessionID), TargetStream); TargetStream.Position := 0; end; procedure TROMasterServerEventRepository.DoRemoveSession( aSessionID: TGUID); begin SessionManager.DeleteSession(GUIDToAnsiString(aSessionID)); end; procedure TROMasterServerEventRepository.DoStoreEventData(SourceSessionID : TGUID; Data : Binary; const ExcludeSender: Boolean; const ExcludeSessionList: Boolean; const SessionList: String); begin SessionManager.StoreMessage(GUIDToAnsiString(SourceSessionID), Data{, ExcludeSender, ExcludeSessionList, SessionList}) end; function TROMasterServerEventRepository.GetSessionManager: IROSessionManager; begin CheckProperties; if (fSessionManager=NIL) then begin fSessionManager := CoROSessionManager.Create(Message, Channel); end; result := fSessionManager; end; procedure TROMasterServerEventRepository.Notification( aComponent: TComponent; Operation: TOperation); begin inherited; if (Operation<>opRemove) then Exit; if (aComponent=fChannel) then Channel := NIL; end; procedure TROMasterServerEventRepository.SetChannel( const Value: TROTransportChannel); begin if (fChannel <> Value) then begin if (fChannel <> nil ) then fChannel.RORemoveFreeNotification(Self); fChannel := Value; if (fChannel <> nil ) then fChannel.ROFreeNotification(Self); end; end; end.