Portable_Group_Map.cpp

Go to the documentation of this file.
00001 // Portable_Group_Map.cpp,v 1.18 2006/03/14 06:14:34 jtc Exp
00002 
00003 #include "orbsvcs/PortableGroup/Portable_Group_Map.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/TAO_Server_Request.h"
00006 #include "tao/CDR.h"
00007 
00008 ACE_RCSID (PortableGroup,
00009            Portable_Group_Map,
00010            "Portable_Group_Map.cpp,v 1.18 2006/03/14 06:14:34 jtc Exp")
00011 
00012 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00013 
00014 /// Constructor.
00015 TAO_Portable_Group_Map::TAO_Portable_Group_Map ()
00016 {
00017 }
00018 
00019 /// Destructor.
00020 TAO_Portable_Group_Map::~TAO_Portable_Group_Map (void)
00021 {
00022   for (Iterator i = this->map_.begin ();
00023        i != this->map_.end ();
00024        ++i)
00025     {
00026       // Deallocate the id.
00027       delete (*i).ext_id_;
00028 
00029       // Delete the chain of Map_Entries.
00030       Map_Entry *entry = (*i).int_id_;
00031       while (entry)
00032         {
00033           Map_Entry *next = entry->next;
00034           delete entry;
00035           entry = next;
00036         }
00037 
00038     }
00039 
00040   this->map_.close ();
00041 }
00042 
00043 
00044 void
00045 TAO_Portable_Group_Map::add_groupid_objectkey_pair (
00046     PortableGroup::TagGroupTaggedComponent *group_id,
00047     const TAO::ObjectKey &key
00048     ACE_ENV_ARG_DECL
00049   )
00050 {
00051   ACE_GUARD (TAO_SYNCH_MUTEX,
00052              guard,
00053              this->lock_);
00054 
00055   Map_Entry *new_entry;
00056 
00057   // We take ownership of the group_id memory.  Be sure we don't
00058   // forget about it.
00059   PortableGroup::TagGroupTaggedComponent_var safe_group = group_id;
00060 
00061   ACE_NEW_THROW_EX (new_entry,
00062                     Map_Entry (),
00063                     CORBA::NO_MEMORY (
00064                                       CORBA::SystemException::_tao_minor_code (
00065                                                                                TAO::VMCID,
00066                                                                                ENOMEM),
00067                                       CORBA::COMPLETED_NO));
00068   ACE_CHECK;
00069 
00070   // Fill out the entry.
00071   new_entry->key = key;
00072 
00073   // First, check if the GroupId is already in the map.
00074   Map_Entry *entry;
00075   if (this->map_.find (group_id,
00076                        entry) == 0)
00077     {
00078       // Add the object key to the list of object keys serviced by this GroupId.
00079       new_entry->next = entry->next;
00080       entry->next = new_entry;
00081     }
00082   else
00083     {
00084       new_entry->next = 0;
00085 
00086       // Add the
00087       int result =
00088         this->map_.bind (group_id,
00089                          new_entry);
00090 
00091       if (result != 0)
00092         {
00093           delete new_entry;
00094           ACE_THROW (CORBA::INTERNAL ());
00095         }
00096 
00097       // Transfer ownership of group_id to the map.
00098       (void) safe_group._retn ();
00099     }
00100 }
00101 
00102 void
00103 TAO_Portable_Group_Map::remove_groupid_objectkey_pair (const PortableGroup::TagGroupTaggedComponent* /*group_id*/,
00104                                                        const TAO::ObjectKey &/*key*/
00105                                                        ACE_ENV_ARG_DECL_NOT_USED)
00106 {
00107 
00108 }
00109 
00110 
00111 void
00112 TAO_Portable_Group_Map::dispatch (PortableGroup::TagGroupTaggedComponent* group_id,
00113                                   TAO_ORB_Core *orb_core,
00114                                   TAO_ServerRequest &request,
00115                                   CORBA::Object_out forward_to
00116                                   ACE_ENV_ARG_DECL)
00117 {
00118   ACE_GUARD (TAO_SYNCH_MUTEX,
00119              guard,
00120              this->lock_);
00121 
00122   // Look up the GroupId.
00123   Map_Entry *entry = 0;
00124   if (this->map_.find (group_id,
00125                        entry) == 0)
00126     {
00127 
00128       // Save the read pointer in the message block since
00129       // every time we dispatch the request, we need to
00130       // reset it so that the request demarshals correctly.
00131       TAO_InputCDR *tao_in = request.incoming ();
00132       ACE_Message_Block *msgblk =
00133           const_cast<ACE_Message_Block *> (tao_in->start ());
00134       char *read_ptr = msgblk->rd_ptr ();
00135 
00136       // Iterate through the list of ObjectKeys.
00137       while (entry)
00138         {
00139           orb_core->adapter_registry ()->dispatch (entry->key,
00140                                                    request,
00141                                                    forward_to
00142                                                    ACE_ENV_ARG_PARAMETER);
00143           ACE_CHECK;
00144 
00145           // Reset the read pointer in the message block.
00146           msgblk->rd_ptr (read_ptr);
00147           entry = entry->next;
00148         }
00149     }
00150 }
00151 
00152 u_long
00153 TAO_GroupId_Hash::operator () (const PortableGroup::TagGroupTaggedComponent *id) const
00154 {
00155   u_long hash =
00156     ACE::hash_pjw ((const char *) id->group_domain_id,
00157                    ACE_OS::strlen ((const char *) id->group_domain_id));
00158 
00159   // Truncate the object_group_id in half for the has.
00160   // Divide by one so that the ACE_U_LongLong representation
00161   // will automatically cast down to a u_long
00162   hash += (u_long) (id->object_group_id / 1);
00163 
00164   hash += id->object_group_ref_version;
00165 
00166   return hash;
00167 }
00168 
00169 int
00170 TAO_GroupId_Equal_To::operator () (
00171   const PortableGroup::TagGroupTaggedComponent *lhs,
00172   const PortableGroup::TagGroupTaggedComponent *rhs) const
00173 {
00174   return
00175     ACE_OS::strcmp (lhs->group_domain_id, rhs->group_domain_id) == 0
00176     && lhs->object_group_id == rhs->object_group_id
00177     && lhs->object_group_ref_version == rhs->object_group_ref_version;
00178 }
00179 
00180 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 14:03:34 2006 for TAO_PortableGroup by doxygen 1.3.6