NCBI C++ ToolKit
srv_connections.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CONNECT_SERVICES__SERVER_CONN_HPP_1
2 #define CONNECT_SERVICES__SERVER_CONN_HPP_1
3 
4 /* $Id: srv_connections.hpp 90665 2020-07-09 16:46:23Z sadyrovr $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Maxim Didneko, Dmitry Kazimirov
30  *
31  * File Description:
32  *
33  */
34 
35 #include "util.hpp"
36 
38 #include <connect/ncbi_socket.hpp>
39 
41 #include <corelib/ncbi_config.hpp>
42 
43 
45 
46 struct SNetServerImpl; ///< @internal
47 struct SNetServerConnectionImpl; ///< @internal
48 struct SNetServerInfoImpl; ///< @internal
49 struct SNetServerMultilineCmdOutputImpl; ///< @internal
50 struct INetServerConnectionListener; ///< @internal
51 
52 ///////////////////////////////////////////////////////////////////////////
53 //
55 {
56  NCBI_NET_COMPONENT(NetServerConnection);
57 
58  /// Execute remote command 'cmd', wait for the reply,
59  /// check that it starts with 'OK:', and return the
60  /// remaining characters of the reply as a string.
61  string Exec(const string& cmd,
62  bool multiline_output = false,
63  const STimeout* timeout = NULL);
64 };
65 
66 
67 ///////////////////////////////////////////////////////////////////////////
68 //
70 {
71 public:
72  virtual void Close() = 0;
73  virtual void Abort() = 0;
74 };
75 
76 ///////////////////////////////////////////////////////////////////////////
77 //
79 {
80 };
81 
82 ///////////////////////////////////////////////////////////////////////////
83 //
85 {
86  NCBI_NET_COMPONENT(NetServerInfo);
87 
88  /// Return the next attribute. If there are no more attributes,
89  /// the method returns false, and attr_name and attr_value are
90  /// left unchanged.
91  bool GetNextAttribute(string& attr_name, string& attr_value);
92 };
93 
95 CNetServerInfo g_ServerInfoFromString(const string& server_info);
96 
97 ///////////////////////////////////////////////////////////////////////////
98 //
100 {
101  NCBI_NET_COMPONENT(NetServer);
102 
103  const SSocketAddress& GetAddress() const;
104 
105  // Shortcuts
106  unsigned GetHost() const { return GetAddress().host; }
107  unsigned short GetPort() const { return GetAddress().port; }
108  string GetServerAddress() const { return GetAddress().AsString(); }
109 
110  struct SExecResult {
111  string response;
113  };
114 
115  /// Execute remote command 'cmd', wait for the reply,
116  /// check if it starts with 'OK:', and return the
117  /// remaining characters of the reply as a string.
118  /// This method makes as many as TServConn_ConnMaxRetries
119  /// attempts to connect to the server and execute
120  /// the specified command.
121  SExecResult ExecWithRetry(const string& cmd,
122  bool multiline_output = false);
123 
124  /// Retrieve basic information about the server as
125  /// attribute name-value pairs.
126  CNetServerInfo GetServerInfo();
127 };
128 
129 ///////////////////////////////////////////////////////////////////////////
130 //
132 {
133  NCBI_NET_COMPONENT(NetServerMultilineCmdOutput);
134 
136 
137  bool ReadLine(string& output);
138 };
139 
140 #ifdef HAVE_LIBCONNEXT
141 #define NCBI_GRID_XSITE_CONN_SUPPORT 1
142 #endif
143 
144 
146 
147 #endif // CONNECT_SERVICES__SERVER_CONN_HPP
unsigned short GetPort() const
string GetServerAddress() const
unsigned GetHost() const
virtual void Close()=0
virtual void Abort()=0
A very basic data-read interface.
A very basic data-write interface.
Abstract reader-writer interface classes.
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static SQLCHAR output[256]
Definition: print.c:5
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XCONNECT_EXPORT
Parameters initialization model.
#define NCBI_NET_COMPONENT(component)
string ReadLine(CNcbiIstream &in)
Definition: phrap.cpp:74
CNetServerInfo g_ServerInfoFromString(const string &server_info)
CNetServerConnection conn
Timeout structure.
Definition: ncbi_types.h:76
Modified on Tue May 21 10:57:47 2024 by modify_doxy.py rev. 669887