session_event.h 1.6 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2021/4/13.
//

羽飞's avatar
羽飞 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16 17 18 19 20

#include <string.h>
#include <string>

#include "common/seda/stage_event.h"
羽飞's avatar
羽飞 已提交
21
#include "sql/executor/sql_result.h"
羽飞's avatar
羽飞 已提交
22

W
wangyunlai.wyl 已提交
23
class Session;
羽飞's avatar
羽飞 已提交
24 25
class Communicator;
class SqlResult;
W
wangyunlai.wyl 已提交
26

羽飞's avatar
羽飞 已提交
27 28
class SessionEvent : public common::StageEvent {
public:
羽飞's avatar
羽飞 已提交
29
  SessionEvent(Communicator *client);
羽飞's avatar
羽飞 已提交
30 31
  virtual ~SessionEvent();

羽飞's avatar
羽飞 已提交
32
  Communicator *get_communicator() const;
W
wangyunlai.wyl 已提交
33
  Session *session() const;
羽飞's avatar
羽飞 已提交
34

羽飞's avatar
羽飞 已提交
35 36 37 38 39
  void set_query(const std::string &query) { query_ = query; }
  void set_sql_result(SqlResult *result) { sql_result_ = result; }
  const std::string &query() const { return query_; }
  SqlResult *sql_result() const { return sql_result_; }

羽飞's avatar
羽飞 已提交
40 41 42 43 44
  const char *get_response() const;
  void set_response(const char *response);
  void set_response(const char *response, int len);
  void set_response(std::string &&response);
  int get_response_len() const;
羽飞's avatar
羽飞 已提交
45
  const char *get_request_buf(); // TODO remove me
羽飞's avatar
羽飞 已提交
46 47

private:
羽飞's avatar
羽飞 已提交
48 49
  Communicator *communicator_ = nullptr;
  SqlResult *sql_result_ = nullptr;
羽飞's avatar
羽飞 已提交
50

羽飞's avatar
羽飞 已提交
51
  std::string query_;
羽飞's avatar
羽飞 已提交
52 53
  std::string response_;
};