Subversion Repositories public

Rev

Blame | Last modification | View Log | Download | RSS feed

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>inotify-cxx: inotify-cxx.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.4 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>inotify-cxx.h</h1><a href="inotify-cxx_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00003"></a>00003
<a name="l00026"></a>00026 <span class="preprocessor">#ifndef _INOTIFYCXX_H_</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#define _INOTIFYCXX_H_</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;deque&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00032"></a>00032
<a name="l00033"></a>00033 <span class="comment">// Please ensure that the following headers take the right place.</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;sys/inotify.h&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;sys/inotify-syscalls.h&gt;</span>
<a name="l00036"></a>00036
<a name="l00038"></a><a class="code" href="inotify-cxx_8h.html#a0">00038</a> <span class="preprocessor">#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span>
<a name="l00041"></a><a class="code" href="inotify-cxx_8h.html#a1">00041</a> <span class="preprocessor">#define INOTIFY_BUFLEN (1024 * (INOTIFY_EVENT_SIZE + 16))</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00044"></a>00044
<a name="l00048"></a><a class="code" href="classInotifyEvent.html">00048</a> <span class="keyword">class </span><a class="code" href="classInotifyEvent.html">InotifyEvent</a>
<a name="l00049"></a>00049 {
<a name="l00050"></a>00050 <span class="keyword">public</span>:
<a name="l00052"></a>00052
<a name="l00055"></a><a class="code" href="classInotifyEvent.html#a0">00055</a>   <a class="code" href="classInotifyEvent.html#a0">InotifyEvent</a>()
<a name="l00056"></a>00056   {
<a name="l00057"></a>00057     memset(&amp;m_evt, 0, <span class="keyword">sizeof</span>(m_evt));
<a name="l00058"></a>00058     m_evt.wd = (int32_t) -1;
<a name="l00059"></a>00059   }
<a name="l00060"></a>00060  
<a name="l00062"></a>00062
<a name="l00068"></a><a class="code" href="classInotifyEvent.html#a1">00068</a>   <a class="code" href="classInotifyEvent.html#a0">InotifyEvent</a>(<span class="keyword">const</span> <span class="keyword">struct</span> inotify_event* pEvt)
<a name="l00069"></a>00069   {
<a name="l00070"></a>00070     <span class="keywordflow">if</span> (pEvt != NULL) {
<a name="l00071"></a>00071       memcpy(&amp;m_evt, pEvt, <span class="keyword">sizeof</span>(m_evt));
<a name="l00072"></a>00072       <span class="keywordflow">if</span> (pEvt-&gt;name != NULL)
<a name="l00073"></a>00073         m_name = pEvt-&gt;name;
<a name="l00074"></a>00074     }
<a name="l00075"></a>00075     <span class="keywordflow">else</span> {
<a name="l00076"></a>00076       memset(&amp;m_evt, 0, <span class="keyword">sizeof</span>(m_evt));
<a name="l00077"></a>00077       m_evt.wd = (int32_t) -1;
<a name="l00078"></a>00078     }
<a name="l00079"></a>00079   }
<a name="l00080"></a>00080  
<a name="l00082"></a><a class="code" href="classInotifyEvent.html#a2">00082</a>   <a class="code" href="classInotifyEvent.html#a2">~InotifyEvent</a>() {}
<a name="l00083"></a>00083  
<a name="l00085"></a>00085
<a name="l00090"></a><a class="code" href="classInotifyEvent.html#a3">00090</a>   <span class="keyword">inline</span> int32_t <a class="code" href="classInotifyEvent.html#a3">GetDescriptor</a>()<span class="keyword"> const</span>
<a name="l00091"></a>00091 <span class="keyword">  </span>{
<a name="l00092"></a>00092     <span class="keywordflow">return</span> (int32_t) m_evt.wd;
<a name="l00093"></a>00093   }
<a name="l00094"></a>00094  
<a name="l00096"></a>00096
<a name="l00101"></a><a class="code" href="classInotifyEvent.html#a4">00101</a>   <span class="keyword">inline</span> uint32_t <a class="code" href="classInotifyEvent.html#a4">GetMask</a>()<span class="keyword"> const</span>
<a name="l00102"></a>00102 <span class="keyword">  </span>{
<a name="l00103"></a>00103     <span class="keywordflow">return</span> (uint32_t) m_evt.mask;
<a name="l00104"></a>00104   }
<a name="l00105"></a>00105  
<a name="l00107"></a>00107
<a name="l00111"></a><a class="code" href="classInotifyEvent.html#a5">00111</a>   <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classInotifyEvent.html#a5">IsType</a>(uint32_t uType)<span class="keyword"> const</span>
<a name="l00112"></a>00112 <span class="keyword">  </span>{
<a name="l00113"></a>00113     <span class="keywordflow">return</span> (((uint32_t) m_evt.mask) &amp; uType) != 0;
<a name="l00114"></a>00114   }
<a name="l00115"></a>00115  
<a name="l00117"></a>00117
<a name="l00120"></a><a class="code" href="classInotifyEvent.html#a6">00120</a>   <span class="keyword">inline</span> uint32_t <a class="code" href="classInotifyEvent.html#a6">GetCookie</a>()<span class="keyword"> const</span>
<a name="l00121"></a>00121 <span class="keyword">  </span>{
<a name="l00122"></a>00122     <span class="keywordflow">return</span> (uint32_t) m_evt.cookie;
<a name="l00123"></a>00123   }
<a name="l00124"></a>00124  
<a name="l00126"></a>00126
<a name="l00129"></a><a class="code" href="classInotifyEvent.html#a7">00129</a>   <span class="keyword">inline</span> uint32_t <a class="code" href="classInotifyEvent.html#a7">GetLength</a>()<span class="keyword"> const</span>
<a name="l00130"></a>00130 <span class="keyword">  </span>{
<a name="l00131"></a>00131     <span class="keywordflow">return</span> (uint32_t) m_evt.len;
<a name="l00132"></a>00132   }
<a name="l00133"></a>00133  
<a name="l00135"></a>00135
<a name="l00138"></a><a class="code" href="classInotifyEvent.html#a8">00138</a>   <span class="keyword">inline</span> <span class="keyword">const</span> std::string&amp; <a class="code" href="classInotifyEvent.html#a8">GetName</a>()<span class="keyword"> const</span>
<a name="l00139"></a>00139 <span class="keyword">  </span>{
<a name="l00140"></a>00140     <span class="keywordflow">return</span> m_name;
<a name="l00141"></a>00141   }
<a name="l00142"></a>00142  
<a name="l00144"></a>00144
<a name="l00147"></a><a class="code" href="classInotifyEvent.html#a9">00147</a>   <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classInotifyEvent.html#a8">GetName</a>(std::string&amp; rName)<span class="keyword"> const</span>
<a name="l00148"></a>00148 <span class="keyword">  </span>{
<a name="l00149"></a>00149     rName = <a class="code" href="classInotifyEvent.html#a8">GetName</a>();
<a name="l00150"></a>00150   }
<a name="l00151"></a>00151  
<a name="l00153"></a>00153
<a name="l00158"></a><a class="code" href="classInotifyEvent.html#a10">00158</a>   <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classInotifyEvent.html#a10">GetData</a>(<span class="keyword">struct</span> inotify_event* pEvt)
<a name="l00159"></a>00159   {
<a name="l00160"></a>00160     <span class="keywordflow">if</span> (pEvt != NULL)
<a name="l00161"></a>00161       memcpy(pEvt, &amp;m_evt, <span class="keyword">sizeof</span>(m_evt));
<a name="l00162"></a>00162   }
<a name="l00163"></a>00163  
<a name="l00165"></a>00165
<a name="l00168"></a><a class="code" href="classInotifyEvent.html#a11">00168</a>   <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classInotifyEvent.html#a10">GetData</a>(<span class="keyword">struct</span> inotify_event&amp; rEvt)
<a name="l00169"></a>00169   {
<a name="l00170"></a>00170     memcpy(&amp;rEvt, &amp;m_evt, <span class="keyword">sizeof</span>(m_evt));
<a name="l00171"></a>00171   }
<a name="l00172"></a>00172  
<a name="l00174"></a>00174
<a name="l00177"></a>00177   <span class="keywordtype">void</span> <a class="code" href="classInotifyEvent.html#a12">DumpTypes</a>(std::string&amp; rStr) <span class="keyword">const</span>;
<a name="l00178"></a>00178  
<a name="l00179"></a>00179 <span class="keyword">private</span>:
<a name="l00180"></a>00180   <span class="keyword">struct </span>inotify_event m_evt;
<a name="l00181"></a>00181   std::string m_name;        
<a name="l00182"></a>00182 };
<a name="l00183"></a>00183
<a name="l00184"></a>00184
<a name="l00185"></a>00185 <span class="keyword">class </span><a class="code" href="classInotify.html">Inotify</a>;  <span class="comment">// forward declaration</span>
<a name="l00186"></a>00186
<a name="l00187"></a>00187
<a name="l00189"></a><a class="code" href="classInotifyWatch.html">00189</a> <span class="keyword">class </span><a class="code" href="classInotifyWatch.html">InotifyWatch</a>
<a name="l00190"></a>00190 {
<a name="l00191"></a>00191 <span class="keyword">public</span>:
<a name="l00193"></a>00193
<a name="l00200"></a><a class="code" href="classInotifyWatch.html#a0">00200</a>   <a class="code" href="classInotifyWatch.html#a0">InotifyWatch</a>(<span class="keyword">const</span> std::string&amp; rPath, int32_t uMask)
<a name="l00201"></a>00201   {
<a name="l00202"></a>00202     m_path = rPath;
<a name="l00203"></a>00203     m_uMask = uMask;
<a name="l00204"></a>00204     m_wd = (int32_t) -1;
<a name="l00205"></a>00205   }
<a name="l00206"></a>00206  
<a name="l00208"></a><a class="code" href="classInotifyWatch.html#a1">00208</a>   <a class="code" href="classInotifyWatch.html#a1">~InotifyWatch</a>() {}
<a name="l00209"></a>00209  
<a name="l00211"></a>00211
<a name="l00214"></a><a class="code" href="classInotifyWatch.html#a2">00214</a>   <span class="keyword">inline</span> int32_t <a class="code" href="classInotifyWatch.html#a2">GetDescriptor</a>()<span class="keyword"> const</span>
<a name="l00215"></a>00215 <span class="keyword">  </span>{
<a name="l00216"></a>00216     <span class="keywordflow">return</span> m_wd;
<a name="l00217"></a>00217   }
<a name="l00218"></a>00218  
<a name="l00220"></a>00220
<a name="l00223"></a><a class="code" href="classInotifyWatch.html#a3">00223</a>   <span class="keyword">inline</span> <span class="keyword">const</span> std::string&amp; <a class="code" href="classInotifyWatch.html#a3">GetPath</a>()<span class="keyword"> const</span>
<a name="l00224"></a>00224 <span class="keyword">  </span>{
<a name="l00225"></a>00225     <span class="keywordflow">return</span> m_path;
<a name="l00226"></a>00226   }
<a name="l00227"></a>00227  
<a name="l00229"></a>00229
<a name="l00232"></a><a class="code" href="classInotifyWatch.html#a4">00232</a>   <span class="keyword">inline</span> uint32_t <a class="code" href="classInotifyWatch.html#a4">GetMask</a>()<span class="keyword"> const</span>
<a name="l00233"></a>00233 <span class="keyword">  </span>{
<a name="l00234"></a>00234     <span class="keywordflow">return</span> (uint32_t) m_uMask;
<a name="l00235"></a>00235   }
<a name="l00236"></a>00236  
<a name="l00237"></a>00237 <span class="keyword">private</span>:
<a name="l00238"></a><a class="code" href="classInotifyWatch.html#n0">00238</a>   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classInotify.html">Inotify</a>;
<a name="l00239"></a>00239
<a name="l00240"></a>00240   std::string m_path;  
<a name="l00241"></a>00241   uint32_t m_uMask;    
<a name="l00242"></a>00242   int32_t m_wd;        
<a name="l00243"></a>00243 };
<a name="l00244"></a>00244
<a name="l00245"></a>00245
<a name="l00247"></a><a class="code" href="inotify-cxx_8h.html#a2">00247</a> <span class="keyword">typedef</span> std::map&lt;int32_t, InotifyWatch*&gt; <a class="code" href="inotify-cxx_8h.html#a2">IN_WATCH_MAP</a>;
<a name="l00248"></a>00248
<a name="l00249"></a>00249
<a name="l00251"></a><a class="code" href="classInotify.html">00251</a> <span class="keyword">class </span><a class="code" href="classInotify.html">Inotify</a>
<a name="l00252"></a>00252 {
<a name="l00253"></a>00253 <span class="keyword">public</span>:
<a name="l00255"></a>00255
<a name="l00259"></a>00259   <a class="code" href="classInotify.html#a0">Inotify</a>();
<a name="l00260"></a>00260  
<a name="l00262"></a>00262
<a name="l00265"></a>00265   <a class="code" href="classInotify.html#a1">~Inotify</a>();
<a name="l00266"></a>00266  
<a name="l00268"></a>00268   <span class="keywordtype">void</span> <a class="code" href="classInotify.html#a2">Close</a>();
<a name="l00269"></a>00269  
<a name="l00271"></a>00271
<a name="l00274"></a><a class="code" href="classInotify.html#a3">00274</a>   <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a3">IsReady</a>()<span class="keyword"> const</span>
<a name="l00275"></a>00275 <span class="keyword">  </span>{
<a name="l00276"></a>00276     <span class="keywordflow">return</span> m_fd != -1;
<a name="l00277"></a>00277   }
<a name="l00278"></a>00278  
<a name="l00280"></a>00280
<a name="l00284"></a>00284   <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a4">Add</a>(<a class="code" href="classInotifyWatch.html">InotifyWatch</a>* pWatch);
<a name="l00285"></a>00285  
<a name="l00287"></a>00287
<a name="l00291"></a><a class="code" href="classInotify.html#a5">00291</a>   <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a4">Add</a>(<a class="code" href="classInotifyWatch.html">InotifyWatch</a>&amp; rWatch)
<a name="l00292"></a>00292   {
<a name="l00293"></a>00293     <span class="keywordflow">return</span> <a class="code" href="classInotify.html#a4">Add</a>(&amp;rWatch);
<a name="l00294"></a>00294   }
<a name="l00295"></a>00295  
<a name="l00297"></a>00297
<a name="l00302"></a>00302   <span class="keywordtype">void</span> <a class="code" href="classInotify.html#a6">Remove</a>(<a class="code" href="classInotifyWatch.html">InotifyWatch</a>* pWatch);
<a name="l00303"></a>00303  
<a name="l00305"></a>00305
<a name="l00310"></a><a class="code" href="classInotify.html#a7">00310</a>   <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classInotify.html#a6">Remove</a>(<a class="code" href="classInotifyWatch.html">InotifyWatch</a>&amp; rWatch)
<a name="l00311"></a>00311   {
<a name="l00312"></a>00312     <a class="code" href="classInotify.html#a6">Remove</a>(&amp;rWatch);
<a name="l00313"></a>00313   }
<a name="l00314"></a>00314  
<a name="l00316"></a>00316   <span class="keywordtype">void</span> <a class="code" href="classInotify.html#a8">RemoveAll</a>();
<a name="l00317"></a>00317  
<a name="l00319"></a>00319
<a name="l00322"></a><a class="code" href="classInotify.html#a9">00322</a>   <span class="keyword">inline</span> size_t <a class="code" href="classInotify.html#a9">GetWatchCount</a>()<span class="keyword"> const</span>
<a name="l00323"></a>00323 <span class="keyword">  </span>{
<a name="l00324"></a>00324     <span class="keywordflow">return</span> (size_t) m_watches.size();
<a name="l00325"></a>00325   }
<a name="l00326"></a>00326  
<a name="l00328"></a>00328
<a name="l00334"></a>00334   <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a10">WaitForEvents</a>(<span class="keywordtype">bool</span> fNoIntr = <span class="keyword">false</span>);
<a name="l00335"></a>00335  
<a name="l00337"></a>00337
<a name="l00343"></a>00343   <span class="keywordtype">int</span> <a class="code" href="classInotify.html#a11">GetEventCount</a>();
<a name="l00344"></a>00344  
<a name="l00346"></a>00346
<a name="l00353"></a>00353   <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a12">GetEvent</a>(<a class="code" href="classInotifyEvent.html">InotifyEvent</a>* pEvt);
<a name="l00354"></a>00354  
<a name="l00356"></a>00356
<a name="l00362"></a><a class="code" href="classInotify.html#a13">00362</a>   <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a12">GetEvent</a>(<a class="code" href="classInotifyEvent.html">InotifyEvent</a>&amp; rEvt)
<a name="l00363"></a>00363   {
<a name="l00364"></a>00364     <span class="keywordflow">return</span> <a class="code" href="classInotify.html#a12">GetEvent</a>(&amp;rEvt);
<a name="l00365"></a>00365   }
<a name="l00366"></a>00366  
<a name="l00368"></a>00368
<a name="l00375"></a>00375   <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a14">PeekEvent</a>(<a class="code" href="classInotifyEvent.html">InotifyEvent</a>* pEvt);
<a name="l00376"></a>00376  
<a name="l00378"></a>00378
<a name="l00384"></a><a class="code" href="classInotify.html#a15">00384</a>   <span class="keywordtype">bool</span> <a class="code" href="classInotify.html#a14">PeekEvent</a>(<a class="code" href="classInotifyEvent.html">InotifyEvent</a>&amp; rEvt)
<a name="l00385"></a>00385   {
<a name="l00386"></a>00386     <span class="keywordflow">return</span> <a class="code" href="classInotify.html#a14">PeekEvent</a>(&amp;rEvt);
<a name="l00387"></a>00387   }
<a name="l00388"></a>00388  
<a name="l00390"></a>00390
<a name="l00396"></a>00396   <a class="code" href="classInotifyWatch.html">InotifyWatch</a>* <a class="code" href="classInotify.html#a16">FindWatch</a>(<span class="keywordtype">int</span> iDescriptor);  
<a name="l00397"></a>00397
<a name="l00398"></a>00398 <span class="keyword">private</span>:
<a name="l00399"></a>00399   <span class="keywordtype">int</span> m_fd;                            
<a name="l00400"></a>00400   <a class="code" href="inotify-cxx_8h.html#a2">IN_WATCH_MAP</a> m_watches;              
<a name="l00401"></a>00401   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> m_buf[<a class="code" href="inotify-cxx_8h.html#a1">INOTIFY_BUFLEN</a>];  
<a name="l00402"></a>00402   std::deque&lt;InotifyEvent&gt; m_events;    
<a name="l00403"></a>00403 };
<a name="l00404"></a>00404
<a name="l00405"></a>00405
<a name="l00406"></a>00406 <span class="preprocessor">#endif //_INOTIFYCXX_H_</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Sep 4 22:30:17 2006 for inotify-cxx by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address>
</body>
</html>