blob: 7d7015d7820a7ea9c11a845a25a9aa8143162d8b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "HandlerManager.h"
#include "IdentityManager.h"
#include "LifecycleManager.h"
#include "PermissionsManager.h"
namespace nt
{
void HandlerManager::DeallocateHandle(struct handle* handle)
{
delete handle;
}
struct HandlerManager::handle* HandlerManager::Open(std::vector<std::string> object_path, void* connection_context)
{
ObjectManager objects;
PermissionsManager permissions;
IdentityManager identities;
LifecycleManager lifecycles;
ObjectManager::registry* retrieved_object = objects.Find((const std::vector<std::string>)object_path);
if (permissions.Access(retrieved_object, (const void*)connection_context)
&& identities.CanOpen(retrieved_object)
&& lifecycles.Contention(retrieved_object)) {
// Starts monitoring this guy
lifecycles.Monitor(retrieved_object);
return new handle{ retrieved_object, connection_context }; // Return a successful handle
}
else {
// Return something more algebraic instead of null or an int
return nullptr;
};
}
bool HandlerManager::Close(struct handle* handle)
{
if (handle == nullptr) {
return false;
}
PermissionsManager permissions;
IdentityManager identities;
LifecycleManager lifecycles;
// Somehow grab the object pointer and connection (maybe drop it...) from the handle
ObjectManager::registry* object = handle->object;
void* connection_context = handle->connection_context;
// Checking for permissions here may be relevant.
// What if we have a handle but no permission? Spooky
if (permissions.Access(object, connection_context)
&& identities.CanClose(object)
// TODO: I think that in this case we do not need to worry about contention.
// But be careful to evaluate this scenario later.
//&& LifecycleManager::Contention(retrieved_object)
) {
// Stops monitoring this guy
lifecycles.Unmonitor(object);
DeallocateHandle(handle);
return true; // Return a successful handle
}
else {
// Return something more algebraic instead of null or an int.
// It's kinda bad to not even report what went wrong.
return false;
};
}
}
|