root/vtcross/branches/bhilburn/src/policy_engines/PolicyEngine.cpp @ 160

Revision 156, 2.2 KB (checked in by bhilburn, 15 years ago)

Reorganized the socket functions to form a static library to link against since
we will be using that code everwhere. All autofoo stuff has been updated to
reflect this. Also, implemented the old policy engine demo with our new
component classes and fixed some bugs in that design.

Line 
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
23PolicyEngine::PolicyEngine()
24{
25    LOG("Creating Policy Engine.\n");
26    LoadPolicies();
27}
28
29
30PolicyEngine::~PolicyEngine()
31{
32}
33
34
35void
36PolicyEngine::GetRemoteComponentType(int32_t socketFD)
37{
38}
39
40
41void
42PolicyEngine::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    int32_t ret = GetRequest(socketFD, pList, &ce_info);
50   
51    if(ret == 1) {
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
61void
62PolicyEngine::Shutdown()
63{
64}
65
66
67void
68PolicyEngine::Reset()
69{
70}
71
72
73void
74PolicyEngine::RegisterComponent(int32_t socketFD)
75{
76    SendMessage(socketFD, "p_register");
77    LOG("Policy Engine:: Registration message sent.\n");
78}
79
80
81void
82PolicyEngine::DeregisterComponent(int32_t socketFD)
83{
84}
85
86
87void
88PolicyEngine::RegisterServices(int32_t socketFD)
89{
90}
91
92
93void
94PolicyEngine::DeregisterServices(int32_t socketFD)
95{
96}
97
98
99void
100PolicyEngine::LoadPolicies()
101{
102    LOG("PolicyEngine:: Loading policies.\n");
103}
104
105
106void
107PolicyEngine::ReloadPolicies()
108{
109}
110
111
112void
113PolicyEngine::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
125void
126PolicyEngine::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
Note: See TracBrowser for help on using the browser.