tool/CommandFoeWrite.cpp
author Florian Pose <fp@igh-essen.com>
Tue, 12 Jan 2010 23:38:35 +0100
branch1.4-foe
changeset 1765 2b0269221410
parent 1708 fae3a1759126
permissions -rw-r--r--
Closed branch.
1707
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1708
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
     3
 * $Id$
1707
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 ****************************************************************************/
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#include <libgen.h> // basename()
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#include <iostream>
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#include <iomanip>
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#include <fstream>
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
using namespace std;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#include "CommandFoeWrite.h"
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#include "byteorder.h"
1708
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
    16
#include "foe.h"
1707
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
/*****************************************************************************/
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
CommandFoeWrite::CommandFoeWrite():
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
    FoeCommand("foe_write", "Store a file on a slave via FoE.")
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
{
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
}
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
/*****************************************************************************/
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
string CommandFoeWrite::helpString() const
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
{
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
    stringstream str;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
    str << getName() << " [OPTIONS] <FILENAME>" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
        << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
        << getBriefDescription() << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
        << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
        << "This command requires a single slave to be selected." << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
    	<< endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
        << "Arguments:" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
        << "  FILENAME can either be a path to a file, or '-'. In" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
        << "           the latter case, data are read from stdin and" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
        << "           the --output-file option has to be specified." << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
        << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
        << "Command-specific options:" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
        << "  --output-file -o <file>   Target filename on the slave." << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
        << "                            If the FILENAME argument is" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
        << "                            '-', this is mandatory." << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
        << "                            Otherwise, the basename() of" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
        << "                            FILENAME is used by default." << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
        << "  --alias       -a <alias>" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
        << "  --position    -p <pos>    Slave selection. See the help" << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        << "                            of the 'slaves' command." << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        << endl
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
        << numericInfo();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
    return str.str();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
}
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
/****************************************************************************/
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
void CommandFoeWrite::execute(MasterDevice &m, const StringVector &args)
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
{
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    stringstream err;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    ec_ioctl_slave_foe_t data;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    ifstream file;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    SlaveList slaves;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    string storeFileName;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    if (args.size() != 1) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
        err << "'" << getName() << "' takes exactly one argument!";
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
        throwInvalidUsageException(err);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    if (args[0] == "-") {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
        loadFoeData(&data, cin);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
        if (getOutputFile().empty()) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
            err << "Please specify a filename for the slave side"
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
                << " with --output-file!";
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
            throwCommandException(err);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        } else {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
            storeFileName = getOutputFile();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    } else {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        file.open(args[0].c_str(), ifstream::in | ifstream::binary);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
        if (file.fail()) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
            err << "Failed to open '" << args[0] << "'!";
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
            throwCommandException(err);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
        }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        loadFoeData(&data, file);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        file.close();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        if (getOutputFile().empty()) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
            char *cpy = strdup(args[0].c_str()); // basename can modify
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
                                                 // the string contents
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
            storeFileName = basename(cpy);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
            free(cpy);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        } else {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
            storeFileName = getOutputFile();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
        }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    try {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        m.open(MasterDevice::ReadWrite);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    } catch (MasterDeviceException &e) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
        if (data.buffer_size)
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
            delete [] data.buffer;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        throw e;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    slaves = selectedSlaves(m);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    if (slaves.size() != 1) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        if (data.buffer_size)
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
            delete [] data.buffer;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        throwSingleSlaveRequired(slaves.size());
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    data.slave_position = slaves.front().position;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    // write data via foe to the slave
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    data.offset = 0;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    strncpy(data.file_name, storeFileName.c_str(), sizeof(data.file_name));
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    try {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        m.writeFoe(&data);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    } catch (MasterDeviceException &e) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
        if (data.buffer_size)
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
            delete [] data.buffer;
1708
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   124
        if (data.result) {
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   125
            if (data.result == FOE_OPCODE_ERROR) {
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   126
                err << "FoE write aborted with error code 0x"
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   127
                    << setw(8) << setfill('0') << hex << data.error_code
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   128
                    << ": " << errorText(data.error_code);
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   129
            } else {
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   130
                err << "Failed to write via FoE: "
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   131
                    << resultText(data.result);
fae3a1759126 Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1707
diff changeset
   132
            }
1707
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
            throwCommandException(err);
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        } else {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
            throw e;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
        }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    if (getVerbosity() == Verbose) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        cerr << "FoE writing finished." << endl;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    if (data.buffer_size)
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        delete [] data.buffer;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
}
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
/*****************************************************************************/
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
void CommandFoeWrite::loadFoeData(
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        ec_ioctl_slave_foe_t *data,
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
        const istream &in
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
        )
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
{
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    stringstream err;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    ostringstream tmp;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    tmp << in.rdbuf();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    string const &contents = tmp.str();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    if (getVerbosity() == Verbose) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        cerr << "Read " << contents.size() << " bytes of FoE data." << endl;
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    data->buffer_size = contents.size();
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    if (data->buffer_size) {
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        // allocate buffer and read file into buffer
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
        data->buffer = new uint8_t[data->buffer_size];
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
        contents.copy((char *) data->buffer, contents.size());
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    }
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
}
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
11ec009e145d Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
/*****************************************************************************/