~drizzle-trunk/drizzle/development

971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
21
2318.3.4 by Olaf van der Spek
Refactor
22
#include <boost/foreach.hpp>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <drizzled/plugin/plugin.h>
24
#include <drizzled/atomics.h>
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
25
#include <vector>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
26
#include <drizzled/visibility.h>
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
27
2252.1.22 by Olaf van der Spek
Common fwd
28
namespace drizzled {
29
namespace plugin {
971.3.65 by Eric Day
Namespace cleanup for Protocol and Listen.
30
2131.7.1 by Andrew Hutchings
Add protocol counters table
31
typedef std::vector<Listen *> ListenVector;
32
typedef std::pair<std::string*, drizzled::atomic<uint64_t>*> ListenCounter;
971.3.51 by Eric Day
Finished up new Listen plugin interface.
33
/**
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
34
 * This class is used by client plugins to provide and manage the listening
35
 * interface for new client instances.
971.3.51 by Eric Day
Finished up new Listen plugin interface.
36
 */
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
37
class DRIZZLED_API Listen : public Plugin
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
38
{
2131.7.1 by Andrew Hutchings
Add protocol counters table
39
protected:
40
  std::vector<ListenCounter*> counters;
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
41
public:
1192.2.5 by Monty Taylor
Replaced overridable virtual methods with passing name to constructor. Now individual plugins will not be allowed to set their own plugin type name. :)
42
  explicit Listen(std::string name_arg)
43
    : Plugin(name_arg, "Listen")
44
  {}
2318.3.4 by Olaf van der Spek
Refactor
45
2131.7.6 by Andrew Hutchings
Fix counters cleanup
46
  virtual ~Listen()
47
  {
2318.3.4 by Olaf van der Spek
Refactor
48
    BOOST_FOREACH(ListenCounter* counter, counters)
2131.7.6 by Andrew Hutchings
Fix counters cleanup
49
    {
50
      delete counter->first;
51
      delete counter;
52
    }
53
  }
971.3.51 by Eric Day
Finished up new Listen plugin interface.
54
2131.7.1 by Andrew Hutchings
Add protocol counters table
55
  static ListenVector &getListenProtocols();
56
2131.7.5 by Andrew Hutchings
Fix compile error in Solaris
57
  std::vector<ListenCounter*>& getListenCounters()
2131.7.1 by Andrew Hutchings
Add protocol counters table
58
  {
59
    return counters;
60
  }
971.3.51 by Eric Day
Finished up new Listen plugin interface.
61
  /**
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
62
   * This provides a list of file descriptors to watch that will trigger new
63
   * Client instances. When activity is detected on one of the returned file
64
   * descriptors, getClient will be called with the file descriptor.
65
   * @fds[out] Vector of file descriptors to watch for activity.
66
   * @retval true on failure, false on success.
971.3.51 by Eric Day
Finished up new Listen plugin interface.
67
   */
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
68
  virtual bool getFileDescriptors(std::vector<int> &fds)= 0;
971.3.51 by Eric Day
Finished up new Listen plugin interface.
69
70
  /**
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
71
   * This provides a new Client object that can be used by a Session.
971.6.7 by Eric Day
Reworked listen interface to not require binding of TCP ports.
72
   * @param[in] fd File descriptor that had activity.
971.3.51 by Eric Day
Finished up new Listen plugin interface.
73
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
74
  virtual plugin::Client *getClient(int fd)= 0;
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
75
76
  /**
77
   * Add a new Listen object to the list of listeners we manage.
78
   */
2318.3.4 by Olaf van der Spek
Refactor
79
  static bool addPlugin(Listen*);
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
80
81
  /**
82
   * Remove a Listen object from the list of listeners we manage.
83
   */
2318.3.4 by Olaf van der Spek
Refactor
84
  static void removePlugin(Listen*);
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
85
86
  /**
87
   * Setup all configured listen plugins.
88
   */
89
  static bool setup(void);
90
91
  /**
92
   * Accept a new connection (Client object) on one of the configured
93
   * listener interfaces.
94
   */
2318.3.4 by Olaf van der Spek
Refactor
95
  static plugin::Client *getClient();
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
96
97
  /**
98
   * Some internal functions drizzled require a temporary Client object to
99
   * create a valid session object, this just returns a dummy client object.
100
   */
2318.3.4 by Olaf van der Spek
Refactor
101
  static plugin::Client *getNullClient();
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
102
103
  /**
104
   * Shutdown and cleanup listen loop for server shutdown.
105
   */
2318.3.4 by Olaf van der Spek
Refactor
106
  static void shutdown();
1192.2.2 by Monty Taylor
Added type name strings to all of the plugin types.
107
971.3.48 by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup.
108
};
109
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
110
} /* namespace plugin */
2131.7.1 by Andrew Hutchings
Add protocol counters table
111
1130.1.12 by Monty Taylor
Moved service stuff into plugin/
112
} /* namespace drizzled */
971.3.65 by Eric Day
Namespace cleanup for Protocol and Listen.
113