NCBI C++ ToolKit
trackmgr_client.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: trackmgr_client.cpp 91807 2020-12-14 15:03:53Z grichenk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'trackmgr.asn'.
35  */
36 
37 #include <ncbi_pch.hpp>
38 #include <serial/serialimpl.hpp>
39 #include <corelib/ncbiapp.hpp>
43 
44 
46 BEGIN_objects_SCOPE
47 
48 
49 CTrackMgrClient::CTrackMgrClient(const string& service)
50  : m_HostType(eNamed_service)
51 {
52  SetService(service);
54  x_Init();
55 }
56 
57 CTrackMgrClient::CTrackMgrClient(const string& host, unsigned int port)
58  : m_HostType(eHost_port),
59  m_Host(host),
60  m_Port(port)
61 {
63  x_Init();
64 }
65 
67 {
68 }
69 
70 void
72 {
73  unique_ptr<STimeout> to(new STimeout());
74  to->sec = 40;
75  SetTimeout(to.release());
76 }
77 
78 // override x_Connect to allow for connection to host:port
79 void
81 {
82  switch (m_HostType) {
83  case eHost_port:
84  _ASSERT(!m_Host.empty());
86  break;
87 
88  case eNamed_service:
90  break;
91  }
92 }
93 
96  const CTMgr_DisplayTrackRequest& req, TReply* reply)
97 {
98  return AskDisplay_tracks(req, reply);
99 }
100 
103 {
104  static const CNcbiApplication* app = CNcbiApplication::Instance();
105  const CNcbiRegistry& cfg = app->GetConfig();
106  const string type = cfg.GetString("TrackMgr", "type", "service");
107  const string name = cfg.GetString("TrackMgr", "name", "TrackMgr");
108  const string port_str = cfg.GetString("TrackMgr", "port", "47228");
109  const unsigned int port(NStr::StringToInt(port_str));
110 
112 
113  if (NStr::EqualNocase(type, "service")) {
114  client.Reset(new CTrackMgrClient(name));
115  }
116  else if (!NStr::EqualNocase(type, "sock")) {
117  NCBI_THROW(CException, eUnknown, "Invalid connection type");
118  }
119  else {
120  client.Reset(new CTrackMgrClient(name, port));
121  }
122 
123  return client.NotNull()
124  ? client->AskDefault_display_tracks(request)
126 }
127 
128 bool CTrackMgrClient::ParseAlignId (const string& external_id,
129  TAlignIDs& parsed_ids)
130 {
131  using TStrIDs = vector<string>;
132 
133  string delim[3] = {";", ":", ","};
134 
135  TStrIDs vec1;
136  NStr::Split(external_id, delim[0], vec1, 0, NULL);
137  for (auto tok1 : vec1)
138  {
139  parsed_ids.push_back(SAlignIds());
140 
141  int batch_id =
142  NStr::StringToNumeric<int>(tok1, NStr::fConvErr_NoThrow, 10);
143  if (batch_id != 0) {
144  parsed_ids.back().batch_id = batch_id;
145  continue;
146  }
147 
148  TStrIDs vec2;
149  NStr::Split(tok1, delim[1], vec2, 0, NULL);
150  int i = -1;
151  for (auto tok2 : vec2)
152  {
153  ++i;
154  if (i % 2 == 0)
155  {
156  int id = NStr::StringToNumeric<int>(tok2,
158  10);
159  if (id != 0) {
160  parsed_ids.back().batch_id = id;
161  continue;
162  }
163  else if (i % 2 == 0) {
164  return false;
165  }
166  }
167 
168  TStrIDs vec3;
169  NStr::Split(tok2, delim[2], vec3, 0, NULL);
170  for (auto tok3 : vec3)
171  {
172  int align_id = NStr::StringToNumeric<int>
173  (tok3, NStr::fConvErr_NoThrow, 10);
174  if (align_id != 0)
175  {
176  parsed_ids.back().align_ids.push_back(align_id);
177  }
178  else
179  {
180  return false;
181  }
182  }
183  }
184 
185  }
186  return true;
187 }
188 
189 END_objects_SCOPE
191 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
This stream exchanges data in a TCP channel, using the SOCK socket API.
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:264
CNcbiRegistry –.
Definition: ncbireg.hpp:913
CRef –.
Definition: ncbiobj.hpp:618
CTMgr_Reply –.
Definition: TMgr_Reply.hpp:66
static CRef< CTMgr_DisplayTrackReply > s_Ask(const CTMgr_DisplayTrackRequest &)
static bool ParseAlignId(const string &external_id, TAlignIDs &parsed_ids)
vector< SAlignIds > TAlignIDs
CTrackMgrClient(const string &service="TrackMgr")
enum CTrackMgrClient::@713 m_HostType
virtual ~CTrackMgrClient()
virtual void x_Connect(void)
These run with m_Mutex already acquired.
unsigned int m_Port
virtual CRef< CTMgr_DisplayTrackReply > AskDefault_display_tracks(const CTMgr_DisplayTrackRequest &req, TReply *reply=0)
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void x_SetStream(CNcbiIostream *stream)
Definition: rpcbase.cpp:214
void SetService(const string &service)
void SetFormat(ESerialDataFormat fmt)
virtual void x_Connect(void) override
Definition: rpcbase.hpp:199
EIO_Status SetTimeout(const STimeout *timeout, EIO_Event direction=eIO_ReadWrite)
Definition: rpcbase.hpp:251
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
virtual string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3452
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5355
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
unsigned short m_Port
TCP port to listen on.
struct STimeoutTag STimeout
Timeout structure.
virtual CRef< CTMgr_DisplayTrackReply > AskDisplay_tracks(const CTMgr_DisplayTrackRequest &req, TReply *reply=0)
int i
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
static CNamedPipeClient * client
Definition: type.c:6
#define _ASSERT
Modified on Wed Sep 04 15:06:02 2024 by modify_doxy.py rev. 669887