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