summaryrefslogtreecommitdiff
path: root/apps/drwho/Protocol_Manager.h
blob: 705a1e81657300ae7aa16da202c5708c11aec7cb (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
85
86
/* -*- C++ -*- */
// $Id$

/* A base class that consolidates friend management functionality
   shared by both clients and servers. */ 

#ifndef _FRIEND_MANAGER_H
#define _FRIEND_MANAGER_H

#include "ace/OS.h"
#include "Options.h"
#include "Search_Struct.h"
#include "Protocol_Record.h"

class Protocol_Manager
{
protected:
  int                   	total_users;
  Search_Struct			*ss;

  int				friend_count (void);

  Drwho_Node			*get_drwho_node (char *host_name, Drwho_Node *&head);
  int				get_total_users (void);
  void				increment_total_users (int remote_users = 1);

  Protocol_Record		*get_next_friend (void);
  Protocol_Record		*get_each_friend (void);

  virtual Protocol_Record 	*insert_protocol_info (Protocol_Record &protocol_record) = 0;

public:
	                	Protocol_Manager (void);
  virtual			~Protocol_Manager (void);

  virtual int			encode (char *packet, int &total_bytes) = 0;
  virtual int			decode (char *packet, int &total_bytes) = 0;
};

#ifdef __OPTIMIZE__
inline 
Protocol_Manager::Protocol_Manager (void): total_users (0)
{}

inline
Protocol_Manager::~Protocol_Manager (void)
{
  if (Options::DEBUG)
    fprintf (stderr, "disposing Protocol_Manager\n");
}

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

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

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

/* Returns the number of friends. */

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

inline int 
Protocol_Manager::get_total_users (void)
{
  return this->total_users;
}

inline void			
Protocol_Manager::increment_total_users (int remote_users)
{
  this->total_users += remote_users;
}
#endif /* __OPTIMIZE__ */
#endif /* _FRIEND_MANAGER_H */