1*fce4895dSRene Gollent /* 2*fce4895dSRene Gollent * Copyright 2016, Rene Gollent, rene@gollent.com. 3*fce4895dSRene Gollent * Distributed under the terms of the MIT License. 4*fce4895dSRene Gollent */ 5*fce4895dSRene Gollent #ifndef TARGET_HOST_H 6*fce4895dSRene Gollent #define TARGET_HOST_H 7*fce4895dSRene Gollent 8*fce4895dSRene Gollent #include <Locker.h> 9*fce4895dSRene Gollent #include <OS.h> 10*fce4895dSRene Gollent #include <String.h> 11*fce4895dSRene Gollent 12*fce4895dSRene Gollent #include <ObjectList.h> 13*fce4895dSRene Gollent #include <Referenceable.h> 14*fce4895dSRene Gollent #include <util/DoublyLinkedList.h> 15*fce4895dSRene Gollent 16*fce4895dSRene Gollent 17*fce4895dSRene Gollent class TeamInfo; 18*fce4895dSRene Gollent 19*fce4895dSRene Gollent 20*fce4895dSRene Gollent class TargetHost : public BReferenceable { 21*fce4895dSRene Gollent public: 22*fce4895dSRene Gollent class Listener; 23*fce4895dSRene Gollent public: 24*fce4895dSRene Gollent TargetHost(const BString& name); 25*fce4895dSRene Gollent virtual ~TargetHost(); 26*fce4895dSRene Gollent Lock()27*fce4895dSRene Gollent bool Lock() { return fLock.Lock(); } Unlock()28*fce4895dSRene Gollent void Unlock() { fLock.Unlock(); } 29*fce4895dSRene Gollent Name()30*fce4895dSRene Gollent const BString& Name() const { return fName; } 31*fce4895dSRene Gollent 32*fce4895dSRene Gollent void AddListener(Listener* listener); 33*fce4895dSRene Gollent void RemoveListener(Listener* listener); 34*fce4895dSRene Gollent 35*fce4895dSRene Gollent int32 CountTeams() const; 36*fce4895dSRene Gollent status_t AddTeam(const team_info& info); 37*fce4895dSRene Gollent void RemoveTeam(team_id team); 38*fce4895dSRene Gollent void UpdateTeam(const team_info& info); 39*fce4895dSRene Gollent TeamInfo* TeamInfoAt(int32 index) const; 40*fce4895dSRene Gollent TeamInfo* TeamInfoByID(team_id team) const; 41*fce4895dSRene Gollent 42*fce4895dSRene Gollent private: 43*fce4895dSRene Gollent typedef DoublyLinkedList<Listener> ListenerList; 44*fce4895dSRene Gollent typedef BObjectList<TeamInfo> TeamInfoList; 45*fce4895dSRene Gollent 46*fce4895dSRene Gollent private: 47*fce4895dSRene Gollent static int _CompareTeams(const TeamInfo* a, 48*fce4895dSRene Gollent const TeamInfo* b); 49*fce4895dSRene Gollent static int _FindTeamByKey(const team_id* id, 50*fce4895dSRene Gollent const TeamInfo* info); 51*fce4895dSRene Gollent 52*fce4895dSRene Gollent void _NotifyTeamAdded(TeamInfo* info); 53*fce4895dSRene Gollent void _NotifyTeamRemoved(team_id team); 54*fce4895dSRene Gollent void _NotifyTeamRenamed(TeamInfo* info); 55*fce4895dSRene Gollent 56*fce4895dSRene Gollent private: 57*fce4895dSRene Gollent BString fName; 58*fce4895dSRene Gollent BLocker fLock; 59*fce4895dSRene Gollent ListenerList fListeners; 60*fce4895dSRene Gollent TeamInfoList fTeams; 61*fce4895dSRene Gollent }; 62*fce4895dSRene Gollent 63*fce4895dSRene Gollent 64*fce4895dSRene Gollent class TargetHost::Listener 65*fce4895dSRene Gollent : public DoublyLinkedListLinkImpl<TargetHost::Listener> { 66*fce4895dSRene Gollent public: 67*fce4895dSRene Gollent virtual ~Listener(); 68*fce4895dSRene Gollent 69*fce4895dSRene Gollent virtual void TeamAdded(TeamInfo* info); 70*fce4895dSRene Gollent virtual void TeamRemoved(team_id team); 71*fce4895dSRene Gollent virtual void TeamRenamed(TeamInfo* info); 72*fce4895dSRene Gollent }; 73*fce4895dSRene Gollent 74*fce4895dSRene Gollent #endif // TARGET_HOST_H 75