tool/cmd_data.cpp
changeset 1126 b09fd81894cb
child 1130 bb1c11adb2db
equal deleted inserted replaced
1125:9976f7b9fe66 1126:b09fd81894cb
       
     1 /*****************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  ****************************************************************************/
       
     6 
       
     7 #include <iostream>
       
     8 using namespace std;
       
     9 
       
    10 #include "globals.h"
       
    11 
       
    12 /*****************************************************************************/
       
    13 
       
    14 const char *help_data =
       
    15     "[OPTIONS]\n"
       
    16     "\n"
       
    17     "Output binary domain data.\n"
       
    18     "\n"
       
    19     "Command-specific options:\n"
       
    20     "  --domain -d <index> Positive numerical domain index. If this option\n"
       
    21     "                      is not specified, data of all domains are\n"
       
    22     "                      output.\n";
       
    23 
       
    24 /****************************************************************************/
       
    25 
       
    26 void outputDomainData(unsigned int);
       
    27 
       
    28 /****************************************************************************/
       
    29 
       
    30 void command_data()
       
    31 {
       
    32     masterDev.open(MasterDevice::Read);
       
    33 
       
    34     if (domainIndex == -1) {
       
    35         unsigned int i;
       
    36         ec_ioctl_master_t master;
       
    37 
       
    38         masterDev.getMaster(&master);
       
    39 
       
    40         for (i = 0; i < master.domain_count; i++) {
       
    41             outputDomainData(i);
       
    42         }
       
    43     } else {
       
    44         outputDomainData(domainIndex);
       
    45     }
       
    46 }
       
    47 
       
    48 /****************************************************************************/
       
    49 
       
    50 void outputDomainData(unsigned int domainIndex)
       
    51 {
       
    52     ec_ioctl_domain_t domain;
       
    53     ec_ioctl_domain_data_t data;
       
    54     unsigned char *processData;
       
    55     unsigned int i;
       
    56     
       
    57     masterDev.getDomain(&domain, domainIndex);
       
    58 
       
    59     if (!domain.data_size)
       
    60         return;
       
    61 
       
    62     processData = new unsigned char[domain.data_size];
       
    63 
       
    64     try {
       
    65         masterDev.getData(&data, domainIndex, domain.data_size, processData);
       
    66     } catch (MasterDeviceException &e) {
       
    67         delete [] processData;
       
    68         throw e;
       
    69     }
       
    70 
       
    71     for (i = 0; i < data.data_size; i++)
       
    72         cout << processData[i];
       
    73     cout.flush();
       
    74 
       
    75     delete [] processData;
       
    76 }
       
    77 
       
    78 /****************************************************************************/