monotone

monotone Mtn Source Tree

Root/packet.hh

1#ifndef __PACKET_HH__
2#define __PACKET_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <iosfwd>
10#include <memory>
11
12#include <boost/function.hpp>
13
14#include "app_state.hh"
15#include "ui.hh"
16#include "vocab.hh"
17
18// the idea here is that monotone can produce and consume "packet streams",
19// where each packet is *informative* rather than transactional. that is to
20// say, they contain no information which needs to be replied to or processed
21// in any particular manner during some communication session.
22//
23// unlike nearly every other part of this program, the packet stream
24// interface is really *stream* oriented. the idea being that, while you
25// might be able to keep any one delta or file in memory at once, asking
26// you to keep *all* the deltas or files associated with a large chunk of
27// work, in memory, is a bit much.
28//
29// packet streams are ascii text, formatted for comfortable viewing on a
30// terminal or inclusion in an email / netnews post. they can be edited with
31// vi, filtered with grep, and concatenated with cat.
32//
33// there are currently 8 types of packets, though this can grow without hurting
34// anyone's feelings. if there's a backwards compatibility problem, just introduce
35// a new packet type.
36
37struct packet_consumer
38{
39protected:
40 boost::function1<void, revision_id> on_revision_written;
41 boost::function1<void, cert const &> on_cert_written;
42 boost::function1<void, rsa_keypair_id> on_pubkey_written;
43 boost::function1<void, rsa_keypair_id> on_keypair_written;
44public:
45
46 virtual void set_on_revision_written(boost::function1<void, revision_id>
47 const & x);
48 virtual void set_on_cert_written(boost::function1<void, cert const &>
49 const & x);
50 virtual void set_on_pubkey_written(boost::function1<void, rsa_keypair_id>
51 const & x);
52 virtual void set_on_keypair_written(boost::function1<void, rsa_keypair_id>
53 const & x);
54
55 virtual ~packet_consumer() {}
56 virtual void consume_file_data(file_id const & ident,
57 file_data const & dat) = 0;
58 virtual void consume_file_delta(file_id const & id_old,
59 file_id const & id_new,
60 file_delta const & del) = 0;
61 virtual void consume_file_reverse_delta(file_id const & id_new,
62 file_id const & id_old,
63 file_delta const & del) = 0;
64
65
66 virtual void consume_manifest_data(manifest_id const & ident,
67 manifest_data const & dat) = 0;
68 virtual void consume_manifest_delta(manifest_id const & id_old,
69 manifest_id const & id_new,
70 manifest_delta const & del) = 0;
71 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
72 manifest_id const & id_old,
73 manifest_delta const & del) = 0;
74
75
76 virtual void consume_revision_data(revision_id const & ident,
77 revision_data const & dat) = 0;
78 virtual void consume_revision_cert(revision<cert> const & t) = 0;
79
80
81 virtual void consume_public_key(rsa_keypair_id const & ident,
82 base64< rsa_pub_key > const & k) = 0;
83 virtual void consume_key_pair(rsa_keypair_id const & ident,
84 keypair const & kp) = 0;
85};
86
87// this writer writes packets into a stream
88
89struct packet_writer : public packet_consumer
90{
91 std::ostream & ost;
92 explicit packet_writer(std::ostream & o);
93 virtual ~packet_writer() {}
94 virtual void consume_file_data(file_id const & ident,
95 file_data const & dat);
96 virtual void consume_file_delta(file_id const & id_old,
97 file_id const & id_new,
98 file_delta const & del);
99 virtual void consume_file_reverse_delta(file_id const & id_new,
100 file_id const & id_old,
101 file_delta const & del);
102
103 virtual void consume_manifest_data(manifest_id const & ident,
104 manifest_data const & dat);
105 virtual void consume_manifest_delta(manifest_id const & id_old,
106 manifest_id const & id_new,
107 manifest_delta const & del);
108 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
109 manifest_id const & id_old,
110 manifest_delta const & del);
111
112 virtual void consume_revision_data(revision_id const & ident,
113 revision_data const & dat);
114 virtual void consume_revision_cert(revision<cert> const & t);
115
116 virtual void consume_public_key(rsa_keypair_id const & ident,
117 base64< rsa_pub_key > const & k);
118 virtual void consume_key_pair(rsa_keypair_id const & ident,
119 keypair const & kp);
120};
121
122// this writer injects packets it receives to the database.
123
124struct packet_db_writer : public packet_consumer
125{
126private:
127 struct impl;
128 std::auto_ptr<impl> pimpl;
129
130public:
131 packet_db_writer(app_state & app,
132 bool take_keys = false);
133 virtual ~packet_db_writer();
134 virtual void consume_file_data(file_id const & ident,
135 file_data const & dat);
136 virtual void consume_file_delta(file_id const & id_old,
137 file_id const & id_new,
138 file_delta const & del);
139 virtual void consume_file_delta(file_id const & id_old,
140 file_id const & id_new,
141 file_delta const & del,
142 bool write_full);
143 virtual void consume_file_reverse_delta(file_id const & id_new,
144 file_id const & id_old,
145 file_delta const & del);
146
147 virtual void consume_manifest_data(manifest_id const & ident,
148 manifest_data const & dat);
149 virtual void consume_manifest_delta(manifest_id const & id_old,
150 manifest_id const & id_new,
151 manifest_delta const & del);
152 virtual void consume_manifest_delta(manifest_id const & id_old,
153 manifest_id const & id_new,
154 manifest_delta const & del,
155 bool write_full);
156 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
157 manifest_id const & id_old,
158 manifest_delta const & del);
159
160 virtual void consume_revision_data(revision_id const & ident,
161 revision_data const & dat);
162 virtual void consume_revision_cert(revision<cert> const & t);
163
164 virtual void consume_public_key(rsa_keypair_id const & ident,
165 base64< rsa_pub_key > const & k);
166 virtual void consume_key_pair(rsa_keypair_id const & ident,
167 keypair const & kp);
168};
169
170// this writer is just like packet_db_writer, except that none of your calls
171// have any effect until after calling open_valve; at that point, all previous
172// consume_* calls will suddenly take effect.
173
174struct packet_db_valve : public packet_consumer
175{
176private:
177 struct impl;
178 std::auto_ptr<impl> pimpl;
179public:
180 packet_db_valve(app_state & app,
181 bool take_keys = false);
182 virtual ~packet_db_valve();
183 virtual void set_on_revision_written(boost::function1<void, revision_id>
184 const & x);
185 virtual void set_on_cert_written(boost::function1<void, cert const &>
186 const & x);
187 virtual void set_on_pubkey_written(boost::function1<void, rsa_keypair_id>
188 const & x);
189 virtual void set_on_keypair_written(boost::function1<void, rsa_keypair_id>
190 const & x);
191 virtual void consume_file_data(file_id const & ident,
192 file_data const & dat);
193 virtual void consume_file_delta(file_id const & id_old,
194 file_id const & id_new,
195 file_delta const & del);
196 virtual void consume_file_delta(file_id const & id_old,
197 file_id const & id_new,
198 file_delta const & del,
199 bool write_full);
200 virtual void consume_file_reverse_delta(file_id const & id_new,
201 file_id const & id_old,
202 file_delta const & del);
203
204 virtual void consume_manifest_data(manifest_id const & ident,
205 manifest_data const & dat);
206 virtual void consume_manifest_delta(manifest_id const & id_old,
207 manifest_id const & id_new,
208 manifest_delta const & del);
209 virtual void consume_manifest_delta(manifest_id const & id_old,
210 manifest_id const & id_new,
211 manifest_delta const & del,
212 bool write_full);
213 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
214 manifest_id const & id_old,
215 manifest_delta const & del);
216
217 virtual void consume_revision_data(revision_id const & ident,
218 revision_data const & dat);
219 virtual void consume_revision_cert(revision<cert> const & t);
220
221 virtual void consume_public_key(rsa_keypair_id const & ident,
222 base64< rsa_pub_key > const & k);
223 virtual void consume_key_pair(rsa_keypair_id const & ident,
224 keypair const & kp);
225
226 virtual void open_valve();
227};
228
229size_t read_packets(std::istream & in, packet_consumer & cons, app_state & app);
230
231#endif

Archive Download this file

Branches

Tags

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