PhoenixMock  1.1.0
Tools to split/merge/print mock
Loading...
Searching...
No Matches
main_restore.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include "OptionParser.h"
8
9#include "phoenix_mock.h"
10
12
14OptionParser createOptionParser(){
15 OptionParser parser(true, __PROGRAM_VERSION__);
16 parser.setExampleLongOption("phoenix_mock_restore --input=file.pmock");
17 parser.setExampleShortOption("phoenix_mock_restore -i file2.mock file2.pmock");
18
19 parser.addOption("input", "i", OptionType::FILENAME, true, "List of input mock to get the info");
20 return parser;
21}
22
24
27bool restoreMockFile(const PPath & inputFile){
28 FILE* fp = fopen(inputFile.c_str(), "r+");
29 if(fp == NULL){
30 std::cerr << "restoreMockFile : cannot open file '"<<inputFile<<"'" << std::endl;
31 return false;
32 }
33 size_t nbMessage(0lu);
34 bool isReadFileOk = fseek(fp, sizeof(size_t), SEEK_SET) == 0; //We can skip the possible broken number of messages in the mock
35 while(isReadFileOk){
36 size_t nbByteInMessage(0lu);
37 isReadFileOk &= data_load(fp, nbByteInMessage);
38 isReadFileOk &= fseek(fp, sizeof(size_t) + nbByteInMessage, SEEK_CUR) == 0; //let's jump until the next message
39 nbMessage += isReadFileOk;
40 }
41 fseek(fp, 0lu, SEEK_SET);
42 bool b = data_save(fp, nbMessage);
43 fseek(fp, 0l, SEEK_END);
44 fclose(fp);
45 return b;
46}
47
49
52bool restoreAllMock(const std::vector<PPath> & vecInputFile){
53 bool b(true);
54 for(std::vector<PPath>::const_iterator itFile(vecInputFile.begin()); itFile != vecInputFile.end(); ++itFile){
55 b &= restoreMockFile(*itFile);
56 }
57 return b;
58}
59
60int main(int argc, char** argv){
61 OptionParser parser = createOptionParser();
62 parser.parseArgument(argc, argv);
63 const OptionMode & defaultMode = parser.getDefaultMode();
64 std::vector<PPath> vecInputFile;
65 defaultMode.getValue(vecInputFile, "input");
66 return restoreAllMock(vecInputFile) - 1;
67}
68
69
int main(int argc, char **argv)
bool restoreAllMock(const std::vector< PPath > &vecInputFile)
Restore all mock files.
OptionParser createOptionParser()
Create the OptionParser of this program.
bool restoreMockFile(const PPath &inputFile)
Restore a mock file.