1 | /* Virginia Tech Cognitive Radio Open Source Systems |
---|
2 | * Virginia Tech, 2009 |
---|
3 | * |
---|
4 | * LICENSE INFORMATION GOES HERE |
---|
5 | */ |
---|
6 | |
---|
7 | /* DESCRIPTION OF FILE. |
---|
8 | */ |
---|
9 | |
---|
10 | |
---|
11 | #include <cstdlib> |
---|
12 | #include <cstring> |
---|
13 | #include <stdint.h> |
---|
14 | |
---|
15 | #include "vtcross/common.h" |
---|
16 | #include "vtcross/components.h" |
---|
17 | #include "vtcross/containers.h" |
---|
18 | #include "vtcross/debug.h" |
---|
19 | #include "vtcross/error.h" |
---|
20 | #include "vtcross/socketcomm.h" |
---|
21 | |
---|
22 | |
---|
23 | PolicyEngine::PolicyEngine() |
---|
24 | { |
---|
25 | LOG("Creating Policy Engine.\n"); |
---|
26 | LoadPolicies(); |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | PolicyEngine::~PolicyEngine() |
---|
31 | { |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | void |
---|
36 | PolicyEngine::GetRemoteComponentType(int32_t socketFD) |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | void |
---|
42 | PolicyEngine::WaitForSignal(int32_t socketFD) |
---|
43 | { |
---|
44 | LOG("Policy Engine:: Waiting for Policy Check Request.\n"); |
---|
45 | |
---|
46 | int32_t decision_array[10]; |
---|
47 | struct Parameter pList[10]; |
---|
48 | struct CE_Info ce_info; |
---|
49 | |
---|
50 | // TODO should this be a GetRequest call or something else? |
---|
51 | if(GetRequest(socketFD, pList, &ce_info)) { |
---|
52 | LOG("Policy Engine:: Validating Transmission Parameters.\n"); |
---|
53 | ValidateParameters(pList, &ce_info, decision_array); |
---|
54 | |
---|
55 | LOG("Policy Engine:: Sending Policy decision to Server.\n"); |
---|
56 | SendPEDecision(socketFD, pList, &ce_info, decision_array); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | void |
---|
62 | PolicyEngine::Shutdown() |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | void |
---|
68 | PolicyEngine::Reset() |
---|
69 | { |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | void |
---|
74 | PolicyEngine::RegisterComponent(int32_t socketFD) |
---|
75 | { |
---|
76 | SendMessage(socketFD, "p_register"); |
---|
77 | LOG("Policy Engine:: Registration message sent.\n"); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | void |
---|
82 | PolicyEngine::DeregisterComponent(int32_t socketFD) |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | void |
---|
88 | PolicyEngine::RegisterServices(int32_t socketFD) |
---|
89 | { |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | void |
---|
94 | PolicyEngine::DeregisterServices(int32_t socketFD) |
---|
95 | { |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | void |
---|
100 | PolicyEngine::LoadPolicies() |
---|
101 | { |
---|
102 | LOG("PolicyEngine:: Loading policies.\n"); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | void |
---|
107 | PolicyEngine::ReloadPolicies() |
---|
108 | { |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | void |
---|
113 | PolicyEngine::SendPEDecision(int32_t socketFD, struct Parameter pList[], \ |
---|
114 | struct CE_Info *ce_info, int32_t decision_array[]) |
---|
115 | { |
---|
116 | char var[50]; |
---|
117 | |
---|
118 | for (size_t i = 0; i < ce_info->numParameters; i++) { |
---|
119 | sprintf(var, "%i", decision_array[i]); |
---|
120 | SendMessage(socketFD, var); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | void |
---|
126 | PolicyEngine::ValidateParameters(struct Parameter pList[], \ |
---|
127 | struct CE_Info *ce_info, int decision_array[]) |
---|
128 | { |
---|
129 | LOG("Policy Engine:: Policies Validated.\n"); |
---|
130 | for (size_t i = 0; i < ce_info->numParameters; i++) |
---|
131 | decision_array[i] = 1; |
---|
132 | } |
---|
133 | |
---|