~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/binlog_reader.cc

  • Committer: Monty Taylor
  • Date: 2009-08-17 18:46:08 UTC
  • mto: (1182.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090817184608-0b2emowpjr9m6le7
"Fixed" the deadlock test. I'd still like someone to look at what's going on here.

Show diffs side-by-side

added added

removed removed

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