~drizzle-trunk/drizzle/development

1931.2.1 by David Shrewsbury
Move transaction_reader from drizzled/message to transaction_log plugin; also pulled transaction_reader file operations out into separate class.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2010 David Shrewsbury <shrewsbury.dave@gmail.com>
1931.2.1 by David Shrewsbury
Move transaction_reader from drizzled/message to transaction_log plugin; also pulled transaction_reader file operations out into separate class.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
/**
21
 * @file
22
 * Declaration of a class used to read the GPB messages written
23
 * by transaction_writer.
24
 */
25
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
26
#pragma once
1931.2.1 by David Shrewsbury
Move transaction_reader from drizzled/message to transaction_log plugin; also pulled transaction_reader file operations out into separate class.
27
28
#include <string>
29
#include <google/protobuf/io/zero_copy_stream_impl.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
30
#include <drizzled/message/transaction.pb.h>
1931.2.1 by David Shrewsbury
Move transaction_reader from drizzled/message to transaction_log plugin; also pulled transaction_reader file operations out into separate class.
31
32
class TransactionFileReader
33
{
34
public:
35
  TransactionFileReader();
36
  ~TransactionFileReader();
37
38
  /**
39
   * Open the given transaction log file.
40
   *
41
   * @param filename Name of the file to open
42
   * @param start_pos Position within the file to begin reading
43
   *
44
   * @retval true Success
45
   * @retval false Failure
46
   */
47
  bool openFile(const std::string &filename, int start_pos = 0);
48
49
  /**
50
   * Read in next Transaction message and checksum.
51
   *
52
   * @note Error message will be "EOF" when end-of-file is reached.
53
   *
54
   * @param transaction Storage for the Transaction message
55
   * @param checksum Storage for the checksum value
56
   *
57
   * @retval true Success
58
   * @retval false Failure or EOF
59
   */
60
  bool getNextTransaction(drizzled::message::Transaction &transaction,
61
                          uint32_t *checksum);
62
63
  /**
64
   * Perform a checksum of the last read transaction message.
65
   */
66
  uint32_t checksumLastReadTransaction();
67
68
  /**
69
   * Get the error message from the last failed operation.
70
   */
2385.3.30 by Olaf van der Spek
cppcheck
71
  const std::string& getErrorString() const
1931.2.1 by David Shrewsbury
Move transaction_reader from drizzled/message to transaction_log plugin; also pulled transaction_reader file operations out into separate class.
72
  {
73
    return error;
74
  }
75
76
private:
77
  int file;
78
  char *buffer;
79
  char *temp_buffer;
80
  uint32_t previous_length;
81
  std::string error;
82
  google::protobuf::io::ZeroCopyInputStream *raw_input;
83
};
84