Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / apps / drwho / BS_Client.cpp
blob3c671b591c75334f9ee9564d18e691eee6d4b9c9
1 #include "Options.h"
2 #include "File_Manager.h"
3 #include "BS_Client.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/Null_Mutex.h"
6 #include "ace/OS_NS_string.h"
8 BS_Client::BS_Client ()
10 this->count_ = FILE_MANAGER::instance ()->open_file (Options::friend_file);
12 if (this->count_ < 0)
13 ACE_ERROR ((LM_ERROR,
14 "%p\n",
15 Options::program_name));
16 else
18 ACE_NEW (this->protocol_record_,
19 Protocol_Record[this->count_]);
20 ACE_NEW (this->sorted_record_,
21 Protocol_Record *[this->count_]);
23 for (int i = 0; i < this->count_; i++)
25 Protocol_Record *prp = &this->protocol_record_[i];
27 this->sorted_record_[i] = prp;
29 FILE_MANAGER::instance ()->get_login_and_real_name
30 (prp->key_name1_, prp->key_name2_);
33 ACE_OS::qsort (this->sorted_record_,
34 this->count_,
35 sizeof *this->sorted_record_,
36 (ACE_COMPARE_FUNC)Binary_Search::name_compare);
40 // This function is used to merge the KEY_NAME from server HOST_NAME
41 // into the sorted list of userids kept on the client's side. Since
42 // we *know* we are going to find the name we use the traditional
43 // binary search.
45 Protocol_Record *
46 BS_Client::insert (const char *key_name, int)
48 #if 0
49 Protocol_Record *pr = (Protocol_Record *)
50 ACE_OS::bsearch ((const void *) key_name,
51 (const void *) this->sorted_record_,
52 this->count_,
53 sizeof ...,
54 int (*compar)(const void *, const void *) ACE_OS::strcmp);
55 return pr;
56 #else
57 int lo = 0;
58 int hi = this->count_ - 1;
59 Protocol_Record **sorted_buffer = this->sorted_record_;
61 while (lo <= hi)
63 int mid = (lo + hi) / 2;
64 Protocol_Record *prp = sorted_buffer[mid];
65 int cmp = ACE_OS::strcmp (key_name,
66 prp->get_login ());
67 if (cmp == 0)
68 return prp;
69 else if (cmp < 0)
70 hi = mid - 1;
71 else
72 lo = mid + 1;
75 return 0;
76 #endif /* 0 */
79 Protocol_Record *
80 BS_Client::get_each_entry ()
82 for (Protocol_Record *prp = Binary_Search::get_each_entry ();
83 prp != 0;
84 prp = Binary_Search::get_each_entry ())
85 if (prp->get_drwho_list () != 0)
86 return prp;
88 return 0;