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 78868 2017-07-25 12:18:47Z clausen $
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  auto_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 {
105  static const CNcbiApplication* app = CNcbiApplication::Instance();
106  const CNcbiRegistry& cfg = app->GetConfig();
107  const string type = cfg.GetString("TrackMgr", "type", "service");
108  const string name = cfg.GetString("TrackMgr", "name", "TrackMgr");
109  const string port_str = cfg.GetString("TrackMgr", "port", "47228");
110  const unsigned int port(NStr::StringToInt(port_str));
111 
112  CRef<CTrackMgrClient> client;
113 
114  if (NStr::EqualNocase(type, "service")) {
115  client.Reset(new CTrackMgrClient(name));
116  }
117  else if (!NStr::EqualNocase(type, "sock")) {
118  NCBI_THROW(CException, eUnknown, "Invalid connection type");
119  }
120  else {
121  client.Reset(new CTrackMgrClient(name, port));
122  }
123 
124  return client.NotNull()
125  ? client->AskDefault_display_tracks(request)
127 }
128 
129 bool CTrackMgrClient::ParseAlignId (const string& external_id,
130  TAlignIDs& parsed_ids)
131 {
132  using TStrIDs = vector<string>;
133 
134  string delim[3] = {";", ":", ","};
135 
136  TStrIDs vec1;
137  NStr::Split(external_id, delim[0], vec1, 0, NULL);
138  for (auto tok1 : vec1)
139  {
140  parsed_ids.push_back(SAlignIds());
141 
142  int batch_id =
143  NStr::StringToNumeric<int>(tok1, NStr::fConvErr_NoThrow, 10);
144  if (batch_id != 0) {
145  parsed_ids.back().batch_id = batch_id;
146  continue;
147  }
148 
149  TStrIDs vec2;
150  NStr::Split(tok1, delim[1], vec2, 0, NULL);
151  int i = -1;
152  for (auto tok2 : vec2)
153  {
154  ++i;
155  if (i % 2 == 0)
156  {
157  int id = NStr::StringToNumeric<int>(tok2,
159  10);
160  if (id != 0) {
161  parsed_ids.back().batch_id = id;
162  continue;
163  }
164  else if (i % 2 == 0) {
165  return false;
166  }
167  }
168 
169  TStrIDs vec3;
170  NStr::Split(tok2, delim[2], vec3, 0, NULL);
171  for (auto tok3 : vec3)
172  {
173  int align_id = NStr::StringToNumeric<int>
174  (tok3, NStr::fConvErr_NoThrow, 10);
175  if (align_id != 0)
176  {
177  parsed_ids.back().align_ids.push_back(align_id);
178  }
179  else
180  {
181  return false;
182  }
183  }
184  }
185 
186  }
187  return true;
188 }
189 
190 END_objects_SCOPE
192 
void SetService(const string &service)
CTrackMgrClient(const string &service="TrackMgr")
virtual void x_Connect(void) override
EIO_Status SetTimeout(const STimeout *timeout, EIO_Event direction=eIO_ReadWrite)
Do not throw an exception on error.
Definition: ncbistr.hpp:253
unsigned int m_Port
This stream exchanges data in a TCP channel, using socket interface.
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
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:98
#define NULL
Definition: ncbistd.hpp:225
virtual CRef< CTMgr_DisplayTrackReply > AskDefault_display_tracks(const CTMgr_DisplayTrackRequest &req, TReply *reply=0)
int i
virtual CRef< CTMgr_DisplayTrackReply > AskDisplay_tracks(const CTMgr_DisplayTrackRequest &req, TReply *reply=0)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
static CRef< CTMgr_DisplayTrackReply > s_Ask(const CTMgr_DisplayTrackRequest &)
virtual ~CTrackMgrClient()
User-defined methods of the data storage class.
bool NotNull(void) const THROWS_NONE
Check if pointer is not null – same effect as NotEmpty().
Definition: ncbiobj.hpp:739
Definition: type.c:5
void x_SetStream(CNcbiIostream *stream)
Definition: rpcbase.cpp:122
vector< SAlignIds > TAlignIDs
User-defined methods of the data storage class.
CRef –.
Definition: ncbiobj.hpp:616
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
Definition: ncbiapp.hpp:707
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
void SetFormat(ESerialDataFormat fmt)
unsigned short m_Port
TCP port to listen on.
CNcbiApplication –.
Definition: ncbiapp.hpp:120
CNcbiRegistry –.
Definition: ncbireg.hpp:914
struct STimeoutTag STimeout
Timeout structure.
#define _ASSERT
static bool EqualNocase(const CTempString str, SIZE_TYPE pos, SIZE_TYPE n, const char *pattern)
Case-insensitive equality of a substring with a pattern.
Definition: ncbistr.hpp:5087
CTMgr_Reply –.
Definition: TMgr_Reply.hpp:65
enum CTrackMgrClient::@691 m_HostType
static bool ParseAlignId(const string &external_id, TAlignIDs &parsed_ids)
#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:547
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:3362
static SSystemMutex & GetInstanceMutex(void)
Mutex for application singleton object.
Definition: ncbiapp.cpp:89
virtual void x_Connect(void)
These run with m_Mutex already acquired.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:768
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:531
ASN.1 binary.
Definition: serialdef.hpp:74
Modified on Sat Apr 21 13:39:11 2018 by modify_doxy.py rev. 546573