-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer_8h_source.html
108 lines (106 loc) · 23.1 KB
/
writer_8h_source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>proio: /home/travis/build/proio-org/cpp-proio/src/writer.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">proio
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File List</span></a></li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">writer.h</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="preprocessor">#ifndef PROIO_WRITER_H</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="preprocessor">#define PROIO_WRITER_H</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> </div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="preprocessor">#include <condition_variable></span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="preprocessor">#include <cstring></span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="preprocessor">#include <mutex></span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="preprocessor">#include <string></span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="preprocessor">#include <thread></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> </div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="preprocessor">#include "google/protobuf/descriptor.h"</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="preprocessor">#include "google/protobuf/descriptor.pb.h"</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="preprocessor">#include "google/protobuf/io/zero_copy_stream_impl.h"</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> </div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor">#include "event.h"</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="preprocessor">#include "proio/proto/proio.pb.h"</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="keyword">namespace </span><a class="code" href="namespaceproio.html">proio</a> {</div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="keyword">typedef</span> proto::BucketHeader_CompType Compression;</div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="keyword">const</span> Compression LZ4 = proto::BucketHeader::LZ4;</div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="keyword">const</span> Compression GZIP = proto::BucketHeader::GZIP;</div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="keyword">const</span> Compression UNCOMPRESSED = proto::BucketHeader::NONE;</div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="keyword">const</span> std::size_t minBucketWriteWindow = 0x100000;</div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> </div><div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="classproio_1_1BucketOutputStream.html"> 25</a></span> <span class="keyword">class </span><a class="code" href="classproio_1_1BucketOutputStream.html">BucketOutputStream</a> : <span class="keyword">public</span> google::protobuf::io::ZeroCopyOutputStream {</div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>  <a class="code" href="classproio_1_1BucketOutputStream.html">BucketOutputStream</a>();</div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>  <span class="keyword">virtual</span> ~<a class="code" href="classproio_1_1BucketOutputStream.html">BucketOutputStream</a>();</div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> </div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  <span class="keywordtype">bool</span> Next(<span class="keywordtype">void</span> **data, <span class="keywordtype">int</span> *size) <span class="keyword">override</span>;</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  <span class="keywordtype">void</span> BackUp(<span class="keywordtype">int</span> count) <span class="keyword">override</span>;</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  google::protobuf::int64 ByteCount() <span class="keyword">const override</span>;</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  <span class="keywordtype">bool</span> AllowsAliasing() <span class="keyword">const override</span>;</div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> </div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  uint8_t *Bytes();</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <span class="keywordtype">void</span> Reset();</div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <span class="keywordtype">void</span> Reset(uint64_t size);</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  <span class="keywordtype">void</span> WriteTo(google::protobuf::io::ZeroCopyOutputStream *stream);</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <span class="keywordtype">void</span> SetOffset(uint64_t offset);</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> </div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  std::vector<uint8_t> bytes;</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  uint64_t offset;</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> };</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> </div><div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="classproio_1_1Writer.html"> 48</a></span> <span class="keyword">class </span><a class="code" href="classproio_1_1Writer.html">Writer</a> : <span class="keyword">public</span> std::mutex {</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <a class="code" href="classproio_1_1Writer.html">Writer</a>(<span class="keywordtype">int</span> fd);</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <a class="code" href="classproio_1_1Writer.html">Writer</a>(std::string filename);</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  <span class="keyword">virtual</span> ~<a class="code" href="classproio_1_1Writer.html">Writer</a>();</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> </div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keywordtype">void</span> Flush();</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keywordtype">void</span> Push(<a class="code" href="classproio_1_1Event.html">Event</a> *event);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordtype">void</span> PushMetadata(std::string name, <span class="keyword">const</span> std::string &data);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keywordtype">void</span> PushMetadata(std::string name, <span class="keyword">const</span> <span class="keywordtype">char</span> *data);</div><div class="line"><a name="l00083"></a><span class="lineno"><a class="line" href="classproio_1_1Writer.html#a3acfa35de7236610c47ec78173bb8122"> 83</a></span>  <span class="keywordtype">void</span> <a class="code" href="classproio_1_1Writer.html#a3acfa35de7236610c47ec78173bb8122">SetCompression</a>(Compression alg = GZIP, <span class="keywordtype">int</span> level = -1) {</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  compression = alg;</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  complevel = level;</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  }</div><div class="line"><a name="l00092"></a><span class="lineno"><a class="line" href="classproio_1_1Writer.html#a1e0b8b3811dc0ec6ea68c7d4c964d9b6"> 92</a></span>  <span class="keywordtype">void</span> <a class="code" href="classproio_1_1Writer.html#a1e0b8b3811dc0ec6ea68c7d4c964d9b6">SetBucketDumpThreshold</a>(uint64_t thres = 0x1000000) { bucketDumpThres = thres; }</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <a class="code" href="classproio_1_1BucketOutputStream.html">BucketOutputStream</a> *bucket;</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  google::protobuf::io::FileOutputStream *fileStream;</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  uint64_t bucketEvents;</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  Compression compression;</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <span class="keywordtype">int</span> complevel;</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <a class="code" href="classproio_1_1BucketOutputStream.html">BucketOutputStream</a> *compBucket;</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  uint64_t bucketDumpThres;</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  proto::BucketHeader *header;</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  std::map<std::string, std::shared_ptr<const std::string>> metadata;</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  std::set<const google::protobuf::FileDescriptor *> writtenFDs;</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> </div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <span class="keywordtype">void</span> initBucket();</div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> </div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  std::thread streamWriteThread;</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keyword">typedef</span> <span class="keyword">struct </span>{</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordtype">bool</span> isValid;</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> </div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <a class="code" href="classproio_1_1BucketOutputStream.html">BucketOutputStream</a> *compBucket;</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  proto::BucketHeader *header;</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  google::protobuf::io::FileOutputStream *fileStream;</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span> </div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  std::mutex doJobMutex;</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  std::condition_variable doJobCond;</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  std::mutex workerReadyMutex;</div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  std::condition_variable workerReadyCond;</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  } WriteJob;</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  WriteJob streamWriteJob;</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  std::unique_lock<std::mutex> workerReadyLock;</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span> </div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="keyword">static</span> <span class="keywordtype">void</span> streamWrite(WriteJob *job);</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> };</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> </div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> <span class="keyword">const</span> uint8_t magicBytes[] = {0xe1, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span> </div><div class="line"><a name="l00130"></a><span class="lineno"><a class="line" href="classproio_1_1SerializationError.html"> 130</a></span> <span class="keyword">const</span> <span class="keyword">class </span><a class="code" href="classproio_1_1SerializationError.html">SerializationError</a> : <span class="keyword">public</span> std::exception {</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *what() <span class="keyword">const</span> <span class="keywordflow">throw</span>() { <span class="keywordflow">return</span> <span class="stringliteral">"Failed to serialize message"</span>; }</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span> } serializationError;</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> </div><div class="line"><a name="l00134"></a><span class="lineno"><a class="line" href="classproio_1_1FileCreationError.html"> 134</a></span> <span class="keyword">const</span> <span class="keyword">class </span><a class="code" href="classproio_1_1FileCreationError.html">FileCreationError</a> : <span class="keyword">public</span> std::exception {</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *what() <span class="keyword">const</span> <span class="keywordflow">throw</span>() { <span class="keywordflow">return</span> <span class="stringliteral">"Failed to creating file for writing"</span>; }</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> } fileCreationError;</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> </div><div class="line"><a name="l00138"></a><span class="lineno"><a class="line" href="classproio_1_1LZ4FrameCreationError.html"> 138</a></span> <span class="keyword">const</span> <span class="keyword">class </span><a class="code" href="classproio_1_1LZ4FrameCreationError.html">LZ4FrameCreationError</a> : <span class="keyword">public</span> std::exception {</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *what() <span class="keyword">const</span> <span class="keywordflow">throw</span>() { <span class="keywordflow">return</span> <span class="stringliteral">"Failed to create LZ4 frame"</span>; }</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> } lz4FrameCreationError;</div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> } <span class="comment">// namespace proio</span></div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> </div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span> <span class="preprocessor">#endif // PROIO_WRITER_H</span></div><div class="ttc" id="classproio_1_1Writer_html"><div class="ttname"><a href="classproio_1_1Writer.html">proio::Writer</a></div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00048">writer.h:48</a></div></div>
<div class="ttc" id="namespaceproio_html"><div class="ttname"><a href="namespaceproio.html">proio</a></div><div class="ttdef"><b>Definition:</b> <a href="event_8h_source.html#l00011">event.h:11</a></div></div>
<div class="ttc" id="classproio_1_1BucketOutputStream_html"><div class="ttname"><a href="classproio_1_1BucketOutputStream.html">proio::BucketOutputStream</a></div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00025">writer.h:25</a></div></div>
<div class="ttc" id="classproio_1_1FileCreationError_html"><div class="ttname"><a href="classproio_1_1FileCreationError.html">proio::FileCreationError</a></div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00134">writer.h:134</a></div></div>
<div class="ttc" id="classproio_1_1LZ4FrameCreationError_html"><div class="ttname"><a href="classproio_1_1LZ4FrameCreationError.html">proio::LZ4FrameCreationError</a></div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00138">writer.h:138</a></div></div>
<div class="ttc" id="classproio_1_1Writer_html_a1e0b8b3811dc0ec6ea68c7d4c964d9b6"><div class="ttname"><a href="classproio_1_1Writer.html#a1e0b8b3811dc0ec6ea68c7d4c964d9b6">proio::Writer::SetBucketDumpThreshold</a></div><div class="ttdeci">void SetBucketDumpThreshold(uint64_t thres=0x1000000)</div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00092">writer.h:92</a></div></div>
<div class="ttc" id="classproio_1_1Event_html"><div class="ttname"><a href="classproio_1_1Event.html">proio::Event</a></div><div class="ttdef"><b>Definition:</b> <a href="event_8h_source.html#l00014">event.h:14</a></div></div>
<div class="ttc" id="classproio_1_1Writer_html_a3acfa35de7236610c47ec78173bb8122"><div class="ttname"><a href="classproio_1_1Writer.html#a3acfa35de7236610c47ec78173bb8122">proio::Writer::SetCompression</a></div><div class="ttdeci">void SetCompression(Compression alg=GZIP, int level=-1)</div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00083">writer.h:83</a></div></div>
<div class="ttc" id="classproio_1_1SerializationError_html"><div class="ttname"><a href="classproio_1_1SerializationError.html">proio::SerializationError</a></div><div class="ttdef"><b>Definition:</b> <a href="writer_8h_source.html#l00130">writer.h:130</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>