xref: /haiku/src/servers/print/ResourceManager.h (revision 452351266356690bad3e99c7509a6a642f831c8a)
1314167cdSDarkWyrm /*
2314167cdSDarkWyrm  * Copyright 2002-2006, Haiku. All rights reserved.
3314167cdSDarkWyrm  * Distributed under the terms of the MIT License.
4314167cdSDarkWyrm  *
5314167cdSDarkWyrm  * Authors:
6314167cdSDarkWyrm  *		Michael Pfeiffer
7314167cdSDarkWyrm  */
88f13f87bSMichael Phipps #ifndef RESOURCE_MANAGER_H
98f13f87bSMichael Phipps #define RESOURCE_MANAGER_H
108f13f87bSMichael Phipps 
118f13f87bSMichael Phipps #include "ObjectList.h"
128f13f87bSMichael Phipps 
138f13f87bSMichael Phipps #include <Locker.h>
148f13f87bSMichael Phipps #include <String.h>
158f13f87bSMichael Phipps 
168f13f87bSMichael Phipps #include "BeUtils.h"
178f13f87bSMichael Phipps 
188f13f87bSMichael Phipps class Resource : public Object {
198f13f87bSMichael Phipps private:
208f13f87bSMichael Phipps 	BString	 fTransport;
218f13f87bSMichael Phipps 	BString  fTransportAddress;
228f13f87bSMichael Phipps 	BString  fConnection;
238f13f87bSMichael Phipps 	sem_id   fResourceAvailable;
248f13f87bSMichael Phipps 
258f13f87bSMichael Phipps public:
268f13f87bSMichael Phipps 	Resource(const char* transport, const char* address, const char* connection);
278f13f87bSMichael Phipps 	~Resource();
288f13f87bSMichael Phipps 
29*45235126SMichael Pfeiffer 	bool NeedsLocking();
30*45235126SMichael Pfeiffer 
318f13f87bSMichael Phipps 	bool Equals(const char* transport, const char* address, const char* connection);
328f13f87bSMichael Phipps 
Transport()338f13f87bSMichael Phipps 	const BString& Transport() const { return fTransport; }
348f13f87bSMichael Phipps 
358f13f87bSMichael Phipps 	bool Lock();
368f13f87bSMichael Phipps 	void Unlock();
378f13f87bSMichael Phipps };
388f13f87bSMichael Phipps 
398f13f87bSMichael Phipps class ResourceManager {
408f13f87bSMichael Phipps private:
418f13f87bSMichael Phipps 	BObjectList<Resource> fResources;
428f13f87bSMichael Phipps 
438f13f87bSMichael Phipps 	Resource* Find(const char* transport, const char* address, const char* connection);
448f13f87bSMichael Phipps 
458f13f87bSMichael Phipps public:
468f13f87bSMichael Phipps 	~ResourceManager();
478f13f87bSMichael Phipps 
488f13f87bSMichael Phipps 	Resource* Allocate(const char* transport, const char* address, const char* connection);
498f13f87bSMichael Phipps 	void Free(Resource* r);
508f13f87bSMichael Phipps };
518f13f87bSMichael Phipps 
528f13f87bSMichael Phipps #endif
53