~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/protocol.h

Reverted my change to interval_list

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
23
#include <drizzled/sql_list.h>
24
24
#include <drizzled/item.h>
25
25
 
26
 
namespace drizzled
27
 
{
28
26
class Session;
29
27
class String;
30
28
 
31
 
namespace plugin
32
 
{
33
 
 
34
 
/**
35
 
 * This class allows new client sources to be written. This could be through
36
 
 * network protocols, in-process threads, or any other client source that can
37
 
 * provide commands and handle result sets. The current implementation is
38
 
 * file-descriptor based, so for non-fd client sources (like from another
39
 
 * thread), derived classes will need to use a pipe() for event notifications.
40
 
 */
41
 
class Client
 
29
class Protocol
42
30
{
43
31
protected:
44
32
  Session *session;
45
33
 
46
34
public:
47
 
  virtual ~Client() {}
48
 
 
49
 
  /**
50
 
   * Get attached session from the client object.
51
 
   * @retval Session object that is attached, NULL if none.
52
 
   */
 
35
  Protocol() {}
 
36
  virtual ~Protocol() {}
 
37
 
 
38
  virtual void setSession(Session *session_arg)
 
39
  {
 
40
    session= session_arg;
 
41
  }
 
42
 
53
43
  virtual Session *getSession(void)
54
44
  {
55
45
    return session;
56
46
  }
57
47
 
58
 
  /**
59
 
   * Attach session to the client object.
60
 
   * @param[in] session_arg Session object to attach, or NULL to clear.
61
 
   */
62
 
  virtual void setSession(Session *session_arg)
63
 
  {
64
 
    session= session_arg;
65
 
  }
66
 
 
67
 
  /**
68
 
   * Get file descriptor associated with client object.
69
 
   * @retval File descriptor that is attached, -1 if none.
70
 
   */
71
 
  virtual int getFileDescriptor(void)= 0;
72
 
 
73
 
  /**
74
 
   * Check to see if the client is currently connected.
75
 
   * @retval Boolean value representing connected state.
76
 
   */
77
 
  virtual bool isConnected(void)= 0;
78
 
 
79
 
  /**
80
 
   * Check to see if the client is actively reading.
81
 
   * @retval Boolean value representing reading state.
82
 
   */
 
48
  virtual bool isConnected()= 0;
 
49
  virtual void setReadTimeout(uint32_t timeout)= 0;
 
50
  virtual void setWriteTimeout(uint32_t timeout)= 0;
 
51
  virtual void setRetryCount(uint32_t count)= 0;
 
52
  virtual void setError(char error)= 0;
 
53
  virtual bool haveError(void)= 0;
 
54
  virtual bool wasAborted(void)= 0;
 
55
  virtual void enableCompression(void)= 0;
 
56
  virtual bool haveMoreData(void)= 0;
83
57
  virtual bool isReading(void)= 0;
84
 
 
85
 
  /**
86
 
   * Check to see if the client is actively writing.
87
 
   * @retval Boolean value representing writing state.
88
 
   */
89
58
  virtual bool isWriting(void)= 0;
90
 
 
91
 
  /**
92
 
   * Flush all data that has been buffered with store() methods.
93
 
   * @retval Boolean indicating success or failure.
94
 
   */
95
 
  virtual bool flush(void)= 0;
96
 
 
97
 
  /**
98
 
   * Close the client object.
99
 
   */
100
 
  virtual void close(void)= 0;
101
 
 
102
 
  /**
103
 
   * Perform handshake and authorize client if needed.
104
 
   */
105
 
  virtual bool authenticate(void)= 0;
106
 
 
107
 
  /**
108
 
   * Read command from client.
109
 
   */
110
 
  virtual bool readCommand(char **packet, uint32_t *packet_length)= 0;
111
 
 
112
 
  /* Send responses. */
113
 
  virtual void sendOK(void)= 0;
114
 
  virtual void sendEOF(void)= 0;
115
 
  virtual void sendError(uint32_t sql_errno, const char *err)= 0;
116
 
 
117
 
  /**
118
 
   * Send field list for result set.
119
 
   */
120
 
  virtual bool sendFields(List<Item> *list)= 0;
121
 
 
122
 
  /* Send result fields in various forms. */
 
59
  virtual bool setFileDescriptor(int fd)=0;
 
60
  virtual int fileDescriptor(void)=0;
 
61
  virtual void setRandom(uint64_t, uint64_t) {};
 
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
 
 
73
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
 
74
  virtual bool sendFields(List<Item> *list, uint32_t flags)= 0;
 
75
 
123
76
  virtual bool store(Field *from)= 0;
124
77
  virtual bool store(void)= 0;
125
78
  virtual bool store(int32_t from)= 0;
127
80
  virtual bool store(int64_t from)= 0;
128
81
  virtual bool store(uint64_t from)= 0;
129
82
  virtual bool store(double from, uint32_t decimals, String *buffer)= 0;
130
 
  virtual bool store(const DRIZZLE_TIME *from);
131
 
  virtual bool store(const char *from);
 
83
  virtual bool store(const DRIZZLE_TIME *from)= 0;
 
84
  virtual bool store(const char *from)
 
85
  {
 
86
    if (from == NULL) 
 
87
      return store();
 
88
    return store(from, strlen(from));
 
89
  }
132
90
  virtual bool store(const char *from, size_t length)= 0;
133
 
  virtual bool store(const std::string &from)
134
 
  {
135
 
    return store(from.c_str(), from.size());
136
 
  }
137
 
 
138
 
  /* Try to remove these. */
139
 
  virtual bool haveMoreData(void)= 0;
140
 
  virtual bool haveError(void)= 0;
141
 
  virtual bool wasAborted(void)= 0;
142
 
 
143
91
};
144
92
 
145
 
} /* namespace plugin */
146
 
} /* namespace drizzled */
147
 
 
148
 
#endif /* DRIZZLED_PLUGIN_CLIENT_H */
 
93
#endif /* DRIZZLED_PLUGIN_PROTOCOL_H */