1/*
2 * Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Axel D��rfler, axeld@pinc-software.de
7 */
8#ifndef AREA_KEEPER_H
9#define AREA_KEEPER_H
10
11
12#include <KernelExport.h>
13#include <OS.h>
14
15#include <util/kernel_cpp.h>
16
17
18class AreaKeeper {
19	public:
20		AreaKeeper();
21		~AreaKeeper();
22
23		area_id Create(const char *name, void **_virtualAddress, uint32 spec,
24			size_t size, uint32 lock, uint32 protection);
25		area_id Map(const char *name, void *physicalAddress, size_t numBytes,
26			uint32 spec, uint32 protection, void **_virtualAddress);
27
28		status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; }
29		void Detach();
30
31	private:
32		area_id	fArea;
33};
34
35
36AreaKeeper::AreaKeeper()
37	:
38	fArea(-1)
39{
40}
41
42
43AreaKeeper::~AreaKeeper()
44{
45	if (fArea >= B_OK)
46		delete_area(fArea);
47}
48
49
50area_id
51AreaKeeper::Create(const char *name, void **_virtualAddress, uint32 spec,
52	size_t size, uint32 lock, uint32 protection)
53{
54	fArea = create_area(name, _virtualAddress, spec, size, lock, protection);
55	return fArea;
56}
57
58
59area_id
60AreaKeeper::Map(const char *name, void *physicalAddress, size_t numBytes,
61	uint32 spec, uint32 protection, void **_virtualAddress)
62{
63	fArea = map_physical_memory(name, (addr_t)physicalAddress, numBytes, spec,
64		protection, _virtualAddress);
65	return fArea;
66}
67
68
69void
70AreaKeeper::Detach()
71{
72	fArea = -1;
73}
74
75#endif	// AREA_KEEPER_H
76