Index: branches/FEPSimulator/FEPSim.cpp
===================================================================
--- branches/FEPSimulator/FEPSim.cpp	(revision 84)
+++ branches/FEPSimulator/FEPSim.cpp	(revision 86)
@@ -1,26 +1,15 @@
 #include "FEPSim.h"
 
-/**
- * Constructor
- * 
- * @param host The host rpc server ip address
- * @param networkFile the xml network file
- */
-FEPSim::FEPSim(char * ATMShost) {
+FEPSim::FEPSim(char * ATMShost, int FEP_PROG, int FEP_REV, int SOCK_PORT) {
     this->ATMSHost = ATMShost;
+    this->FEP_PROG = FEP_PROG;
+    this->FEP_REV = FEP_REV;
+    this->SOCK_PORT = SOCK_PORT;
 }
 
-/**
- * Destructor
- */
 FEPSim::~FEPSim() {
-    cout << "Destroying client..." << endl;
-    clnt_destroy(clnt);
+
 }
 
-/**
- * Handler for the ATMS RPC Response (to the client RPC Call)
- * @param response pointer to fep_reply struct
- */
 void FEPSim::handleCallResponse(void *response) {
     // Failed RPC Call
@@ -34,10 +23,9 @@
 }
 
-void FEPSim::sendReplys(char * xml)
-{
+void FEPSim::sendReplys(char * xml) {
     NetworkReader networkReader = NetworkReader(xml);
     vector<FEP_LINE*> lines = networkReader.getLines();
     vector<STATION*> ldsMap = networkReader.getStations();
-    
+
     // Send one reply for every FEPLine
     for (int i = 0; i < lines.size(); i++) {
@@ -104,29 +92,22 @@
 }
 
-/**
- * Sends an fep_reply for every line in the FEP.
- */
 void FEPSim::updateATMS(char * xml) {
-    if(createClient(this->ATMSHost))
-    {
+    if (createClient()) {
         sendReplys(xml);
+        cout << "Destroying client..." << endl;
+        clnt_destroy(clnt);
     }
 }
 
-/**
- * Creates the RPC Client. If not successful, exit with status 1.
- * @param host rpc server ip
- */
-bool FEPSim::createClient(char * host) {
+bool FEPSim::createClient() {
     /* Create RPC Client to communicate with ATMS */
     bool success = true;
-    cout << "Creating RPC Client" << endl;
-    clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp");
+
+    clnt = clnt_create(this->ATMSHost, FEP_PROG, FEP_REV, "tcp");
     /* Check if client creation failed */
     if (clnt == (CLIENT *) NULL) {
-        cerr << "Can't create client to " << host << endl;
+        cerr << "Can't create client to " << this->ATMSHost << endl;
         success = false;
-    }
-    else {
+    } else {
         cout << "Client created" << endl;
     }
@@ -134,24 +115,10 @@
 }
 
-/**
- * Main driver for ATMSCommunicator. Creates an RPC Client from command line args.
- * @param argc
- * @param argv
- * @return 
- */
-int main(int argc, char *argv[]) {
-    if(argc != 3)
-    {
-        cerr << "Usage: FEPSim <ATMS_Host> <FEP_ATMSDriver_PortNo" << endl;
-        exit(1);
-    }
-    char *FEPSimHost = argv[1];    
-    FEPSim fep = FEPSim(FEPSimHost);
-    
+void FEPSim::runSockServer() {
     int sockfd, newsockfd, portno, clilen;
     char buffer[BUFF_SIZE];
     struct sockaddr_in serv_addr, cli_addr;
     int n;
-    portno = atoi(argv[2]);
+    portno = this->SOCK_PORT;
 
     /* First call to socket() function */
@@ -184,6 +151,6 @@
 
     /* Accept actual connections from the client */
-    while(1) {
-        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
+    while (1) {
+        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *) & clilen);
 
         if (newsockfd < 0) {
@@ -195,20 +162,18 @@
         // zero out buffer
         bzero(buffer, BUFF_SIZE);
-        
+
         // read XML from socket
         int totBytes = 0;
-        while ((n = recv(newsockfd, &buffer[totBytes], sizeof(buffer), 0)) > 0) {
+        while ((n = recv(newsockfd, &buffer[totBytes], sizeof (buffer), 0)) > 0) {
             totBytes += n;
         }
-        
+
         if (n < 0) {
             perror("ERROR reading from socket");
             exit(1);
         }
-        
+
         // send data to atms
-        fep.updateATMS(buffer);
+        updateATMS(buffer);
     }
-
-    return 0;
 }
