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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS_DATA_LOADERS_CDD_CDD_ACCESS__CDD_CLIENT__HPP
2 #define OBJTOOLS_DATA_LOADERS_CDD_CDD_ACCESS__CDD_CLIENT__HPP
3 
4 /* $Id: cdd_client.hpp 101499 2023-12-20 18:12:03Z grichenk $
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  * Author: Aleksey Grichenko
30  *
31  * File Description:
32  * RPC client for CDD annotations
33  *
34  */
35 
38 #include <serial/rpcbase.hpp>
40 
42 
43 BEGIN_objects_SCOPE // namespace ncbi::objects::
44 
45 #define DEFAULT_CDD_SERVICE_NAME "getCddSeqAnnot"
46 #define DEFAULT_CDD_POOL_SOFT_LIMIT 10
47 #define DEFAULT_CDD_POOL_AGE_LIMIT 900
48 #define DEFAULT_CDD_EXCLUDE_NUCLEOTIDES true
49 
50 
51 class CSeq_id;
52 class CID2_Blob_Id;
53 
54 class NCBI_CDD_ACCESS_EXPORT CCDDClient : public CRPCClient<CCDD_Request_Packet, CCDD_Reply>
55 {
57 public:
58  /// Serial data format for requests and replies
59  enum EDataFormat {
60  eDefaultFormat, ///< Determined by [CCddClient] data_format
61  eJSON, ///< Bidirectional JSON
62  eSemiBinary, ///< JSON requests, binary ASN.1 replies
63  eBinary ///< Bidirectional binary ASN.1
64  };
65 
66  // constructor
67  CCDDClient(const string& service_name = kEmptyStr,
68  EDataFormat data_format = eDefaultFormat);
69  // destructor
70  ~CCDDClient(void);
71 
73  typedef vector< CConstRef<CCDD_Reply> > TReplies;
74 
75  virtual void Ask(const CCDD_Request_Packet& request, CCDD_Reply& reply);
76 
77  virtual void WriteRequest(CObjectOStream& out,
78  const CCDD_Request_Packet& request);
79 
80  virtual void ReadReply(CObjectIStream& in, CCDD_Reply& reply);
81 
82  const TReplies& GetReplies(void) { return m_Replies; }
83 
84  // Shortcut method for fetching a single blob-id.
85  CRef<CCDD_Reply> AskBlobId(int serial_number, const CSeq_id& seq_id);
86 
87  // Shortcut method for fetching a single blob.
88  CRef<CCDD_Reply> AskBlob(int serial_number, const CID2_Blob_Id& blob_id);
89 
90  void JustAsk(const CCDD_Request_Packet& request);
91  void JustFetch(CCDD_Reply& reply)
92  { ReadReply(*m_In, reply); }
93 
94 
95 private:
96  // Prohibit copy constructor and assignment operator
99 
102 };
103 
104 
105 class CCDDBlobCache;
106 
108 {
109 public:
110  CCDDClientPool(const string& service_name = DEFAULT_CDD_SERVICE_NAME,
111  size_t pool_soft_limit = DEFAULT_CDD_POOL_SOFT_LIMIT,
112  time_t pool_age_limit = DEFAULT_CDD_POOL_AGE_LIMIT,
113  bool exclude_nucleotides = DEFAULT_CDD_EXCLUDE_NUCLEOTIDES);
114  ~CCDDClientPool(void);
115 
120 
121  struct SCDDBlob {
124  };
125  typedef SCDDBlob TBlob;
126 
127  SCDDBlob GetBlobBySeq_id(CSeq_id_Handle idh);
128  SCDDBlob GetBlobBySeq_ids(const TSeq_idSet& ids);
129  TBlobInfo GetBlobIdBySeq_id(CSeq_id_Handle idh);
130  TBlobData GetBlobByBlobId(const TBlobId& blob_id);
131 
132  bool IsValidId(const CSeq_id& id);
133 
134  void SetClientTimeout(CTimeout timeout) { m_ClientTimeout = timeout; }
135 
136  static string BlobIdToString(const TBlobId& blob_id);
137  static CRef<TBlobId> StringToBlobId(const string& s);
138 
139 private:
141  typedef TClientPool::iterator TClient;
142  friend class CCDDClientGuard;
143 
144  TClient x_GetClient();
145  void x_ReleaseClient(TClient& client);
146  void x_DiscardClient(TClient& client);
147  bool x_CheckReply(CRef<CCDD_Reply>& reply, int serial, CCDD_Reply::TReply::E_Choice choice);
148  TBlobData x_RequestBlobData(const TBlobId& blob_id);
149 
150  static int x_NextSerialNumber(void);
151 
156  // bool m_Compress;
160  unique_ptr<CCDDBlobCache> m_Cache;
162 };
163 
165 {
166 public:
167  enum EErrCode {
168  eClientError, // Communication error
169  eReplyError, // Error in CDD reply
170  eOtherError
171  };
172  virtual const char* GetErrCodeString(void) const override;
174 };
175 
176 END_objects_SCOPE // namespace ncbi::objects::
177 
179 
180 
181 #endif // OBJTOOLS_DATA_LOADERS_CDD_CDD_ACCESS__CDD_CLIENT__HPP
User-defined methods of the data storage class.
User-defined methods of the data storage class.
#define DEFAULT_CDD_POOL_AGE_LIMIT
Definition: cdd_client.hpp:47
#define DEFAULT_CDD_POOL_SOFT_LIMIT
Definition: cdd_client.hpp:46
#define DEFAULT_CDD_SERVICE_NAME
Definition: cdd_client.hpp:45
#define DEFAULT_CDD_EXCLUDE_NUCLEOTIDES
Definition: cdd_client.hpp:48
NCBI_EXCEPTION_DEFAULT(CCDDClientException, CException)
size_t m_PoolSoftLimit
Definition: cdd_client.hpp:153
SCDDBlob TBlob
Definition: cdd_client.hpp:125
string m_ServiceName
Definition: cdd_client.hpp:152
set< CSeq_id_Handle > TSeq_idSet
Definition: cdd_client.hpp:116
CID2_Blob_Id TBlobId
Definition: cdd_client.hpp:117
TClientPool m_NotInUse
Definition: cdd_client.hpp:159
CRef< CCDD_Reply_Get_Blob_Id > TBlobInfo
Definition: cdd_client.hpp:118
TClientPool m_InUse
Definition: cdd_client.hpp:158
CRef< CSeq_annot > TBlobData
Definition: cdd_client.hpp:119
CTimeout m_ClientTimeout
Definition: cdd_client.hpp:161
unique_ptr< CCDDBlobCache > m_Cache
Definition: cdd_client.hpp:160
multimap< time_t, CRef< CCDDClient > > TClientPool
Definition: cdd_client.hpp:140
TClientPool::iterator TClient
Definition: cdd_client.hpp:141
bool m_ExcludeNucleotides
Definition: cdd_client.hpp:155
CFastMutex m_PoolLock
Definition: cdd_client.hpp:157
void SetClientTimeout(CTimeout timeout)
Definition: cdd_client.hpp:134
time_t m_PoolAgeLimit
Definition: cdd_client.hpp:154
EDataFormat m_DataFormat
Definition: cdd_client.hpp:101
CCDD_Request_Packet TRequests
Definition: cdd_client.hpp:72
EDataFormat
Serial data format for requests and replies.
Definition: cdd_client.hpp:59
@ eSemiBinary
JSON requests, binary ASN.1 replies.
Definition: cdd_client.hpp:62
@ eDefaultFormat
Determined by [CCddClient] data_format.
Definition: cdd_client.hpp:60
@ eJSON
Bidirectional JSON.
Definition: cdd_client.hpp:61
TReplies m_Replies
Definition: cdd_client.hpp:100
vector< CConstRef< CCDD_Reply > > TReplies
Definition: cdd_client.hpp:73
CCDDClient(const CCDDClient &value)
CRPCClient< CCDD_Request_Packet, CCDD_Reply > Tparent
Definition: cdd_client.hpp:56
void JustFetch(CCDD_Reply &reply)
Definition: cdd_client.hpp:91
CCDDClient & operator=(const CCDDClient &value)
const TReplies & GetReplies(void)
Definition: cdd_client.hpp:82
CCDD_Reply –.
Definition: CDD_Reply.hpp:66
CCDD_Request_Packet –.
CFastMutex –.
Definition: ncbimtx.hpp:667
CID2_Blob_Id –.
Definition: ID2_Blob_Id.hpp:66
CObjectIStream –.
Definition: objistr.hpp:93
CObjectOStream –.
Definition: objostr.hpp:83
CObject –.
Definition: ncbiobj.hpp:180
CRPCClient – prototype client for ASN.1/XML-based RPC.
Definition: rpcbase.hpp:63
CRef –.
Definition: ncbiobj.hpp:618
CTimeout – Timeout interval.
Definition: ncbitime.hpp:1693
Definition: set.hpp:45
std::ofstream out("events_result.xml")
main entry point for tests
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
virtual void ReadReply(CObjectIStream &in, TReply &reply)
Definition: rpcbase.hpp:93
virtual void Ask(const TRequest &request, TReply &reply)
Definition: rpcbase.hpp:87
virtual void WriteRequest(CObjectOStream &out, const TRequest &request)
Definition: rpcbase.hpp:90
#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 kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_CDD_ACCESS_EXPORT
Definition: ncbi_export.h:1505
E_Choice
Choice variants.
Definition: CDD_Reply_.hpp:117
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
std::istream & in(std::istream &in_, double &x_)
static CNamedPipeClient * client
Modified on Wed Sep 04 15:03:26 2024 by modify_doxy.py rev. 669887