[163] | 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 | ServiceManagementLayer::ServiceManagementLayer() |
---|
| 24 | { |
---|
[164] | 25 | LOG("Creating Service Management Layer.\n"); |
---|
[204] | 26 | shellSocketFD = -1; |
---|
[164] | 27 | LoadConfiguration(); |
---|
[163] | 28 | } |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | ServiceManagementLayer::~ServiceManagementLayer() |
---|
| 32 | { |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
[204] | 36 | ServiceManagementLayer::ServiceManagementLayer(const char* serverName, \ |
---|
| 37 | const char* serverPort) |
---|
| 38 | { |
---|
| 39 | LOG("Creating Service Management Layer.\n"); |
---|
| 40 | |
---|
| 41 | ConnectToShell(serverName, serverPort); |
---|
| 42 | |
---|
| 43 | LoadConfiguration(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
[163] | 47 | void |
---|
[200] | 48 | ServiceManagementLayer::SendComponentType() |
---|
[163] | 49 | { |
---|
[204] | 50 | SendMessage(shellSocketFD, "response_sml"); |
---|
| 51 | LOG("SML responded to GetRemoteComponentType query.\n"); |
---|
[163] | 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | void |
---|
[204] | 56 | ServiceManagementLayer::ConnectToShell(const char* serverName, \ |
---|
| 57 | const char* serverPort) |
---|
[200] | 58 | { |
---|
[204] | 59 | shellSocketFD = ClientSocket(serverName, serverPort); |
---|
| 60 | |
---|
| 61 | RegisterComponent(); |
---|
[200] | 62 | } |
---|
[164] | 63 | |
---|
[200] | 64 | |
---|
| 65 | void |
---|
| 66 | ServiceManagementLayer::WaitForSignal() |
---|
| 67 | { |
---|
[206] | 68 | char buffer[256]; |
---|
| 69 | |
---|
| 70 | while(true) { |
---|
| 71 | memset(buffer, 0, 256); |
---|
| 72 | |
---|
| 73 | ReadMessage(shellSocketFD, buffer); |
---|
| 74 | |
---|
| 75 | // TODO |
---|
| 76 | // If we send integer op codes rather than strings, this process will be |
---|
| 77 | // MUCH faster since instead of donig string compares we can simply |
---|
| 78 | // switch on the integer value... |
---|
| 79 | if(strcmp(buffer, "register_service") == 0) { |
---|
| 80 | if(strcmp(buffer, "policy_geo") == 0) { |
---|
| 81 | } |
---|
| 82 | else if(strcmp(buffer, "policy_time") == 0) { |
---|
| 83 | } |
---|
| 84 | else if(strcmp(buffer, "policy_spectrum") == 0) { |
---|
| 85 | } |
---|
| 86 | else if(strcmp(buffer, "policy_spacial") == 0) { |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | else if(strcmp(buffer, "deregister_service") == 0) { |
---|
| 90 | if(strcmp(buffer, "policy_geo") == 0) { |
---|
| 91 | } |
---|
| 92 | else if(strcmp(buffer, "policy_time") == 0) { |
---|
| 93 | } |
---|
| 94 | else if(strcmp(buffer, "policy_spectrum") == 0) { |
---|
| 95 | } |
---|
| 96 | else if(strcmp(buffer, "policy_spacial") == 0) { |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | else if(strcmp(buffer, "query_component_type") == 0) { |
---|
| 100 | SendComponentType(); |
---|
| 101 | } |
---|
| 102 | else if(strcmp(buffer, "reset_sml") == 0) { |
---|
| 103 | Reset(); |
---|
| 104 | } |
---|
| 105 | else if(strcmp(buffer, "shutdown_sml") == 0) { |
---|
| 106 | Shutdown(); |
---|
| 107 | } |
---|
| 108 | } |
---|
[163] | 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | void |
---|
| 113 | ServiceManagementLayer::Shutdown() |
---|
| 114 | { |
---|
[204] | 115 | DeregisterComponent(); |
---|
[163] | 116 | } |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | void |
---|
| 120 | ServiceManagementLayer::Reset() |
---|
| 121 | { |
---|
[204] | 122 | DeregisterComponent(); |
---|
| 123 | LoadConfiguration(); |
---|
[163] | 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | void |
---|
[200] | 128 | ServiceManagementLayer::RegisterComponent() |
---|
[163] | 129 | { |
---|
[200] | 130 | SendMessage(shellSocketFD, "register_sml"); |
---|
[164] | 131 | LOG("ServiceManagementLayer:: Registration message sent.\n"); |
---|
[163] | 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | void |
---|
[200] | 136 | ServiceManagementLayer::DeregisterComponent() |
---|
[163] | 137 | { |
---|
[204] | 138 | SendMessage(shellSocketFD, "deregister_sml"); |
---|
| 139 | LOG("ServiceManagementLayer:: Deregistration message sent.\n"); |
---|
| 140 | |
---|
| 141 | shutdown(shellSocketFD, 2); |
---|
| 142 | close(shellSocketFD); |
---|
| 143 | shellSocketFD = -1; |
---|
| 144 | LOG("ServiceManagementLayer:: Shell socket closed.\n"); |
---|
[163] | 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | void |
---|
| 149 | ServiceManagementLayer::TransferRadioConfiguration() |
---|
| 150 | { |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | void |
---|
| 155 | ServiceManagementLayer::TransferExperience() |
---|
| 156 | { |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | void |
---|
| 161 | ServiceManagementLayer::ReceiveServices() |
---|
| 162 | { |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | void |
---|
| 167 | ServiceManagementLayer::SetActiveMission() |
---|
| 168 | { |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | void |
---|
| 173 | ServiceManagementLayer::ListServices() |
---|
| 174 | { |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | void |
---|
| 179 | ServiceManagementLayer::ReloadConfiguration() |
---|
| 180 | { |
---|
[204] | 181 | LOG("ServiceManagementLayer:: Reloading Configuration.\n"); |
---|
[163] | 182 | } |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | void |
---|
| 186 | ServiceManagementLayer::LoadConfiguration() |
---|
| 187 | { |
---|
[164] | 188 | LOG("ServiceManagementLayer:: Loading Configuration.\n"); |
---|
[163] | 189 | } |
---|
| 190 | |
---|