More coding

So I have more C++ to relearn. I had to remember how to pass by reference and update same. I reworked the code to move all the hard coding to the routine and thus hid all of it.

Here is a bit of the main now:

int main()
	// Print a header of execution out
	auto result = std::time(nullptr);	
	std::cout << "Start: Master Control Program " << std::endl;
	std::cout << "Local Time: " <<
	    std::asctime(std::localtime(&result)) << std::endl;
    // Get running values
    std::string versionnumber, storedirectory, sharedirectory, UUID[10];
    MCPParms ourparms("MCP.xml"); // parms for program
    try {
    catch (std::exception const&  ex) {
       std::cout << ex.what() << std::endl;
       return (1);
	// Write out version number
	std::cout << "File version: " << versionnumber << std::endl;
	// write out UUID of starting value
	std::cout << "UUID " << UUID[0] << std::endl;;
	int client = ourparms.client();
	std::cout << "Client " << client;
	if (client == 0) {
	    std::cout << " Primary!";
	std::cout << std::endl;
	std::cout << "Store: " << storedirectory << std::endl;
	std::cout << "Share: " << sharedirectory << std::endl;
	// Shutdown
	result = std::time(nullptr);
    std::cout << "Exit: Master Control Program " << std::endl;
	std::cout << "Local Time: " <<
	    std::asctime(std::localtime(&result)) << std::endl;
    // Leave politely
    return 0;


I have left the open of the file to be a try/except as I think it would hard to handle it in the constructor. I have moved the getting of values to methods.

That code looks like this (please notice the one bit of crazy C++ code that is obscure):

void MCPParms::version(std::string &myversion)
    myversion = this->get("mcp.version");

void MCPParms::UUID(std::string myUUID[10])
    myUUID[0] = this->get("UUID.0");
    myUUID[1] = this->get("UUID.1");
	myUUID[2] = this->get("UUID.2");
	myUUID[3] = this->get("UUID.3");
    myUUID[4] = this->get("UUID.4");
	myUUID[5] = this->get("UUID.5");
	myUUID[6] = this->get("UUID.6");
    myUUID[7] = this->get("UUID.7");
	myUUID[8] = this->get("UUID.8");
	myUUID[9] = this->get("UUID.9");

void MCPParms::store(std::string &mystore)
    mystore = this->get("");

void MCPParms::share(std::string &myshare)
    myshare = this->get("mcp.share");

int MCPParms::client()
    You would think this would be easy. But no.
    Here is the logic I used.... Broke it in steps to be clear

    std::string myclientstr = this->get("mcp.client");
    int myclient = atoi(myclientstr.c_str()); // Crazy C++ code
    return myclient;

The spacing is better in the code. I am tired of trying to align this stuff in WordPress!

So we have added the needed items to begin the next step, actually passing files. I intend to have a file appear in the share directory, process it, accept it, move it to the store directory, and send back an acknowledgment​. That is the next step. I am having trouble finding a way to get a list of files in a directory and information on the files. It appears that this is not available in C++11 that I am using. I will keep digging.

We are about to step out into the interesting bits. I hope to at least have code that can see files next time.

I forgot to add that I wrote a program to create the XML file. That is how I get all the values into​ the file. When I get this running the file will be create once and then copied to the various systems with different client numbers.​

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s