Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
streams.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of version 2 of the GNU General Public License as
7 // published by the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // There is a copy of the GNU General Public License in the COPYING file
15 // packaged with this plugin; if you cannot find it, write to the Free
16 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301 USA
18 
19 #ifndef __MPICOMM_H__
20 #define __MPICOMM_H__
21 
22 #ifdef MPI_DIST_SERVER
23 #include <mpi.h>
24 #endif
25 #include <streambuf>
26 #include <iostream>
27 #include <vector>
28 #include <stdio.h>
29 #include "percytypes.h"
30 #include "percyparams.h"
31 
32 #ifdef MPI_DIST_SERVER
33 class MPIStreamBuf : public std::streambuf
34 {
35 public:
36  MPIStreamBuf (int other_rank, MPI_Comm comm = MPI_COMM_WORLD);
37  ~MPIStreamBuf ();
38 
39 protected:
40  virtual int underflow ();
41  virtual int overflow (int c = EOF);
42  virtual std::streamsize xsputn (const char * s, std::streamsize n);
43 
44 private:
45  char * buffer;
46  int buffersize;
47 
48  int other_rank;
49  int my_rank;
50  MPI_Comm comm;
51 };
52 #endif
53 
54 struct BufferInfo {
55  BufferInfo () : addr(), size() {}
56  BufferInfo (char * addr, dbsize_t size) : addr(addr), size(size) {}
57  char * addr;
58  dbsize_t size;
59 };
60 
61 typedef std::vector<BufferInfo> BufferList;
62 
63 class MemoryStreamBuf : public std::streambuf {
64 public:
65  MemoryStreamBuf ();
66  MemoryStreamBuf (BufferList inbuffers, BufferList outbuffers);
67  virtual ~MemoryStreamBuf ();
68 
69  void add_inbuffer (char * addr, dbsize_t size);
70  void add_outbuffer (char * addr, dbsize_t size);
71 
72  virtual std::streamsize showmanyc ();
73  virtual int underflow ();
74  virtual int uflow ();
75  virtual int overflow (int c = EOF);
76 
77  bool in_eof ();
78  bool out_eof ();
79 
80 private:
81  BufferList inbuffers;
82  BufferList outbuffers;
83  std::streamsize inbufferindex;
84  std::streamsize outbufferindex;
85  dbsize_t incharindex;
86  dbsize_t outcharindex;
87 };
88 
89 #endif
Definition: streams.h:63
This header contains typedefs for seamless switching between 32- and 64-bit builds of Percy++...
Defines the basic structure of protocol parameters (PercyParams), client parameters (PercyClientParam...
Definition: streams.h:54