/*
 * BackupRestore.c
 * 
 * Gocator 2000 Sample
 * Copyright (C) 2011 by LMI Technologies Inc.
 * 
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 *
 * Purpose: Backup a Gocator system and restore it
 *
 */
#include <Go2.h>
#include <stdio.h>

void main(int argc, char **argv)
{
	int status;
	Go2System system = GO2_NULL;
	Go2Sensor mainSensor = GO2_NULL;
	Go2IPAddress address;
	char* backupFile = "SystemBackup.bin";

	// initialize Go2 API
	if ((status = Go2Api_Initialize()) != GO2_OK)
	{
		printf("Error: Go2Api_Initialize:%d\n", status);
		return;
	}

	// construct Go2 system object
	if ((status = Go2System_Construct(&system)) != GO2_OK)
	{
		printf("Error: Go2System_Construct:%d\n", status);
		return;
	}

	// convert ip address string to Go2IPAddress object
	if ((status = Go2IPAddress_Parse("192.168.1.10", &address)) != GO2_OK)
	{
		printf("Error: Go2IPAddress_Parse:%d\n", status);
		return;
	}

	// connect to Gocator system at default address
	if ((status = Go2System_Connect(system, address)) != GO2_OK)
	{
		printf("Error: Go2System_Connect:%d\n", status);
		return;
	}

	printf("Creating backup file:%s\n", backupFile);
	printf("-------------------\n");
	if ((status = Go2System_Backup(system, backupFile)) != GO2_OK)
	{
		printf("Error: Go2System_Backup:%d\n", status);
		return;
	}

	printf("Restoring from  backup file:%s\n", backupFile);
	printf("-------------------\n");
	if ((status = Go2System_Restore(system, backupFile)) != GO2_OK)
	{
		printf("Error: Go2System_Restore:%d\n", status);
		return;
	}

	// destroy system handle
	if ((status = Go2System_Destroy(system)) != GO2_OK)
	{
		printf("Error: Go2System_Destroy:%d\n", status);
		return;
	}

	// terminate Go2 API
	if ((status = Go2Api_Terminate()) != GO2_OK)
	{
		printf("Error: Go2Api_Terminate:%d\n", status);
		return;
	}
	
	printf("Press any key to continue...\n");
	getchar();

	return;
}