1 /* 2 Copyright (c) 2003, 2021, Oracle and/or its affiliates. 3 4 All rights reserved. Use is subject to license terms. 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, version 2.0, 8 as published by the Free Software Foundation. 9 10 This program is also distributed with certain software (including 11 but not limited to OpenSSL) that is licensed under separate terms, 12 as designated in a particular file or component or in included license 13 documentation. The authors of MySQL hereby grant you an additional 14 permission to link the program and your derivative works with the 15 separately licensed software that they have included with MySQL. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License, version 2.0, for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 */ 26 27 #ifndef __CPCCLIENT_HPP_INCLUDED__ 28 #define __CPCCLIENT_HPP_INCLUDED__ 29 30 #include <Parser.hpp> 31 #include <SocketServer.hpp> 32 #include <util/InputStream.hpp> 33 #include <util/OutputStream.hpp> 34 35 /* 36 Simple CPC client class. 37 */ 38 class SimpleCpcClient { 39 public: 40 SimpleCpcClient(const char *host, int port); 41 ~SimpleCpcClient(); 42 getPort() const43 int getPort() const { return port;} getHost() const44 const char * getHost() const { return host;} 45 46 struct Process { 47 int m_id; 48 BaseString m_name; 49 50 BaseString m_owner; 51 BaseString m_group; 52 BaseString m_runas; 53 54 BaseString m_cwd; 55 BaseString m_env; 56 BaseString m_path; 57 BaseString m_args; 58 59 BaseString m_type; 60 BaseString m_status; 61 62 BaseString m_stdin; 63 BaseString m_stdout; 64 BaseString m_stderr; 65 BaseString m_ulimit; 66 BaseString m_shutdown_options; 67 }; 68 69 private: 70 class ParserDummy : SocketServer::Session { 71 public: 72 ParserDummy(NDB_SOCKET_TYPE sock); 73 }; 74 75 typedef Parser<ParserDummy> Parser_t; 76 typedef ParserRow<ParserDummy> ParserRow_t; 77 78 char *host; 79 int port; 80 NDB_SOCKET_TYPE cpc_sock; 81 82 public: 83 int connect(); 84 int list_processes(Vector<Process>&, Properties &reply); 85 int start_process(Uint32 id, Properties& reply); 86 int stop_process(Uint32 id, Properties& reply); 87 int undefine_process(Uint32 id, Properties& reply); 88 int define_process(Process & p, Properties& reply); 89 90 private: 91 int cpc_send(const char *cmd, 92 const Properties &args); 93 94 95 Parser_t::ParserStatus cpc_recv(const ParserRow_t *syntax, 96 const Properties **reply, 97 void **user_data = NULL); 98 99 const Properties *cpc_call(const char *cmd, 100 const Properties &args, 101 const ParserRow_t *reply_syntax); 102 }; 103 104 #endif /* !__CPCCLIENT_HPP_INCLUDED__ */ 105