Klv2CoT Converter Version 1.0
Klv2CoTTest.cpp
#include <IKlv2CoTConv.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

#if !defined(WIN32)
        const char* CoTFile = "/home/alexc/workspace/cot2klvws/CoT2KlvTest/CoT.xml";
        const char* KlvFile = "/home/alexc/workspace/cot2klvws/CoT2KlvTest/Klv.bin";
#else 
        const char* CoTFile = "CoT.xml";
        const char* KlvFile = "Klv.bin";
#endif          

char* ReadBinData(const char* path, int& l);

void writeFile(const char* path, const char* cot_buf, size_t len);


int main()
{
                IKlv2CoTConv* pKlv2CoTConv;
                size_t len;
                string xmlStrPP, xmlStrSPI;
                string pathMessage1 = "c:\\SP.xml";
                string pathMessage2 = "c:\\SPI.xml";
                string path;

            cout << "Klv2CoT Test Application" << endl;
            try
            {
                        // Create Converter (LDS test)
                        pKlv2CoTConv = CreateKlv2CoTConv(IKlv2CoTConv::KLV_MODE::LDS);

                        // Create Converter (UDS test)
                        //pKlv2CoTConv = CreateKlv2CoTConv(IKlv2CoTConv::KLV_MODE::UDS);

                        // Read Klv bin data into the buffer
                        cout << "Please enter bin file path:" << endl;
                    getline (cin, path);
                    int l;
                    char* klv_buf =  ReadBinData(path.c_str(), l);
                        
                        // Parse Klv buffer and fill the CoT with the encoded data
                        if(pKlv2CoTConv->Process(klv_buf, len, xmlStrPP, xmlStrSPI))
                        {
                                // Write data to XML file.
                                 writeFile(pathMessage1.c_str(), xmlStrPP.c_str(),xmlStrPP.length());  
                                 writeFile(pathMessage2.c_str(), xmlStrSPI.c_str(),xmlStrSPI.length()) ;     
                        }
                        else
                                cout << "Error parsing Klv buffer" << endl;

            }
            catch(Klv2CoTConvException& err)
            {
                cout << err.what() << endl;
            }

                // Delete converter
            if(pKlv2CoTConv)
                delete pKlv2CoTConv;


        return 0;
}

char* ReadBinData(const char* path, int& l)
 {
  char * buffer;

  ifstream is;
  is.open (path, ios::binary );

  // get length of file:
  is.seekg (0, ios::end);
  l = is.tellg();
  is.seekg (0, ios::beg);

  buffer = new char [l];
 
  is.read (buffer,l);
  is.close(); 
  
  return buffer;
}

// write data to XML file
void writeFile(const char* path, const char* cot_buf, size_t len)
{
       fstream xml_file(path, ios::out|ios::app); 
       xml_file.write(cot_buf, len);
       xml_file.close();
}
Untitled 1




 Copyright 2011,    IMPLEOTV SYSTEMS LTD