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 "vocab.hh"
14
15class app_state;
16struct cert;
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
34// hurting anyone's feelings. if there's a backwards compatibility problem,
35// just introduce a new packet type.
36
37struct packet_consumer
38{
39public:
40 virtual ~packet_consumer() {}
41 virtual void consume_file_data(file_id const & ident,
42 file_data const & dat) = 0;
43 virtual void consume_file_delta(file_id const & id_old,
44 file_id const & id_new,
45 file_delta const & del) = 0;
46
47 virtual void consume_revision_data(revision_id const & ident,
48 revision_data const & dat) = 0;
49 virtual void consume_revision_cert(revision<cert> const & t) = 0;
50
51
52 virtual void consume_public_key(rsa_keypair_id const & ident,
53 base64< rsa_pub_key > const & k) = 0;
54 virtual void consume_key_pair(rsa_keypair_id const & ident,
55 keypair const & kp) = 0;
56};
57
58// this writer writes packets into a stream
59
60struct packet_writer : public packet_consumer
61{
62 std::ostream & ost;
63 explicit packet_writer(std::ostream & o);
64 virtual ~packet_writer() {}
65 virtual void consume_file_data(file_id const & ident,
66 file_data const & dat);
67 virtual void consume_file_delta(file_id const & id_old,
68 file_id const & id_new,
69 file_delta const & del);
70
71 virtual void consume_revision_data(revision_id const & ident,
72 revision_data const & dat);
73 virtual void consume_revision_cert(revision<cert> const & t);
74
75 virtual void consume_public_key(rsa_keypair_id const & ident,
76 base64< rsa_pub_key > const & k);
77 virtual void consume_key_pair(rsa_keypair_id const & ident,
78 keypair const & kp);
79};
80
81size_t read_packets(std::istream & in, packet_consumer & cons, app_state & app);
82
83// Local Variables:
84// mode: C++
85// fill-column: 76
86// c-file-style: "gnu"
87// indent-tabs-mode: nil
88// End:
89// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
90
91#endif

Archive Download this file

Branches

Tags

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