~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/binlog_reader.cc

  • Committer: Mark Atwood
  • Date: 2008-10-03 01:39:40 UTC
  • mto: This revision was merged to the branch mainline in revision 437.
  • Revision ID: mark@fallenpegasus.com-20081003013940-mvefjo725dltz41h
rename logging_noop to logging_query

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "binary_log.h"
 
2
 
 
3
#include <iostream>
 
4
 
 
5
#include <google/protobuf/io/coded_stream.h>
 
6
#include <google/protobuf/io/zero_copy_stream_impl.h>
 
7
 
 
8
#include <getopt.h>
 
9
#include <fcntl.h>
 
10
 
 
11
#include <sys/stat.h>
 
12
 
 
13
using namespace google::protobuf;
 
14
using namespace google::protobuf::io;
 
15
 
 
16
void print_usage_and_exit(char *prog) {
 
17
  using std::cerr;
 
18
  const char *name= strrchr(prog, '/');
 
19
 
 
20
  if (name)
 
21
    ++name;
 
22
  else
 
23
    name= "binlog_reader";
 
24
  cerr << "Usage: " << name << " <options>\n"
 
25
       << "    --input name   Read queries from file <name> (default: 'log.bin')\n"
 
26
       << std::flush;
 
27
  exit(1);
 
28
}
 
29
 
 
30
 
 
31
void
 
32
print_event(BinaryLog::Event *event)
 
33
{
 
34
}
 
35
 
 
36
 
 
37
int
 
38
main(int argc, char *argv[])
 
39
{
 
40
  using std::ios;
 
41
 
 
42
  static struct option options[] = {
 
43
    { "input",     1 /* has_arg */, NULL, 0 },
 
44
    { 0, 0, 0, 0 }
 
45
  };
 
46
 
 
47
  const char *file_name= "log.bin";
 
48
 
 
49
  int ch, option_index;
 
50
  while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
 
51
    if (ch == '?')
 
52
      print_usage_and_exit(argv[0]);
 
53
 
 
54
    switch (option_index) {
 
55
    case 0:                                     // --input
 
56
      file_name= optarg;
 
57
      break;
 
58
 
 
59
    }
 
60
  }
 
61
 
 
62
  if (optind > argc)
 
63
    print_usage_and_exit(argv[0]);
 
64
 
 
65
  int fd = open(file_name, O_RDONLY);
 
66
  ZeroCopyInputStream* raw_input = new FileInputStream(fd);
 
67
  CodedInputStream *coded_input = new CodedInputStream(raw_input);
 
68
 
 
69
  BinaryLog::Event event;
 
70
  while (event.read(coded_input))
 
71
    event.print(std::cout);
 
72
 
 
73
  delete coded_input;
 
74
  delete raw_input;
 
75
  close(fd);
 
76
}