summaryrefslogtreecommitdiff
path: root/apps/drwho/Protocol_Manager.cpp
blob: 238956108937952236e5053986a3870c127b7db4 (plain)
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
// $Id$
#include "Options.h"
#include "new.h"
#include "Protocol_Manager.h"

// Returns a pointer to the Drwho_Node associated with HOST_NAME (if
// it exists, otherwise a new node is created.  Note that if a
// Drwho_Node is found it is moved to the front of the list so that
// subsequent finds are faster (i.e., self-organizing!)
     
Drwho_Node *
Protocol_Manager::get_drwho_node (char *key_name, Drwho_Node *&head)
{
  for (Drwho_Node **temp = &head;
       *temp != 0;
       temp = &(*temp)->next_)
    if (ACE_OS::strcmp (key_name,
                        (*temp)->get_login_name ()) == 0)
      break;
  
  if (*temp == 0)
    ACE_NEW_RETURN (head,
                    Drwho_Node (key_name, head),
                    0);
  else
    {
      Drwho_Node *t = *temp;
      
      *temp = (*temp)->next_;
      t->next_ = head;

      head = t;
    }

  return head;
}

Protocol_Manager::Protocol_Manager (void)
  : total_users (0)
{
}

Protocol_Manager::~Protocol_Manager (void)
{
  if (Options::get_opt (Options::DEBUG))
    ACE_DEBUG ((LM_DEBUG,
                "disposing Protocol_Manager\n"));
}

// Returns the next friend in the sequence of sorted friends.

Protocol_Record *
Protocol_Manager::get_next_friend (void)
{
  return this->ss->get_next_entry ();
}

Protocol_Record *
Protocol_Manager::get_each_friend (void)
{
  return this->ss->get_each_entry ();
}

// Returns the number of friends.

int
Protocol_Manager::friend_count (void)
{
  return this->ss->n_elems ();
}

// Returns total number of users logged in throughout the system.

int 
Protocol_Manager::get_total_users (void)
{
  return Protocol_Manager::total_users;
}

void			
Protocol_Manager::increment_total_users (int remote_users)
{
  Protocol_Manager::total_users += remote_users;
}