~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/protocol.h

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_PLUGIN_CLIENT_H
21
 
#define DRIZZLED_PLUGIN_CLIENT_H
 
20
#ifndef DRIZZLED_PLUGIN_PROTOCOL_H
 
21
#define DRIZZLED_PLUGIN_PROTOCOL_H
22
22
 
23
 
#include <drizzled/catalog/instance.h>
24
 
#include <drizzled/catalog/local.h>
25
 
#include <drizzled/error_t.h>
 
23
#include <drizzled/sql_list.h>
26
24
#include <drizzled/item.h>
27
 
#include <drizzled/sql_list.h>
28
 
 
29
 
#include "drizzled/visibility.h"
30
 
 
31
 
namespace drizzled
32
 
{
 
25
 
33
26
class Session;
34
27
class String;
35
28
 
 
29
namespace drizzled
 
30
{
36
31
namespace plugin
37
32
{
38
33
 
39
 
/**
40
 
 * This class allows new client sources to be written. This could be through
41
 
 * network protocols, in-process threads, or any other client source that can
42
 
 * provide commands and handle result sets. The current implementation is
43
 
 * file-descriptor based, so for non-fd client sources (like from another
44
 
 * thread), derived classes will need to use a pipe() for event notifications.
45
 
 */
46
 
class DRIZZLED_API Client
 
34
class Protocol
47
35
{
48
36
protected:
49
37
  Session *session;
50
38
 
51
39
public:
52
 
  virtual ~Client() {}
53
 
 
54
 
  /**
55
 
   * Get attached session from the client object.
56
 
   * @retval Session object that is attached, NULL if none.
57
 
   */
 
40
  Protocol() {}
 
41
  virtual ~Protocol() {}
 
42
 
 
43
  virtual void setSession(Session *session_arg)
 
44
  {
 
45
    session= session_arg;
 
46
  }
 
47
 
58
48
  virtual Session *getSession(void)
59
49
  {
60
50
    return session;
61
51
  }
62
52
 
63
 
  /**
64
 
   * Attach session to the client object.
65
 
   * @param[in] session_arg Session object to attach, or NULL to clear.
66
 
   */
67
 
  virtual void setSession(Session *session_arg)
68
 
  {
69
 
    session= session_arg;
70
 
  }
71
 
 
72
 
  /**
73
 
   * Get file descriptor associated with client object.
74
 
   * @retval File descriptor that is attached, -1 if none.
75
 
   */
76
 
  virtual int getFileDescriptor(void)= 0;
77
 
 
78
 
  /**
79
 
   * Check to see if the client is currently connected.
80
 
   * @retval Boolean value representing connected state.
81
 
   */
82
 
  virtual bool isConnected(void)= 0;
83
 
 
84
 
  /**
85
 
   * Check to see if the client is actively reading.
86
 
   * @retval Boolean value representing reading state.
87
 
   */
 
53
  virtual bool isConnected()= 0;
 
54
  virtual void setError(char error)= 0;
 
55
  virtual bool haveError(void)= 0;
 
56
  virtual bool wasAborted(void)= 0;
 
57
  virtual bool haveMoreData(void)= 0;
88
58
  virtual bool isReading(void)= 0;
89
 
 
90
 
  /**
91
 
   * Check to see if the client is actively writing.
92
 
   * @retval Boolean value representing writing state.
93
 
   */
94
59
  virtual bool isWriting(void)= 0;
95
 
 
96
 
  /**
97
 
   * Flush all data that has been buffered with store() methods.
98
 
   * @retval Boolean indicating success or failure.
99
 
   */
100
 
  virtual bool flush(void)= 0;
101
 
 
102
 
  /**
103
 
   * Close the client object.
104
 
   */
105
 
  virtual void close(void)= 0;
106
 
 
107
 
  /**
108
 
   * Perform handshake and authorize client if needed.
109
 
   */
110
 
  virtual bool authenticate(void)= 0;
111
 
 
112
 
  virtual bool isConsole()
113
 
  {
114
 
    return false;
115
 
  }
116
 
 
117
 
  virtual catalog::Instance::shared_ptr catalog()
118
 
  {
119
 
    return catalog::local();
120
 
  }
121
 
 
122
 
  /**
123
 
   * Read command from client.
124
 
   */
125
 
  virtual bool readCommand(char **packet, uint32_t *packet_length)= 0;
126
 
 
127
 
  /* Send responses. */
128
 
  virtual void sendOK(void)= 0;
129
 
  virtual void sendEOF(void)= 0;
130
 
  virtual void sendError(const drizzled::error_t sql_errno, const char *err)= 0;
131
 
 
132
 
  /**
133
 
   * Send field list for result set.
134
 
   */
 
60
  virtual bool setFileDescriptor(int fd)=0;
 
61
  virtual int fileDescriptor(void)=0;
 
62
  virtual bool authenticate(void)=0;
 
63
  virtual bool readCommand(char **packet, uint32_t *packet_length)=0;
 
64
  virtual void sendOK()= 0;
 
65
  virtual void sendEOF()= 0;
 
66
  virtual void sendError(uint32_t sql_errno, const char *err)=0;
 
67
  virtual void close()= 0;
 
68
  virtual void forceClose()= 0;
 
69
  virtual void prepareForResend()= 0;
 
70
  virtual void free()= 0;
 
71
  virtual bool write()= 0;
 
72
 
135
73
  virtual bool sendFields(List<Item> *list)= 0;
136
74
 
137
 
  /* Send result fields in various forms. */
138
75
  virtual bool store(Field *from)= 0;
139
76
  virtual bool store(void)= 0;
140
77
  virtual bool store(int32_t from)= 0;
142
79
  virtual bool store(int64_t from)= 0;
143
80
  virtual bool store(uint64_t from)= 0;
144
81
  virtual bool store(double from, uint32_t decimals, String *buffer)= 0;
145
 
  virtual bool store(const type::Time *from);
146
 
  virtual bool store(const char *from);
 
82
  virtual bool store(const DRIZZLE_TIME *from)= 0;
 
83
  virtual bool store(const char *from)
 
84
  {
 
85
    if (from == NULL) 
 
86
      return store();
 
87
    return store(from, strlen(from));
 
88
  }
147
89
  virtual bool store(const char *from, size_t length)= 0;
148
 
  virtual bool store(const std::string &from)
149
 
  {
150
 
    return store(from.c_str(), from.size());
151
 
  }
152
 
 
153
 
  /* Try to remove these. */
154
 
  virtual bool haveMoreData(void)= 0;
155
 
  virtual bool haveError(void)= 0;
156
 
  virtual bool wasAborted(void)= 0;
157
 
 
158
90
};
159
91
 
160
 
} /* namespace plugin */
161
 
} /* namespace drizzled */
 
92
} /* end namespace drizzled::plugin */
 
93
} /* end namespace drizzled */
162
94
 
163
 
#endif /* DRIZZLED_PLUGIN_CLIENT_H */
 
95
#endif /* DRIZZLED_PLUGIN_PROTOCOL_H */