Current File : //usr/share/doc/dbus/api/dbus-dataslot_8c_source.html
<!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"/>
<title>D-Bus: dbus-dataslot.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">D-Bus
   &#160;<span id="projectnumber">1.8.20</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">dbus-dataslot.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C; c-file-style: &quot;gnu&quot;; indent-tabs-mode: nil; -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* dbus-dataslot.c  storing data on objects</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2003 Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00007"></a>00007 <span class="comment"> * </span>
<a name="l00008"></a>00008 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00009"></a>00009 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00010"></a>00010 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00011"></a>00011 <span class="comment"> * (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00016"></a>00016 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> * </span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00019"></a>00019 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;dbus-dataslot.h&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &quot;dbus-threads-internal.h&quot;</span>
<a name="l00027"></a>00027 
<a name="l00045"></a>00045 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00046"></a><a class="code" href="group__DBusDataSlot.html#ga49236838eb414100f691a22ad5210cb5">00046</a> <a class="code" href="group__DBusDataSlot.html#ga49236838eb414100f691a22ad5210cb5" title="Initializes a data slot allocator object, used to assign integer IDs for data slots.">_dbus_data_slot_allocator_init</a> (<a class="code" href="structDBusDataSlotAllocator.html" title="An allocator that tracks a set of slot IDs.">DBusDataSlotAllocator</a> *allocator,
<a name="l00047"></a>00047                                 DBusGlobalLock         lock)
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00050"></a>00050   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a> = 0;
<a name="l00051"></a>00051   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a> = 0;
<a name="l00052"></a>00052   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a> = lock;
<a name="l00053"></a>00053 
<a name="l00054"></a>00054   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 
<a name="l00068"></a>00068 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00069"></a><a class="code" href="group__DBusDataSlot.html#gaf61f2bd0148bace4f67a2d6d97b26ea9">00069</a> <a class="code" href="group__DBusDataSlot.html#gaf61f2bd0148bace4f67a2d6d97b26ea9" title="Allocates an integer ID to be used for storing data in a DBusDataSlotList.">_dbus_data_slot_allocator_alloc</a> (<a class="code" href="structDBusDataSlotAllocator.html" title="An allocator that tracks a set of slot IDs.">DBusDataSlotAllocator</a> *allocator,
<a name="l00070"></a>00070                                  <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>          *slot_id_p)
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072   <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a> slot;
<a name="l00073"></a>00073 
<a name="l00074"></a>00074   <span class="keywordflow">if</span> (!_dbus_lock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>))
<a name="l00075"></a>00075     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00076"></a>00076 
<a name="l00077"></a>00077   <span class="keywordflow">if</span> (*slot_id_p &gt;= 0)
<a name="l00078"></a>00078     {
<a name="l00079"></a>00079       slot = *slot_id_p;
<a name="l00080"></a>00080       
<a name="l00081"></a>00081       _dbus_assert (slot &lt; allocator-&gt;n_allocated_slots);
<a name="l00082"></a>00082       _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> == slot);
<a name="l00083"></a>00083       
<a name="l00084"></a>00084       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> += 1;
<a name="l00085"></a>00085 
<a name="l00086"></a>00086       <span class="keywordflow">goto</span> out;
<a name="l00087"></a>00087     }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089   _dbus_assert (*slot_id_p &lt; 0);
<a name="l00090"></a>00090   
<a name="l00091"></a>00091   <span class="keywordflow">if</span> (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a> &lt; allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a>)
<a name="l00092"></a>00092     {
<a name="l00093"></a>00093       slot = 0;
<a name="l00094"></a>00094       <span class="keywordflow">while</span> (slot &lt; allocator-&gt;n_allocated_slots)
<a name="l00095"></a>00095         {
<a name="l00096"></a>00096           <span class="keywordflow">if</span> (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> &lt; 0)
<a name="l00097"></a>00097             {
<a name="l00098"></a>00098               allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> = slot;
<a name="l00099"></a>00099               allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> = 1;
<a name="l00100"></a>00100               allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a> += 1;
<a name="l00101"></a>00101               <span class="keywordflow">break</span>;
<a name="l00102"></a>00102             }
<a name="l00103"></a>00103           ++slot;
<a name="l00104"></a>00104         }
<a name="l00105"></a>00105 
<a name="l00106"></a>00106       _dbus_assert (slot &lt; allocator-&gt;n_allocated_slots);
<a name="l00107"></a>00107     }
<a name="l00108"></a>00108   <span class="keywordflow">else</span>
<a name="l00109"></a>00109     {
<a name="l00110"></a>00110       <a class="code" href="structDBusAllocatedSlot.html" title="An allocated slot for storing data.">DBusAllocatedSlot</a> *tmp;
<a name="l00111"></a>00111       
<a name="l00112"></a>00112       slot = -1;
<a name="l00113"></a>00113       tmp = <a class="code" href="group__DBusMemory.html#ga2d505f2960ccf343042d363170b27f9c" title="Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_realloc</a> (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>,
<a name="l00114"></a>00114                           sizeof (<a class="code" href="structDBusAllocatedSlot.html" title="An allocated slot for storing data.">DBusAllocatedSlot</a>) * (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a> + 1));
<a name="l00115"></a>00115       <span class="keywordflow">if</span> (tmp == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00116"></a>00116         <span class="keywordflow">goto</span> out;
<a name="l00117"></a>00117 
<a name="l00118"></a>00118       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a> = tmp;
<a name="l00119"></a>00119       slot = allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a>;
<a name="l00120"></a>00120       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a> += 1;
<a name="l00121"></a>00121       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a> += 1;
<a name="l00122"></a>00122       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> = slot;
<a name="l00123"></a>00123       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> = 1;
<a name="l00124"></a>00124     }
<a name="l00125"></a>00125 
<a name="l00126"></a>00126   _dbus_assert (slot &gt;= 0);
<a name="l00127"></a>00127   _dbus_assert (slot &lt; allocator-&gt;n_allocated_slots);
<a name="l00128"></a>00128   _dbus_assert (*slot_id_p &lt; 0);
<a name="l00129"></a>00129   _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> == slot);
<a name="l00130"></a>00130   _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> == 1);
<a name="l00131"></a>00131   
<a name="l00132"></a>00132   *slot_id_p = slot;
<a name="l00133"></a>00133   
<a name="l00134"></a>00134   _dbus_verbose (<span class="stringliteral">&quot;Allocated slot %d on allocator %p total %d slots allocated %d used\n&quot;</span>,
<a name="l00135"></a>00135                  slot, allocator, allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a>, allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a>);
<a name="l00136"></a>00136   
<a name="l00137"></a>00137  out:
<a name="l00138"></a>00138   _dbus_unlock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>);
<a name="l00139"></a>00139   <span class="keywordflow">return</span> slot &gt;= 0;
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00153"></a>00153 <span class="keywordtype">void</span>
<a name="l00154"></a><a class="code" href="group__DBusDataSlot.html#ga059c50a24cd9fc984e918e6159841633">00154</a> <a class="code" href="group__DBusDataSlot.html#ga059c50a24cd9fc984e918e6159841633" title="Deallocates an ID previously allocated with _dbus_data_slot_allocator_alloc().">_dbus_data_slot_allocator_free</a> (<a class="code" href="structDBusDataSlotAllocator.html" title="An allocator that tracks a set of slot IDs.">DBusDataSlotAllocator</a> *allocator,
<a name="l00155"></a>00155                                 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>          *slot_id_p)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157   <span class="keywordflow">if</span> (!_dbus_lock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>))
<a name="l00158"></a>00158     _dbus_assert_not_reached (<span class="stringliteral">&quot;we should have initialized global locks &quot;</span>
<a name="l00159"></a>00159         <span class="stringliteral">&quot;before we allocated this slot&quot;</span>);
<a name="l00160"></a>00160 
<a name="l00161"></a>00161   _dbus_assert (*slot_id_p &lt; allocator-&gt;n_allocated_slots);
<a name="l00162"></a>00162   _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> == *slot_id_p);
<a name="l00163"></a>00163   _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> &gt; 0);
<a name="l00164"></a>00164 
<a name="l00165"></a>00165   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> -= 1;
<a name="l00166"></a>00166 
<a name="l00167"></a>00167   <span class="keywordflow">if</span> (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#a554eaffc3334a90a86f618eaa713410c" title="Number of uses of the slot.">refcount</a> &gt; 0)
<a name="l00168"></a>00168     {
<a name="l00169"></a>00169       _dbus_unlock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>);
<a name="l00170"></a>00170       <span class="keywordflow">return</span>;
<a name="l00171"></a>00171     }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173   <span class="comment">/* refcount is 0, free the slot */</span>
<a name="l00174"></a>00174   _dbus_verbose (<span class="stringliteral">&quot;Freeing slot %d on allocator %p total %d allocated %d used\n&quot;</span>,
<a name="l00175"></a>00175                  *slot_id_p, allocator, allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a>, allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a>);
<a name="l00176"></a>00176   
<a name="l00177"></a>00177   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[*slot_id_p].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> = -1;
<a name="l00178"></a>00178   *slot_id_p = -1;
<a name="l00179"></a>00179   
<a name="l00180"></a>00180   allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a> -= 1;
<a name="l00181"></a>00181   
<a name="l00182"></a>00182   <span class="keywordflow">if</span> (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#ad68b0989a821eb266983052f8a402a4a" title="number of slots used">n_used_slots</a> == 0)
<a name="l00183"></a>00183     {
<a name="l00184"></a>00184       <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>);
<a name="l00185"></a>00185       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00186"></a>00186       allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a57702eaf2d6558cc15f12205aca90dda" title="number of slots malloc&#39;d">n_allocated_slots</a> = 0;
<a name="l00187"></a>00187     }
<a name="l00188"></a>00188 
<a name="l00189"></a>00189   _dbus_unlock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>);
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 
<a name="l00196"></a>00196 <span class="keywordtype">void</span>
<a name="l00197"></a><a class="code" href="group__DBusDataSlot.html#ga6de49b3a1210202215d40a5a19806992">00197</a> <a class="code" href="group__DBusDataSlot.html#ga6de49b3a1210202215d40a5a19806992" title="Initializes a slot list.">_dbus_data_slot_list_init</a> (<a class="code" href="structDBusDataSlotList.html" title="Data structure that stores the actual user data set at a given slot.">DBusDataSlotList</a> *list)
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199   list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00200"></a>00200   list-&gt;<a class="code" href="structDBusDataSlotList.html#a2d6cb7670a940bc886c99cb892b44502" title="Slots we have storage for in data_slots.">n_slots</a> = 0;
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202 
<a name="l00220"></a>00220 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00221"></a><a class="code" href="group__DBusDataSlot.html#gad2952f9f686d96e7114fc49ab7452e1a">00221</a> <a class="code" href="group__DBusDataSlot.html#gad2952f9f686d96e7114fc49ab7452e1a" title="Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...">_dbus_data_slot_list_set</a>  (<a class="code" href="structDBusDataSlotAllocator.html" title="An allocator that tracks a set of slot IDs.">DBusDataSlotAllocator</a> *allocator,
<a name="l00222"></a>00222                            <a class="code" href="structDBusDataSlotList.html" title="Data structure that stores the actual user data set at a given slot.">DBusDataSlotList</a>      *list,
<a name="l00223"></a>00223                            <span class="keywordtype">int</span>                    slot,
<a name="l00224"></a>00224                            <span class="keywordtype">void</span>                  *data,
<a name="l00225"></a>00225                            <a class="code" href="group__DBusMemory.html#ga061bcded226d76c7d7de35beaa165cb5" title="The type of a function which frees a block of memory.">DBusFreeFunction</a>       free_data_func,
<a name="l00226"></a>00226                            <a class="code" href="group__DBusMemory.html#ga061bcded226d76c7d7de35beaa165cb5" title="The type of a function which frees a block of memory.">DBusFreeFunction</a>      *old_free_func,
<a name="l00227"></a>00227                            <span class="keywordtype">void</span>                 **old_data)
<a name="l00228"></a>00228 {
<a name="l00229"></a>00229 <span class="preprocessor">#ifndef DBUS_DISABLE_ASSERT</span>
<a name="l00230"></a>00230 <span class="preprocessor"></span>  <span class="comment">/* We need to take the allocator lock here, because the allocator could</span>
<a name="l00231"></a>00231 <span class="comment">   * be e.g. realloc()ing allocated_slots. We avoid doing this if asserts</span>
<a name="l00232"></a>00232 <span class="comment">   * are disabled, since then the asserts are empty.</span>
<a name="l00233"></a>00233 <span class="comment">   */</span>
<a name="l00234"></a>00234   <span class="keywordflow">if</span> (!_dbus_lock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>))
<a name="l00235"></a>00235     _dbus_assert_not_reached (<span class="stringliteral">&quot;we should have initialized global locks &quot;</span>
<a name="l00236"></a>00236         <span class="stringliteral">&quot;before we allocated this slot&quot;</span>);
<a name="l00237"></a>00237 
<a name="l00238"></a>00238   _dbus_assert (slot &lt; allocator-&gt;n_allocated_slots);
<a name="l00239"></a>00239   _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> == slot);
<a name="l00240"></a>00240   _dbus_unlock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>);
<a name="l00241"></a>00241 <span class="preprocessor">#endif</span>
<a name="l00242"></a>00242 <span class="preprocessor"></span>  
<a name="l00243"></a>00243   <span class="keywordflow">if</span> (slot &gt;= list-&gt;<a class="code" href="structDBusDataSlotList.html#a2d6cb7670a940bc886c99cb892b44502" title="Slots we have storage for in data_slots.">n_slots</a>)
<a name="l00244"></a>00244     {
<a name="l00245"></a>00245       <a class="code" href="structDBusDataSlot.html" title="DBusDataSlot is used to store application data on the connection.">DBusDataSlot</a> *tmp;
<a name="l00246"></a>00246       <span class="keywordtype">int</span> i;
<a name="l00247"></a>00247       
<a name="l00248"></a>00248       tmp = <a class="code" href="group__DBusMemory.html#ga2d505f2960ccf343042d363170b27f9c" title="Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_realloc</a> (list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>,
<a name="l00249"></a>00249                           sizeof (<a class="code" href="structDBusDataSlot.html" title="DBusDataSlot is used to store application data on the connection.">DBusDataSlot</a>) * (slot + 1));
<a name="l00250"></a>00250       <span class="keywordflow">if</span> (tmp == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00251"></a>00251         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00252"></a>00252       
<a name="l00253"></a>00253       list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a> = tmp;
<a name="l00254"></a>00254       i = list-&gt;<a class="code" href="structDBusDataSlotList.html#a2d6cb7670a940bc886c99cb892b44502" title="Slots we have storage for in data_slots.">n_slots</a>;
<a name="l00255"></a>00255       list-&gt;<a class="code" href="structDBusDataSlotList.html#a2d6cb7670a940bc886c99cb892b44502" title="Slots we have storage for in data_slots.">n_slots</a> = slot + 1;
<a name="l00256"></a>00256       <span class="keywordflow">while</span> (i &lt; list-&gt;n_slots)
<a name="l00257"></a>00257         {
<a name="l00258"></a>00258           list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#a883c8c8946f13b6f5f3cf99f230159fd" title="The application data.">data</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00259"></a>00259           list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#ab899f58869942556fb1b381ca3f3e2b2" title="Free the application data.">free_data_func</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00260"></a>00260           ++i;
<a name="l00261"></a>00261         }
<a name="l00262"></a>00262     }
<a name="l00263"></a>00263 
<a name="l00264"></a>00264   _dbus_assert (slot &lt; list-&gt;n_slots);
<a name="l00265"></a>00265 
<a name="l00266"></a>00266   *old_data = list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#a883c8c8946f13b6f5f3cf99f230159fd" title="The application data.">data</a>;
<a name="l00267"></a>00267   *old_free_func = list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#ab899f58869942556fb1b381ca3f3e2b2" title="Free the application data.">free_data_func</a>;
<a name="l00268"></a>00268 
<a name="l00269"></a>00269   list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#a883c8c8946f13b6f5f3cf99f230159fd" title="The application data.">data</a> = data;
<a name="l00270"></a>00270   list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#ab899f58869942556fb1b381ca3f3e2b2" title="Free the application data.">free_data_func</a> = free_data_func;
<a name="l00271"></a>00271 
<a name="l00272"></a>00272   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00273"></a>00273 }
<a name="l00274"></a>00274 
<a name="l00284"></a>00284 <span class="keywordtype">void</span>*
<a name="l00285"></a><a class="code" href="group__DBusDataSlot.html#ga43f741229f0c38788442601e2750ec66">00285</a> <a class="code" href="group__DBusDataSlot.html#ga43f741229f0c38788442601e2750ec66" title="Retrieves data previously set with _dbus_data_slot_list_set_data().">_dbus_data_slot_list_get</a>  (<a class="code" href="structDBusDataSlotAllocator.html" title="An allocator that tracks a set of slot IDs.">DBusDataSlotAllocator</a> *allocator,
<a name="l00286"></a>00286                            <a class="code" href="structDBusDataSlotList.html" title="Data structure that stores the actual user data set at a given slot.">DBusDataSlotList</a>      *list,
<a name="l00287"></a>00287                            <span class="keywordtype">int</span>                    slot)
<a name="l00288"></a>00288 {
<a name="l00289"></a>00289 <span class="preprocessor">#ifndef DBUS_DISABLE_ASSERT</span>
<a name="l00290"></a>00290 <span class="preprocessor"></span>  <span class="comment">/* We need to take the allocator lock here, because the allocator could</span>
<a name="l00291"></a>00291 <span class="comment">   * be e.g. realloc()ing allocated_slots. We avoid doing this if asserts</span>
<a name="l00292"></a>00292 <span class="comment">   * are disabled, since then the asserts are empty.</span>
<a name="l00293"></a>00293 <span class="comment">   */</span>
<a name="l00294"></a>00294   <span class="keywordflow">if</span> (!_dbus_lock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>))
<a name="l00295"></a>00295     _dbus_assert_not_reached (<span class="stringliteral">&quot;we should have initialized global locks &quot;</span>
<a name="l00296"></a>00296         <span class="stringliteral">&quot;before we allocated this slot&quot;</span>);
<a name="l00297"></a>00297 
<a name="l00298"></a>00298   _dbus_assert (slot &gt;= 0);
<a name="l00299"></a>00299   _dbus_assert (slot &lt; allocator-&gt;n_allocated_slots);
<a name="l00300"></a>00300   _dbus_assert (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a290fc1a48efc181da4e54dae572306b5" title="Allocated slots.">allocated_slots</a>[slot].<a class="code" href="structDBusAllocatedSlot.html#a849e5f8d951d159c45172ce825fb3a1e" title="ID of this slot.">slot_id</a> == slot);
<a name="l00301"></a>00301   _dbus_unlock (allocator-&gt;<a class="code" href="structDBusDataSlotAllocator.html#a5908a6f2e17e5feec5b77a2cfbc81dbd" title="index of thread lock">lock</a>);
<a name="l00302"></a>00302 <span class="preprocessor">#endif</span>
<a name="l00303"></a>00303 <span class="preprocessor"></span>
<a name="l00304"></a>00304   <span class="keywordflow">if</span> (slot &gt;= list-&gt;<a class="code" href="structDBusDataSlotList.html#a2d6cb7670a940bc886c99cb892b44502" title="Slots we have storage for in data_slots.">n_slots</a>)
<a name="l00305"></a>00305     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00306"></a>00306   <span class="keywordflow">else</span>
<a name="l00307"></a>00307     <span class="keywordflow">return</span> list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[slot].<a class="code" href="structDBusDataSlot.html#a883c8c8946f13b6f5f3cf99f230159fd" title="The application data.">data</a>;
<a name="l00308"></a>00308 }
<a name="l00309"></a>00309 
<a name="l00316"></a>00316 <span class="keywordtype">void</span>
<a name="l00317"></a><a class="code" href="group__DBusDataSlot.html#ga3c96d2ca263ba397b4da2956a49ae282">00317</a> <a class="code" href="group__DBusDataSlot.html#ga3c96d2ca263ba397b4da2956a49ae282" title="Frees all data slots contained in the list, calling application-provided free functions if they exist...">_dbus_data_slot_list_clear</a> (<a class="code" href="structDBusDataSlotList.html" title="Data structure that stores the actual user data set at a given slot.">DBusDataSlotList</a> *list)
<a name="l00318"></a>00318 {
<a name="l00319"></a>00319   <span class="keywordtype">int</span> i;
<a name="l00320"></a>00320 
<a name="l00321"></a>00321   i = 0;
<a name="l00322"></a>00322   <span class="keywordflow">while</span> (i &lt; list-&gt;n_slots)
<a name="l00323"></a>00323     {
<a name="l00324"></a>00324       <span class="keywordflow">if</span> (list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#ab899f58869942556fb1b381ca3f3e2b2" title="Free the application data.">free_data_func</a>)
<a name="l00325"></a>00325         (* list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#ab899f58869942556fb1b381ca3f3e2b2" title="Free the application data.">free_data_func</a>) (list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#a883c8c8946f13b6f5f3cf99f230159fd" title="The application data.">data</a>);
<a name="l00326"></a>00326       list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#a883c8c8946f13b6f5f3cf99f230159fd" title="The application data.">data</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00327"></a>00327       list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>[i].<a class="code" href="structDBusDataSlot.html#ab899f58869942556fb1b381ca3f3e2b2" title="Free the application data.">free_data_func</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00328"></a>00328       ++i;
<a name="l00329"></a>00329     }
<a name="l00330"></a>00330 }
<a name="l00331"></a>00331 
<a name="l00339"></a>00339 <span class="keywordtype">void</span>
<a name="l00340"></a><a class="code" href="group__DBusDataSlot.html#gabc399733376c462c3010271a2d431e73">00340</a> <a class="code" href="group__DBusDataSlot.html#gabc399733376c462c3010271a2d431e73" title="Frees the data slot list and all data slots contained in it, calling application-provided free functi...">_dbus_data_slot_list_free</a> (<a class="code" href="structDBusDataSlotList.html" title="Data structure that stores the actual user data set at a given slot.">DBusDataSlotList</a> *list)
<a name="l00341"></a>00341 {
<a name="l00342"></a>00342   <a class="code" href="group__DBusDataSlot.html#ga3c96d2ca263ba397b4da2956a49ae282" title="Frees all data slots contained in the list, calling application-provided free functions if they exist...">_dbus_data_slot_list_clear</a> (list);
<a name="l00343"></a>00343   
<a name="l00344"></a>00344   <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a>);
<a name="l00345"></a>00345   list-&gt;<a class="code" href="structDBusDataSlotList.html#a4dd0fc6cc10b9c48dd53f34335abd08e" title="Data slots.">slots</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00346"></a>00346   list-&gt;<a class="code" href="structDBusDataSlotList.html#a2d6cb7670a940bc886c99cb892b44502" title="Slots we have storage for in data_slots.">n_slots</a> = 0;
<a name="l00347"></a>00347 }
<a name="l00348"></a>00348 
<a name="l00351"></a>00351 <span class="preprocessor">#ifdef DBUS_ENABLE_EMBEDDED_TESTS</span>
<a name="l00352"></a>00352 <span class="preprocessor"></span><span class="preprocessor">#include &quot;dbus-test.h&quot;</span>
<a name="l00353"></a>00353 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00354"></a>00354 
<a name="l00355"></a>00355 <span class="keyword">static</span> <span class="keywordtype">int</span> free_counter;
<a name="l00356"></a>00356 
<a name="l00357"></a>00357 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00358"></a>00358 test_free_slot_data_func (<span class="keywordtype">void</span> *data)
<a name="l00359"></a>00359 {
<a name="l00360"></a>00360   <span class="keywordtype">int</span> i = _DBUS_POINTER_TO_INT (data);
<a name="l00361"></a>00361 
<a name="l00362"></a>00362   _dbus_assert (free_counter == i);
<a name="l00363"></a>00363   ++free_counter;
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365 
<a name="l00369"></a>00369 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00370"></a>00370 _dbus_data_slot_test (<span class="keywordtype">void</span>)
<a name="l00371"></a>00371 {
<a name="l00372"></a>00372   <a class="code" href="structDBusDataSlotAllocator.html" title="An allocator that tracks a set of slot IDs.">DBusDataSlotAllocator</a> allocator;
<a name="l00373"></a>00373   <a class="code" href="structDBusDataSlotList.html" title="Data structure that stores the actual user data set at a given slot.">DBusDataSlotList</a> list;
<a name="l00374"></a>00374   <span class="keywordtype">int</span> i;
<a name="l00375"></a>00375   <a class="code" href="group__DBusMemory.html#ga061bcded226d76c7d7de35beaa165cb5" title="The type of a function which frees a block of memory.">DBusFreeFunction</a> old_free_func;
<a name="l00376"></a>00376   <span class="keywordtype">void</span> *old_data;
<a name="l00377"></a>00377 
<a name="l00378"></a>00378   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusDataSlot.html#ga49236838eb414100f691a22ad5210cb5" title="Initializes a data slot allocator object, used to assign integer IDs for data slots.">_dbus_data_slot_allocator_init</a> (&amp;allocator, _DBUS_LOCK_server_slots))
<a name="l00379"></a>00379     _dbus_assert_not_reached (<span class="stringliteral">&quot;no memory for allocator&quot;</span>);
<a name="l00380"></a>00380 
<a name="l00381"></a>00381   <a class="code" href="group__DBusDataSlot.html#ga6de49b3a1210202215d40a5a19806992" title="Initializes a slot list.">_dbus_data_slot_list_init</a> (&amp;list);
<a name="l00382"></a>00382 
<a name="l00383"></a>00383 <span class="preprocessor">#define N_SLOTS 100</span>
<a name="l00384"></a>00384 <span class="preprocessor"></span>
<a name="l00385"></a>00385   i = 0;
<a name="l00386"></a>00386   <span class="keywordflow">while</span> (i &lt; N_SLOTS)
<a name="l00387"></a>00387     {
<a name="l00388"></a>00388       <span class="comment">/* we don&#39;t really want apps to rely on this ordered</span>
<a name="l00389"></a>00389 <span class="comment">       * allocation, but it simplifies things to rely on it</span>
<a name="l00390"></a>00390 <span class="comment">       * here.</span>
<a name="l00391"></a>00391 <span class="comment">       */</span>
<a name="l00392"></a>00392       <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a> tmp = -1;
<a name="l00393"></a>00393 
<a name="l00394"></a>00394       <a class="code" href="group__DBusDataSlot.html#gaf61f2bd0148bace4f67a2d6d97b26ea9" title="Allocates an integer ID to be used for storing data in a DBusDataSlotList.">_dbus_data_slot_allocator_alloc</a> (&amp;allocator, &amp;tmp);
<a name="l00395"></a>00395 
<a name="l00396"></a>00396       <span class="keywordflow">if</span> (tmp != i)
<a name="l00397"></a>00397         _dbus_assert_not_reached (<span class="stringliteral">&quot;did not allocate slots in numeric order\n&quot;</span>);
<a name="l00398"></a>00398 
<a name="l00399"></a>00399       ++i;
<a name="l00400"></a>00400     }
<a name="l00401"></a>00401 
<a name="l00402"></a>00402   i = 0;
<a name="l00403"></a>00403   <span class="keywordflow">while</span> (i &lt; N_SLOTS)
<a name="l00404"></a>00404     {
<a name="l00405"></a>00405       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusDataSlot.html#gad2952f9f686d96e7114fc49ab7452e1a" title="Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...">_dbus_data_slot_list_set</a> (&amp;allocator, &amp;list,
<a name="l00406"></a>00406                                      i,
<a name="l00407"></a>00407                                      _DBUS_INT_TO_POINTER (i), 
<a name="l00408"></a>00408                                      test_free_slot_data_func,
<a name="l00409"></a>00409                                      &amp;old_free_func, &amp;old_data))
<a name="l00410"></a>00410         _dbus_assert_not_reached (<span class="stringliteral">&quot;no memory to set data&quot;</span>);
<a name="l00411"></a>00411 
<a name="l00412"></a>00412       _dbus_assert (old_free_func == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00413"></a>00413       _dbus_assert (old_data == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00414"></a>00414 
<a name="l00415"></a>00415       _dbus_assert (<a class="code" href="group__DBusDataSlot.html#ga43f741229f0c38788442601e2750ec66" title="Retrieves data previously set with _dbus_data_slot_list_set_data().">_dbus_data_slot_list_get</a> (&amp;allocator, &amp;list, i) ==
<a name="l00416"></a>00416                     _DBUS_INT_TO_POINTER (i));
<a name="l00417"></a>00417       
<a name="l00418"></a>00418       ++i;
<a name="l00419"></a>00419     }
<a name="l00420"></a>00420 
<a name="l00421"></a>00421   free_counter = 0;
<a name="l00422"></a>00422   i = 0;
<a name="l00423"></a>00423   <span class="keywordflow">while</span> (i &lt; N_SLOTS)
<a name="l00424"></a>00424     {
<a name="l00425"></a>00425       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusDataSlot.html#gad2952f9f686d96e7114fc49ab7452e1a" title="Stores a pointer in the data slot list, along with an optional function to be used for freeing the da...">_dbus_data_slot_list_set</a> (&amp;allocator, &amp;list,
<a name="l00426"></a>00426                                      i,
<a name="l00427"></a>00427                                      _DBUS_INT_TO_POINTER (i), 
<a name="l00428"></a>00428                                      test_free_slot_data_func,
<a name="l00429"></a>00429                                      &amp;old_free_func, &amp;old_data))
<a name="l00430"></a>00430         _dbus_assert_not_reached (<span class="stringliteral">&quot;no memory to set data&quot;</span>);
<a name="l00431"></a>00431 
<a name="l00432"></a>00432       _dbus_assert (old_free_func == test_free_slot_data_func);
<a name="l00433"></a>00433       _dbus_assert (_DBUS_POINTER_TO_INT (old_data) == i);
<a name="l00434"></a>00434 
<a name="l00435"></a>00435       (* old_free_func) (old_data);
<a name="l00436"></a>00436       _dbus_assert (i == (free_counter - 1));
<a name="l00437"></a>00437 
<a name="l00438"></a>00438       _dbus_assert (<a class="code" href="group__DBusDataSlot.html#ga43f741229f0c38788442601e2750ec66" title="Retrieves data previously set with _dbus_data_slot_list_set_data().">_dbus_data_slot_list_get</a> (&amp;allocator, &amp;list, i) ==
<a name="l00439"></a>00439                     _DBUS_INT_TO_POINTER (i));
<a name="l00440"></a>00440       
<a name="l00441"></a>00441       ++i;
<a name="l00442"></a>00442     }
<a name="l00443"></a>00443 
<a name="l00444"></a>00444   free_counter = 0;
<a name="l00445"></a>00445   <a class="code" href="group__DBusDataSlot.html#gabc399733376c462c3010271a2d431e73" title="Frees the data slot list and all data slots contained in it, calling application-provided free functi...">_dbus_data_slot_list_free</a> (&amp;list);
<a name="l00446"></a>00446 
<a name="l00447"></a>00447   _dbus_assert (N_SLOTS == free_counter);
<a name="l00448"></a>00448 
<a name="l00449"></a>00449   i = 0;
<a name="l00450"></a>00450   <span class="keywordflow">while</span> (i &lt; N_SLOTS)
<a name="l00451"></a>00451     {
<a name="l00452"></a>00452       <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a> tmp = i;
<a name="l00453"></a>00453       
<a name="l00454"></a>00454       <a class="code" href="group__DBusDataSlot.html#ga059c50a24cd9fc984e918e6159841633" title="Deallocates an ID previously allocated with _dbus_data_slot_allocator_alloc().">_dbus_data_slot_allocator_free</a> (&amp;allocator, &amp;tmp);
<a name="l00455"></a>00455       _dbus_assert (tmp == -1);
<a name="l00456"></a>00456       ++i;
<a name="l00457"></a>00457     }
<a name="l00458"></a>00458 
<a name="l00459"></a>00459   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00460"></a>00460 }
<a name="l00461"></a>00461 
<a name="l00462"></a>00462 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_ENABLE_EMBEDDED_TESTS */</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Thu Mar 3 2016 17:50:30 for D-Bus by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>