monotone

monotone Mtn Source Tree

Root/packet.hh

1#ifndef __PACKET_HH__
2#define __PACKET_HH__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13#include <iosfwd>
14#include <memory>
15
16#include <boost/function.hpp>
17
18#include "app_state.hh"
19#include "ui.hh"
20#include "vocab.hh"
21
22// the idea here is that monotone can produce and consume "packet streams",
23// where each packet is *informative* rather than transactional. that is to
24// say, they contain no information which needs to be replied to or processed
25// in any particular manner during some communication session.
26//
27// unlike nearly every other part of this program, the packet stream
28// interface is really *stream* oriented. the idea being that, while you
29// might be able to keep any one delta or file in memory at once, asking
30// you to keep *all* the deltas or files associated with a large chunk of
31// work, in memory, is a bit much.
32//
33// packet streams are ascii text, formatted for comfortable viewing on a
34// terminal or inclusion in an email / netnews post. they can be edited with
35// vi, filtered with grep, and concatenated with cat.
36//
37// there are currently 8 types of packets, though this can grow without hurting
38// anyone's feelings. if there's a backwards compatibility problem, just introduce
39// a new packet type.
40
41struct packet_consumer
42{
43protected:
44 boost::function1<void, revision_id> on_revision_written;
45 boost::function1<void, cert const &> on_cert_written;
46 boost::function1<void, rsa_keypair_id> on_pubkey_written;
47 boost::function1<void, rsa_keypair_id> on_keypair_written;
48public:
49
50 virtual void set_on_revision_written(boost::function1<void, revision_id>
51 const & x);
52 virtual void set_on_cert_written(boost::function1<void, cert const &>
53 const & x);
54 virtual void set_on_pubkey_written(boost::function1<void, rsa_keypair_id>
55 const & x);
56 virtual void set_on_keypair_written(boost::function1<void, rsa_keypair_id>
57 const & x);
58
59 virtual ~packet_consumer() {}
60 virtual void consume_file_data(file_id const & ident,
61 file_data const & dat) = 0;
62 virtual void consume_file_delta(file_id const & id_old,
63 file_id const & id_new,
64 file_delta const & del) = 0;
65
66 virtual void consume_revision_data(revision_id const & ident,
67 revision_data const & dat) = 0;
68 virtual void consume_revision_cert(revision<cert> const & t) = 0;
69
70
71 virtual void consume_public_key(rsa_keypair_id const & ident,
72 base64< rsa_pub_key > const & k) = 0;
73 virtual void consume_key_pair(rsa_keypair_id const & ident,
74 keypair const & kp) = 0;
75};
76
77// this writer writes packets into a stream
78
79struct packet_writer : public packet_consumer
80{
81 std::ostream & ost;
82 explicit packet_writer(std::ostream & o);
83 virtual ~packet_writer() {}
84 virtual void consume_file_data(file_id const & ident,
85 file_data const & dat);
86 virtual void consume_file_delta(file_id const & id_old,
87 file_id const & id_new,
88 file_delta const & del);
89
90 virtual void consume_revision_data(revision_id const & ident,
91 revision_data const & dat);
92 virtual void consume_revision_cert(revision<cert> const & t);
93
94 virtual void consume_public_key(rsa_keypair_id const & ident,
95 base64< rsa_pub_key > const & k);
96 virtual void consume_key_pair(rsa_keypair_id const & ident,
97 keypair const & kp);
98};
99
100// this writer injects packets it receives to the database.
101
102struct packet_db_writer : public packet_consumer
103{
104 app_state & app;
105public:
106 packet_db_writer(app_state & app);
107 virtual ~packet_db_writer();
108 virtual void consume_file_data(file_id const & ident,
109 file_data const & dat);
110 virtual void consume_file_delta(file_id const & id_old,
111 file_id const & id_new,
112 file_delta const & del);
113
114 virtual void consume_revision_data(revision_id const & ident,
115 revision_data const & dat);
116 virtual void consume_revision_cert(revision<cert> const & t);
117
118 virtual void consume_public_key(rsa_keypair_id const & ident,
119 base64< rsa_pub_key > const & k);
120 virtual void consume_key_pair(rsa_keypair_id const & ident,
121 keypair const & kp);
122};
123
124size_t read_packets(std::istream & in, packet_consumer & cons, app_state & app);
125
126// Local Variables:
127// mode: C++
128// fill-column: 76
129// c-file-style: "gnu"
130// indent-tabs-mode: nil
131// End:
132// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
133
134#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status