Index: vtcross/branches/bhilburn/src/policy_engines/Makefile.am
===================================================================
--- vtcross/branches/bhilburn/src/policy_engines/Makefile.am	(revision 125)
+++ vtcross/branches/bhilburn/src/policy_engines/Makefile.am	(revision 127)
@@ -3,4 +3,4 @@
 bin_PROGRAMS = policy_demo
 
-policy_demo_SOURCES = default_policy_engine.c
+policy_demo_SOURCES = default_policy_engine.cpp
 
Index: vtcross/branches/bhilburn/src/policy_engines/default_policy_engine.cpp
===================================================================
--- vtcross/branches/bhilburn/src/policy_engines/default_policy_engine.cpp	(revision 127)
+++ vtcross/branches/bhilburn/src/policy_engines/default_policy_engine.cpp	(revision 127)
@@ -0,0 +1,236 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "vtcross/cbr.h"
+#include "vtcross/containers.h"
+
+#define CR_PORT 30002
+
+// error handling
+void error(char *msg)
+{
+    perror(msg);
+    exit(0);
+}
+
+void ReadMessage(int socket,char * buffer) {
+    int i,n;
+
+    n = recv(socket,buffer,256,MSG_PEEK);
+    for(i=0;i<256;i++){
+	    if(strcmp(&buffer[i],"\0") == 0) break;
+    }
+    n = recv(socket,buffer,i+1,0);
+    if (n < 0) 
+         error("ERROR reading from socket");
+    //printf("ReadMessage:%s %d\n",buffer,n);
+}
+
+// setup client socket connection
+int ClientSocket(int argc, char** argv)
+{
+    int sockfd;
+    int portno;
+    struct sockaddr_in serv_addr;
+    struct hostent *server;
+    
+    // server name
+    server = gethostbyname(argv[1]);
+    if (server == NULL) {
+        fprintf(stderr,"ERROR, no such host\n");
+        exit(0);
+    }
+    // port no.
+    portno = atoi(argv[2]);
+    // socket file descriptor
+    sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    if (sockfd < 0) 
+        error("ERROR opening socket");
+    // initiate struct socketaddr_in
+    bzero((char *) &serv_addr, sizeof(serv_addr));
+    serv_addr.sin_family = AF_INET;
+    serv_addr.sin_port = htons(portno);
+    bcopy((char *)server->h_addr, 
+         (char *)&serv_addr.sin_addr.s_addr,
+         server->h_length);
+    // cast sockaddr_in to sockaddr
+    if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) 
+        error("ERROR connecting");
+
+    return sockfd;
+}
+
+    
+int SendMessage(int socketfd, char *message) 
+{
+    int n;
+     
+    strcat(message, "\0000");
+    n = send(socketfd,message,(strlen(message)+1),0);
+    if (n<0)
+        error("Error sending to server\n");
+    else if(n == 0)
+        printf("Server closed the socket.\n");
+   
+    return n;
+}
+
+int GetParameter(int sockfd, struct Parameter pList[], struct CE_Info *ce_info)
+{
+    char buffer[256];
+    int i;
+
+    // numParameters
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+    ce_info->numParameters = atoi(buffer);
+    printf("number of parameters: %d\n", ce_info->numParameters);
+    
+    for (i = 0; i < ce_info->numParameters; i++){
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        printf("Name: %s\n", buffer);
+        strcpy(pList[i].name, buffer);
+    
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        printf("Units: %s\n", buffer);
+        strcpy(pList[i].units, buffer);
+
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        printf("Min: %s\n", buffer);
+        pList[i].min = atof(buffer);
+    
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        printf("Max: %s\n", buffer);
+        pList[i].max = atof(buffer);
+    
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        printf("Step: %s\n", buffer);
+        pList[i].step = atof(buffer);
+    
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        printf("Value: %s\n", buffer);
+        pList[i].value = atof(buffer);
+    
+    }
+    return 1;
+}
+
+
+int GetRequest(int sockfd, struct Parameter pList[], struct CE_Info *ce_info)
+{
+    char buffer[256];
+   
+    // Get control identifier
+    // Possibly could implement some sort of authentication here
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+
+    if(strcmp(buffer,"val") != 0) {
+            printf("Policy Engine:: Unexpected control data received.\n\n");
+        return 0;
+    }
+
+    printf("Policy Engine:: Getting parameters.\n\n");
+    // Get potenial transmission parameter values
+    GetParameter(sockfd, pList, ce_info);
+
+    return 1;
+}
+
+int ValidateTransmissionParameters(struct Parameter pList[], struct CE_Info *ce_info, int decision_array[])
+{
+    int i = 0;
+    // Decision array holds parameter decision
+    // 1 = OK
+    // 0 = FAIL
+
+    printf("Policy Engine:: Policies Validated.\n\n");
+    for (i = 0; i < ce_info->numParameters; i++){
+        decision_array[i] = 1;
+    }
+
+    return 1;
+}
+
+
+int RegisterPE(int sockfd)
+{
+    // Send register message to cognitive radio
+    SendMessage(sockfd, "p_register");
+    printf("Policy Engine:: Registration message sent.\n\n");
+    return 1;
+}
+
+int SendCEDecision(int sockfd, struct Parameter pList[], struct CE_Info *ce_info, int decision_array[])
+{
+    // send results back to server
+    char var[50];
+    int i;
+ 
+    // parameter
+    for (i = 0; i < ce_info->numParameters; i++){
+        sprintf(var, "%i", decision_array[i]);
+        SendMessage(sockfd, var);
+    }
+    
+    return 1;
+}
+
+int ParsePolicies() {
+
+    printf("Policy Engine:: Policies parsed.\n\n");
+
+    return 1;
+}
+
+// main client socket
+int main(int argc, char *argv[])
+{
+    int decision_array[10];
+    struct Parameter pList[10];
+    struct CE_Info ce_info;
+    int sockfd;
+    int ret = 0;
+    
+    // setup client socket connection
+    if (argc < 3) {
+       fprintf(stderr,"usage: %s hostname port\n", argv[0]);
+       exit(0);
+    }
+    
+    // setup client socket connection with server
+    sockfd = ClientSocket(argc, argv);
+
+    // Parse initial Policies 
+    printf("Policy Engine:: Parsing local policies.\n\n");
+    ret = ParsePolicies();
+
+    ret = RegisterPE(sockfd);
+
+    while(1) {
+        
+        printf("Policy Engine:: Waiting for Policy Check Request.\n\n");
+        ret = GetRequest(sockfd, pList, &ce_info);
+       
+        if(ret == 1) {
+            printf("Policy Engine:: Validating Transmission Parameters.\n\n");
+            ValidateTransmissionParameters(pList, &ce_info, decision_array);    
+   
+            printf("Policy Engine:: Sending Policy decision to Server.\n\n");
+            SendCEDecision(sockfd, pList, &ce_info, decision_array);
+        }
+    }
+    
+    return 0;
+}
