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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/*
Copyright (c) 2022 Sogou, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __SRPC_CONTROLLER__
#define __SRPC_CONTROLLER__
#include "srpc_config.h"
class CommandController
{
public:
bool parse_args(int argc, const char **argv);
virtual bool dependencies_and_dir();
virtual bool copy_files();
virtual void print_success_info() const;
virtual void print_usage(const char *name) const = 0;
protected:
virtual bool check_args();
private:
virtual bool get_opt(int argc, const char **argv) = 0;
public:
CommandController() { }
virtual ~CommandController() { }
using transform_function_t = bool (*)(const std::string&, FILE *,
const struct srpc_config *);
struct file_info
{
std::string in_file;
std::string out_file;
transform_function_t transform;
};
protected:
std::vector<struct file_info> default_files;
struct srpc_config config;
protected:
bool get_path(const char *file, char *path, int depth);
bool copy_single_file(const std::string& in_file,
const std::string& out_file,
transform_function_t transform);
void fill_rpc_default_files();
};
class HttpController : public CommandController
{
public:
void print_usage(const char *name) const override;
private:
bool get_opt(int argc, const char **argv) override;
public:
HttpController();
~HttpController() { }
};
class RedisController : public CommandController
{
public:
void print_usage(const char *name) const override;
private:
bool get_opt(int argc, const char **argv) override;
public:
RedisController();
~RedisController() { }
};
class RPCController : public CommandController
{
public:
void print_usage(const char *name) const override;
bool copy_files() override;
protected:
bool check_args() override;
private:
bool get_opt(int argc, const char **argv) override;
public:
RPCController();
~RPCController() { }
};
class APIController : public CommandController
{
public:
bool dependencies_and_dir() override;
void print_usage(const char *name) const override;
void print_success_info() const override;
protected:
bool check_args() override { return true; }
private:
bool get_opt(int argc, const char **argv) override;
public:
APIController();
~APIController() { }
};
class ProxyController : public CommandController
{
public:
void print_usage(const char *name) const override;
void print_success_info() const override;
bool copy_files() override;
protected:
bool check_args() override;
private:
bool get_opt(int argc, const char **argv) override;
public:
ProxyController();
~ProxyController() { }
};
class FileServiceController : public CommandController
{
public:
void print_usage(const char *name) const override;
void print_success_info() const override;
private:
bool get_opt(int argc, const char **argv) override;
public:
FileServiceController();
~FileServiceController() { }
};
class ComputeController : public CommandController
{
public:
void print_usage(const char *name) const override;
void print_success_info() const override;
private:
bool get_opt(int argc, const char **argv) override;
public:
ComputeController();
~ComputeController() { }
};
////////// common functions //////////
int mkdir_p(const char *name, mode_t mode);
////////// common transform functions //////////
bool common_cmake_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool basic_client_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool basic_server_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool basic_client_config_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool basic_server_config_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool rpc_idl_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool rpc_client_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool rpc_server_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
bool rpc_cmake_transform(const std::string& format, FILE *out,
const struct srpc_config *config);
#endif
|