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

Go to the SVN repository for this file.

1 /* $Id: id2_fetch_simple.cpp 94691 2021-08-31 11:49:51Z gouriano $
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: Denis Vakatov, Aleksey Grichenko
27  *
28  * File Description:
29  * New IDFETCH network client (get Seq-Entry by GI)
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbiapp.hpp>
34 #include <corelib/ncbienv.hpp>
35 #include <corelib/ncbiargs.hpp>
36 #include <corelib/ncbireg.hpp>
37 #include <corelib/rwstream.hpp>
38 
39 #include <connect/ncbi_util.h>
40 #include <connect/ncbi_socket.h>
43 
44 #include <serial/serial.hpp>
45 #include <serial/objistrasnb.hpp>
46 #include <serial/objostrasnb.hpp>
47 #include <serial/objcopy.hpp>
48 #include <serial/objectio.hpp>
49 #include <serial/iterator.hpp>
50 #include <serial/impl/stdtypes.hpp>
51 
67 
69 #include <util/compress/zlib.hpp>
70 #include <corelib/rwstream.hpp>
71 
73 #include <strstream>
74 
77 
78 
79 
80 /////////////////////////////////
81 // CId1FetchApp::
82 //
83 
85 {
86 public:
87  virtual void Init(void);
88  virtual int Run(void);
89  virtual void Exit(void);
90 
91 private:
92  void x_InitConnection(bool show_init);
93  void x_InitConnection(const string& server_name, bool show_init);
94  void x_InitPubSeqConnection(const string& server_name, bool show_init);
96  void x_ReadReply(CID2_Reply& reply);
97  void x_ReadReply(CID2_Reply& reply, CObjectInfo& object);
98  void x_ProcessRequest(CID2_Request& request, bool dump = true);
99  void x_ProcessRequest(CID2_Request_Packet& packet, bool dump = true);
100  void x_ProcessData(const CID2_Reply_Data& data);
101  void x_SaveDataObject(const CObjectInfo& object, CNcbiOstream& out);
102 
103  unique_ptr<I_DriverContext> m_Context;
107  CNcbiOstream* m_OutFile; // ID2 reply output
108  CNcbiOstream* m_DataFile; // ID2 data output
109  CNcbiOstream* m_RawFile; // ID2 raw data output
115  bool m_Verbose;
117 };
118 
119 
121 {
122  // Prepare command line descriptions
123  //
124 
125  // Create
127 
128  // GI
129  arg_desc->AddOptionalKey
130  ("gi", "SeqEntryID",
131  "GI id of the Seq-Entry to fetch",
133  // Seq-id
134  arg_desc->AddOptionalKey
135  ("id", "SeqEntryID",
136  "Seq-id of the Seq-Entry to fetch",
138  // Seq-id
139  arg_desc->AddOptionalKey
140  ("blob_id", "BlobID",
141  "Blob id of the Seq-Entry to fetch (sat,sat-key)",
143  // Request
144  arg_desc->AddOptionalKey
145  ("req", "Request",
146  "ID2 request in ASN.1 text format",
148  arg_desc->AddOptionalKey
149  ("packet", "Packet",
150  "ID2 request packet in ASN.1 text format",
152  arg_desc->AddOptionalKey
153  ("in", "RequestFile",
154  "File to read request(s) from",
156 
157  arg_desc->AddFlag("verbose", "Verbose output");
158  // Skip blob data
159  arg_desc->AddFlag("skip_data", "Skip blob data");
160  // Copy blob data
161  arg_desc->AddFlag("copy_data", "Copy blob data");
162  // Parse blob data
163  arg_desc->AddFlag("parse_data", "Parse blob data");
164  // Pipe blob data
165  arg_desc->AddFlag("pipe_data", "Pipe parsing blob data");
166 
167  // Print init reply
168  arg_desc->AddFlag("show_init", "Show init reply");
169 
170  // Output format
171  arg_desc->AddDefaultKey
172  ("fmt", "OutputFormat",
173  "Format to dump server reply in",
175  arg_desc->SetConstraint("fmt", &(*new CArgAllow_Strings,
176  "asn", "asnb", "xml", "none"));
177 
178  // Output file
179  arg_desc->AddDefaultKey
180  ("out", "ResultFile",
181  "File to dump the resulting data to",
183 
184  // Raw ID2 data file
185  arg_desc->AddOptionalKey
186  ("raw", "RawFile",
187  "File to dump the raw ID2 data to",
189 
190  // ID2 data file
191  arg_desc->AddOptionalKey
192  ("data", "DataFile",
193  "File to save blob data to",
195 
196  // Log file
197  arg_desc->AddOptionalKey
198  ("log", "LogFile",
199  "File to post errors and messages to",
201  0);
202 
203  // Server to connect
204  arg_desc->AddDefaultKey
205  ("server", "Server",
206  "ID2 server name",
208 
209  // Server to connect
210  arg_desc->AddOptionalKey
211  ("pubseqos", "PubSeqOS",
212  "PubSeqOS server name",
214  arg_desc->AddFlag("HUP", "Set cubby_user");
215 
216  // Number of requests
217  arg_desc->AddDefaultKey
218  ("count", "Count",
219  "Repeat request number of times",
221 
222  // Program description
223  string prog_description =
224  "Fetch SeqEntry from ID server by its GI id";
225  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
226  prog_description, false);
227 
228  // Pass argument descriptions to the application
229  //
230  SetupArgDescriptions(arg_desc.release());
231 }
232 
233 
234 void CId2FetchApp::x_InitConnection(const string& server_name,
235  bool show_init)
236 {
237  STimeout tmout; tmout.sec = 9; tmout.usec = 0;
239  (server_name, fSERV_Any, 0, 0, &tmout));
240 
241  CONN_Wait(m_ID2Conn->GetCONN(), eIO_Write, &tmout);
242  const char* descr = CONN_Description(m_ID2Conn->GetCONN());
243  if ( descr ) {
244  LOG_POST(" connection description: " << descr);
245  }
246 
247  x_InitConnection(show_init);
248 }
249 
250 
251 void CId2FetchApp::x_InitPubSeqConnection(const string& server_name,
252  bool show_init)
253 {
254  C_DriverMgr drvMgr;
255  map<string,string> args;
256  args["packet"]="3584"; // 7*512
257  args["version"]="125"; // for correct connection to OpenServer
258  string errmsg;
259  m_Context.reset(drvMgr.GetDriverContext("ftds", &errmsg, &args));
260  if ( !m_Context ) {
261  ERR_FATAL("Failed to create ftds context: "<<errmsg);
262  }
263 
264  m_PubSeqOS.reset(m_Context->Connect(server_name, "anyone", "allowed", 0));
265  if ( !m_PubSeqOS.get() ) {
266  ERR_FATAL("Failed to open PubSeqOS connection: "<<server_name);
267  }
268 
269  {{
270  AutoPtr<CDB_LangCmd> cmd(m_PubSeqOS->LangCmd("set blob_stream on"));
271  if ( cmd ) {
272  cmd->Send();
273  cmd->DumpResults();
274  }
275  }}
276  if ( GetArgs()["HUP"] ) {
277  string user_name = CSystemInfo::GetUserName();
278  LOG_POST("Setting cubby_user = "<<user_name);
279  // Using a formal parameter is typically better practice, but
280  // likely won't work here (a custom Open Server).
281  string encoded = NStr::SQLEncode(user_name, NStr::eSqlEnc_TagNonASCII);
283  (m_PubSeqOS->LangCmd("set cubby_user " + encoded));
284  cmd->Send();
285  cmd->DumpResults();
286  }
287 
288  x_InitConnection(show_init);
289 }
290 
291 
292 void CId2FetchApp::x_InitConnection(bool show_init)
293 {
294  m_SerialNumber = 0;
295  CID2_Request req;
296  req.SetRequest().SetInit();
297  CID2_Request_Packet packet;
298  packet.Set().push_back(Ref(&req));
299 
300  x_ProcessRequest(packet, show_init);
301 }
302 
303 
304 namespace {
305  bool sx_FetchNextItem(CDB_Result& result, const CTempString& name)
306  {
307  while ( result.Fetch() ) {
308  for ( unsigned pos = 0; pos < result.NofItems(); ++pos ) {
309  if ( result.ItemName(pos) == name ) {
310  return true;
311  }
312  result.SkipItem();
313  }
314  }
315  return false;
316  }
317 
318  class CDB_Result_Reader : public CObject, public IReader
319  {
320  public:
322  AutoPtr<CDB_Result> db_result)
323  : m_DB_RPCCmd(cmd), m_DB_Result(db_result)
324  {
325  }
326 
327  ERW_Result Read(void* buf,
328  size_t count,
329  size_t* bytes_read)
330  {
331  if ( !count ) {
332  if ( bytes_read ) {
333  *bytes_read = 0;
334  }
335  return eRW_Success;
336  }
337  size_t ret;
338  while ( (ret = m_DB_Result->ReadItem(buf, count)) == 0 ) {
339  if ( !sx_FetchNextItem(*m_DB_Result, "asnout") ) {
340  break;
341  }
342  }
343  if ( bytes_read ) {
344  *bytes_read = ret;
345  }
346  return ret? eRW_Success: eRW_Eof;
347  }
348  ERW_Result PendingCount(size_t* /*count*/)
349  {
350  return eRW_NotImplemented;
351  }
352 
353  private:
354  AutoPtr<CDB_RPCCmd> m_DB_RPCCmd;
356  };
357 }
358 
359 
361 {
362  if ( m_Verbose ) {
363  cout << "Sending: " << MSerial_AsnText << packet;
364  }
365  // Open connection to ID1 server
366  if ( m_ID2Conn ) {
367  CObjectOStreamAsnBinary id2_server_output(*m_ID2Conn);
368  // Send request packet to the server
369  id2_server_output << packet;
370  id2_server_output.Flush();
371  }
372  else {
374  const size_t MAX_ASN_IN = 20*1024;
375  char buffer[MAX_ASN_IN];
376  size_t size;
377  {{
378  // NOT CNcbiOstrstream, because that can be ostringstream, which
379  // doesn't support setting up a fixed-length buffer in this manner.
380  ostrstream mem_str(buffer, sizeof(buffer));
381  {{
382  CObjectOStreamAsnBinary obj_str(mem_str);
383  obj_str << packet;
384  }}
385  if ( !mem_str ) {
386  ERR_FATAL("PubSeqOS: packet size overflow");
387  }
388  size = mem_str.pcount();
389  }}
390  CDB_VarChar service("ID2");
391  CDB_VarChar short_asn;
392  CDB_LongBinary long_asn(size);
393  long_asn.SetValue(buffer, size);
394  CDB_TinyInt text_in(0);
395  CDB_TinyInt text_out(0);
396 
397  AutoPtr<CDB_RPCCmd> cmd(m_PubSeqOS->RPC("os_asn_request"));
398  cmd->SetParam("@service", &service);
399  cmd->SetParam("@asnin", &short_asn);
400  cmd->SetParam("@text", &text_in);
401  cmd->SetParam("@out_text", &text_out);
402  cmd->SetParam("@asnin_long", &long_asn);
403  cmd->Send();
404 
406  while( cmd->HasMoreResults() ) {
407  if ( cmd->HasFailed() ) {
408  ERR_FATAL("PubSeqOS: failed RPC");
409  }
410  dbr = cmd->Result();
411  if ( !dbr.get() || dbr->ResultType() != eDB_RowResult ) {
412  continue;
413  }
414  if ( sx_FetchNextItem(*dbr, "asnout") ) {
416  (new CDB_Result_Reader(cmd, dbr));
417  m_PubSeqOSReply.reset(new CRStream(reader.release(),
418  0, 0,
420  return;
421  }
422  }
423  ERR_FATAL("PubSeqOS: no more results");
424  }
425 }
426 
427 
428 namespace {
429  class COSSReader : public IReader
430  {
431  public:
432  typedef vector<char> TOctetString;
433  typedef list<TOctetString*> TOctetStringSequence;
434 
435  COSSReader(const TOctetStringSequence& in)
436  : m_Input(in),
437  m_CurVec(in.begin())
438  {
439  x_SetVec();
440  }
441 
442  virtual ERW_Result Read(void* buffer,
443  size_t count,
444  size_t* bytes_read = 0)
445  {
446  size_t pending = x_Pending();
447  count = min(pending, count);
448  if ( bytes_read ) {
449  *bytes_read = count;
450  }
451  if ( pending == 0 ) {
452  return eRW_Eof;
453  }
454  if ( count ) {
455  memcpy(buffer, &(**m_CurVec)[m_CurPos], count);
456  m_CurPos += count;
457  }
458  return eRW_Success;
459  }
460 
461  virtual ERW_Result PendingCount(size_t* count)
462  {
463  size_t pending = x_Pending();
464  *count = pending;
465  return pending? eRW_Success: eRW_Eof;
466  }
467 
468  protected:
469  void x_SetVec(void)
470  {
471  m_CurPos = 0;
472  m_CurSize = m_CurVec == m_Input.end()? 0: (**m_CurVec).size();
473  }
474  size_t x_Pending(void)
475  {
476  size_t size;
477  while ( (size = m_CurSize - m_CurPos) == 0 &&
478  m_CurVec != m_Input.end() ) {
479  ++m_CurVec;
480  x_SetVec();
481  }
482  return size;
483  }
484  private:
485  const TOctetStringSequence& m_Input;
486  TOctetStringSequence::const_iterator m_CurVec;
487  size_t m_CurPos;
488  size_t m_CurSize;
489  };
490 
491  class CReadDataObjectHookSkip : public CReadClassMemberHook
492  {
493  public:
494  virtual void ReadClassMember(CObjectIStream& in,
495  const CObjectInfoMI& member) {
498  for ( CIStreamContainerIterator it(in, member.GetMemberType());
499  it; it.NextElement(), ++it ) {
501 
502  char buf[4096];
503  size_t count;
504  while ( (count = block.Read(buf, sizeof(buf))) != 0 ) {
505  }
506 
507  block.End();
508  }
509  data.SetData();
510  }
511  };
512 
513  class COSSPipeReader : public IReader
514  {
515  public:
516  COSSPipeReader(CObjectIStream& in,
517  const CObjectInfoMI& member)
518  : m_Input(in),
519  m_Iter(in, member.GetMemberType()) {
520  }
521 
522  ~COSSPipeReader() {
523  do {
524  x_CloseBlock();
525  } while ( x_OpenBlock() );
526  }
527 
528  virtual ERW_Result Read(void* buffer,
529  size_t buffer_size,
530  size_t* bytes_read = 0) {
531  for ( ;; ) {
532  if ( m_Block.get() ) {
533  size_t count = m_Block->Read(buffer, buffer_size);
534  if ( count != 0 ) {
535  if ( bytes_read ) {
536  *bytes_read = count;
537  }
538  return eRW_Success;
539  }
540  else {
541  x_CloseBlock();
542  }
543  }
544  else {
545  if ( !x_OpenBlock() ) {
546  if ( bytes_read ) {
547  *bytes_read = 0;
548  }
549  return eRW_Eof;
550  }
551  }
552  }
553  }
554  virtual ERW_Result PendingCount(size_t* /*count*/) {
555  return eRW_NotImplemented;
556  }
557  protected:
558  bool x_OpenBlock(void) {
559  if ( !m_Iter ) {
560  return false;
561  }
562  m_Block.reset(new CObjectIStream::ByteBlock(m_Input));
563  return true;
564  }
565  void x_CloseBlock(void) {
566  if ( m_Block.get() ) {
567  m_Block->End();
568  m_Block.reset();
569  m_Iter.NextElement();
570  ++m_Iter;
571  }
572  }
573  private:
574  CObjectIStream& m_Input;
577  };
578 
579  class CReadDataObjectHook : public CReadClassMemberHook
580  {
581  public:
582  CObjectInfo m_Object;
583 
584  virtual void ReadClassMember(CObjectIStream& in,
585  const CObjectInfoMI& member) {
588 
589  TTypeInfo obj_type = 0;
590  switch ( data.GetData_type() ) {
592  obj_type = CSeq_entry::GetTypeInfo();
593  break;
595  obj_type = CSeq_annot::GetTypeInfo();
596  break;
598  obj_type = CID2S_Split_Info::GetTypeInfo();
599  break;
601  obj_type = CID2S_Chunk::GetTypeInfo();
602  break;
603  default:
604  ERR_FATAL("Unknown data type in ID2_Reply_Data");
605  }
606 
608  switch ( data.GetData_format() ) {
611  break;
614  break;
617  break;
618  default:
619  ERR_FATAL("Unknown data format in ID2_Reply_Data");
620  }
621 
622  {{
623  COSSPipeReader reader(in, member);
624  CRStream stream(&reader);
625  AutoPtr<CObjectIStream> obj_stream;
626 
627  switch ( data.GetData_compression() ) {
629  {
630  obj_stream.reset(CObjectIStream::Open(format, stream));
631  break;
632  }
634  {
635  obj_stream.reset
637  (format,
638  *new CCompressionIStream(stream,
641  eTakeOwnership));
642  break;
643  }
644  default:
645  ERR_FATAL("Unknown data compression in ID2_Reply_Data");
646  }
647  _ASSERT( obj_stream.get() );
648  obj_stream->UseMemoryPool();
649  m_Object = CObjectInfo(obj_type);
650  obj_stream->Read(m_Object.GetObjectPtr(), obj_type);
651  }}
652 
653  data.SetData();
654  }
655  };
656 }
657 
658 
660 {
661  // Read server response in ASN.1 binary format
662  if ( m_ID2Conn ) {
663  CObjectIStreamAsnBinary id2_server_input(*m_ID2Conn);
664  id2_server_input >> reply;
665  }
666  else {
667  CObjectIStreamAsnBinary id2_server_input(*m_PubSeqOSReply);
668  id2_server_input >> reply;
669  }
670  if ( m_Verbose ) {
671  cout << "Received: " << MSerial_AsnText << reply;
672  }
673 }
674 
675 
677 {
678  // Read server response in ASN.1 binary format
679  CRef<CReadDataObjectHook> hook(new CReadDataObjectHook);
680  CObjectHookGuard<CID2_Reply_Data> guard("data", *hook);
681  if ( m_ID2Conn ) {
682  CObjectIStreamAsnBinary id2_server_input(*m_ID2Conn);
683  id2_server_input >> reply;
684  }
685  else {
686  CObjectIStreamAsnBinary id2_server_input(*m_PubSeqOSReply);
687  id2_server_input >> reply;
688  }
689  object = hook->m_Object;
690  if ( m_Verbose ) {
691  cout << "Received: " << MSerial_AsnText << reply;
692  }
693 }
694 
695 
697 {
698  CID2_Request_Packet packet;
699  packet.Set().push_back(Ref(&request));
700  x_ProcessRequest(packet, dump);
701 }
702 
703 
705 {
708  CID2_Request& req = **it;
709  if ( !req.IsSetSerial_number() ) {
711  }
712  }
713 
714  if ( false && dump ) {
715  CNcbiOstrstream ostr;
716  ostr << MSerial_AsnText << packet;
717  LOG_POST("\nProcessing request:\n" << ostr.rdbuf());
718  }
719 
720  x_SendRequestPacket(packet);
721 
722  size_t remaining_count = packet.Set().size();
723 
724  CID2_Reply reply;
725 
726  double time_first = 0;
727  while ( remaining_count > 0 ) {
728  if ( m_PipeData ) {
729  CObjectInfo object;
730  x_ReadReply(reply, object);
731  if ( !time_first ) time_first = sw.Elapsed();
732  if ( object && m_DataFile ) {
733  x_SaveDataObject(object, *m_DataFile);
734  }
735  }
736  else {
737  x_ReadReply(reply);
738  if ( !time_first ) time_first = sw.Elapsed();
739  if ( m_ParseData || m_SkipData || m_RawFile || m_DataFile ) {
741  if ( iter && iter->IsSetData() ) {
742  if ( m_ParseData || m_RawFile || m_DataFile ) {
743  x_ProcessData(*iter);
744  }
745  if ( m_SkipData ) {
746  iter->ResetData();
747  iter->SetData();
748  }
749  }
750  }
751  }
752  if ( dump && m_OutFile ) {
753  AutoPtr<CObjectOStream> id2_client_output
755 
756  *id2_client_output << reply;
758  *m_OutFile << NcbiEndl;
759  }
760  }
761  if ( reply.IsSetEnd_of_reply() ) {
762  --remaining_count;
763  }
764  }
765  LOG_POST("Packet processed in " << sw.Elapsed()<< " first at "<<time_first);
766 }
767 
768 
770 {
771  _ASSERT( data.IsSetData() );
772 
773  TTypeInfo obj_type = 0;
774  switch ( data.GetData_type() ) {
776  obj_type = CSeq_entry::GetTypeInfo();
777  break;
779  obj_type = CSeq_annot::GetTypeInfo();
780  break;
782  obj_type = CID2S_Split_Info::GetTypeInfo();
783  break;
785  obj_type = CID2S_Chunk::GetTypeInfo();
786  break;
787  default:
788  ERR_FATAL("Unknown data type in ID2_Reply_Data");
789  }
790 
792  switch ( data.GetData_format() ) {
795  break;
798  break;
801  break;
802  default:
803  ERR_FATAL("Unknown data format in ID2_Reply_Data");
804  }
805 
806  if ( m_RawFile ) {
807  COSSReader reader(data.GetData());
808  CRStream stream(&reader);
809  if ( data.GetData_compression() == CID2_Reply_Data::eData_compression_gzip ) {
810  CCompressionIStream stream2(stream,
813  *m_RawFile << stream2.rdbuf();
814  }
815  else {
816  *m_RawFile << stream.rdbuf();
817  }
818  }
819 
820  COSSReader reader(data.GetData());
821  CRStream stream(&reader);
822  AutoPtr<CObjectIStream> obj_stream;
823 
824  switch ( data.GetData_compression() ) {
826  {
827  obj_stream.reset(CObjectIStream::Open(format, stream));
828  break;
829  }
831  {
832  obj_stream.reset(CObjectIStream::Open(format,
833  *(new CCompressionIStream(stream,
836  break;
837  }
838  default:
839  ERR_FATAL("Unknown data compression in ID2_Reply_Data");
840  }
841  _ASSERT( obj_stream.get() );
842  obj_stream->UseMemoryPool();
843  AutoPtr<CObjectOStream> out_stream;
844  if ( m_DataFile ) {
846  }
847  if ( m_CopyData && out_stream.get() ) {
848  CObjectStreamCopier copier(*obj_stream, *out_stream);
849  copier.Copy(obj_type);
850  }
851  else {
852  CObjectInfo obj(obj_type);
853  obj_stream->Read(obj.GetObjectPtr(), obj.GetTypeInfo());
854  if ( out_stream.get() ) {
855  out_stream->Write(obj.GetObjectPtr(), obj.GetTypeInfo());
856  }
857  }
858  if ( out_stream.get() && m_Format != eSerial_AsnBinary) {
859  out_stream->FlushBuffer();
860  *m_DataFile << '\n';
861  }
862 }
863 
864 
866  CNcbiOstream& out)
867 {
868  AutoPtr<CObjectOStream> out_stream(
870  out_stream->Write(object.GetObjectPtr(), object.GetTypeInfo());
871  if ( m_Format != eSerial_AsnBinary) {
872  out_stream->FlushBuffer();
873  out << '\n';
874  }
875 }
876 
877 
879 {
880  // Process command line args
881  const CArgs& args = GetArgs();
882 
883  // Setup and tune logging facilities
884  if ( args["log"] ) {
885  SetDiagStream( &args["log"].AsOutputFile() );
886  }
887 #ifdef _DEBUG
888  // SetDiagTrace(eDT_Enable);
891 #endif
892 
893  // Setup application registry, error log, and MT-lock for CONNECT library
895 
896  m_OutFile = 0;
897  m_DataFile = 0;
898  m_RawFile = 0;
899  if ( args["fmt"].AsString() != "none" ) {
900  if ( args["data"] ) {
901  m_DataFile = &args["data"].AsOutputFile();
902  }
903  if ( !m_DataFile || args["out"].AsString() != "-" ) {
904  m_OutFile = &args["out"].AsOutputFile();
905  }
906  }
907  if ( args["raw"] ) {
908  m_RawFile = &args["raw"].AsOutputFile();
909  }
910  const string& fmt = args["fmt"].AsString();
911  if (fmt == "asn") {
913  } else if (fmt == "asnb") {
915  } else if (fmt == "xml") {
917  }
918  m_Verbose = args["verbose"];
919  m_SkipData = args["skip_data"];
920  m_CopyData = args["copy_data"];
921  m_ParseData = args["parse_data"];
922  m_PipeData = args["pipe_data"];
923 
924  int count = args["count"].AsInteger();
925 
926  if ( args["pubseqos"] ) {
927  x_InitPubSeqConnection(args["pubseqos"].AsString(), args["show_init"]);
928  }
929  else {
930  x_InitConnection(args["server"].AsString(), args["show_init"]);
931  }
932 
933  typedef vector<CRef<CID2_Request_Packet> > TReqs;
934  TReqs reqs;
935 
936  if ( args["gi"] ) {
937  TGi gi = GI_FROM(TIntId, args["gi"].AsIntId());
939  reqs.push_back(packet);
941  packet->Set().push_back(req);
942 
943  req->SetRequest().SetGet_blob_info().SetBlob_id().SetResolve().
944  SetRequest().SetSeq_id().SetSeq_id().SetSeq_id().SetGi(gi);
945  req->SetRequest().SetGet_blob_info().SetGet_data();
946  }
947  else if ( args["id"] ) {
948  CRef<CSeq_id> id(new CSeq_id(args["id"].AsString()));
950  reqs.push_back(packet);
952  packet->Set().push_back(req);
953 
954  req->SetRequest().SetGet_blob_info().SetBlob_id().SetResolve().
955  SetRequest().SetSeq_id().SetSeq_id().SetSeq_id(*id);
956  req->SetRequest().SetGet_blob_info().SetGet_data();
957  }
958  else if ( args["blob_id"] ) {
959  vector<string> vv;
960  NStr::Split(args["blob_id"].AsString(), ",", vv);
961  if ( vv.size() != 2 ) {
962  ERR_FATAL("Bad blob_id format: "<<args["blob_id"]);
963  }
964  int sat = NStr::StringToInt(vv[0]);
965  int sat_key = NStr::StringToInt(vv[1]);
967  reqs.push_back(packet);
969  packet->Set().push_back(req);
970  CID2_Blob_Id& blob_id =
971  req->SetRequest().SetGet_blob_info().SetBlob_id().SetBlob_id();
972  blob_id.SetSat(sat);
973  blob_id.SetSat_key(sat_key);
974  req->SetRequest().SetGet_blob_info().SetGet_data();
975  }
976  else if ( args["req"] ) {
978  reqs.push_back(packet);
980  packet->Set().push_back(req);
981 
982  string text = args["req"].AsString();
983  if ( text.find("::=") == NPOS ) {
984  text = "ID2-Request ::= " + text;
985  }
987  in >> MSerial_AsnText >> *req;
988  }
989  else if ( args["packet"] ) {
991  reqs.push_back(packet);
992 
993  string text = args["packet"].AsString();
994  if ( text.find("::=") == NPOS ) {
995  text = "ID2-Request-Packet ::= " + text;
996  }
997  CID2_Request_Packet id2_packet;
999  in >> MSerial_AsnText >> *packet;
1000  }
1001  else if ( args["in"] ) {
1002  AutoPtr<CObjectIStream> req_input
1003  (CObjectIStream::Open(eSerial_AsnText, args["in"].AsInputFile()));
1004 
1005  while ( !req_input->EndOfData() ) {
1006  string type = req_input->ReadFileHeader();
1007  if (type == "ID2-Request") {
1009  reqs.push_back(packet);
1011  packet->Set().push_back(req);
1012 
1013  req_input->Read(req, req->GetThisTypeInfo(),
1015  }
1016  else if (type == "ID2-Request-Packet") {
1018  reqs.push_back(packet);
1019 
1020  req_input->Read(packet, packet->GetThisTypeInfo(),
1022  }
1023  else {
1024  ERR_FATAL("Object type must be ID2-Request or ID2-Request-Packet.");
1025  }
1026  }
1027  }
1028  else {
1029  ERR_FATAL("No ID2-Request specified.");
1030  }
1031 
1032 
1033  NON_CONST_ITERATE ( TReqs, it, reqs ) {
1034  for ( int i = 0; i < count; ++i ) {
1035  x_ProcessRequest(**it);
1036  }
1037  }
1038  return 0; // Done
1039 }
1040 
1041 
1042 
1043 // Cleanup
1045 {
1046  SOCK_ShutdownAPI();
1047  SetDiagStream(0);
1048 }
1049 
1050 
1051 
1052 /////////////////////////////////////////////////////////////////////////////
1053 // MAIN
1054 //
1055 
1056 int main(int argc, const char* argv[])
1057 {
1058  return CId2FetchApp().AppMain(argc, argv);
1059 }
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CArgAllow_Strings –.
Definition: ncbiargs.hpp:1641
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
This stream exchanges data with a named service, in a constraint that the service is implemented as o...
ERW_Result PendingCount(size_t *)
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
Definition: asn2asn.cpp:746
ERW_Result Read(void *buf, size_t count, size_t *bytes_read)
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
Definition: asn2asn.cpp:727
CDB_Result * m_DB_Result
Definition: asn2asn.cpp:751
CDB_Result_Reader(CDB_Result *db_result)
Definition: asn2asn.cpp:723
CID2_Blob_Id –.
Definition: ID2_Blob_Id.hpp:66
CID2_Reply –.
Definition: ID2_Reply.hpp:66
CID2_Request_Packet –.
CID2_Request –.
Definition: ID2_Request.hpp:66
Reading (iterating through) elements of containers (SET OF, SEQUENCE OF).
Definition: objectio.hpp:164
unique_ptr< I_DriverContext > m_Context
void x_InitConnection(bool show_init)
virtual int Run(void)
Run the application.
CNcbiOstream * m_DataFile
CNcbiOstream * m_RawFile
void x_SendRequestPacket(CID2_Request_Packet &packet)
CNcbiOstream * m_OutFile
void x_InitPubSeqConnection(const string &server_name, bool show_init)
void x_SaveDataObject(const CObjectInfo &object, CNcbiOstream &out)
void x_ProcessRequest(CID2_Request &request, bool dump=true)
virtual void Init(void)
Initialize the application.
AutoPtr< CDB_Connection > m_PubSeqOS
AutoPtr< CNcbiIstream > m_PubSeqOSReply
ESerialDataFormat m_Format
void x_ProcessData(const CID2_Reply_Data &data)
virtual void Exit(void)
Cleanup on application exit.
AutoPtr< CConn_ServiceStream > m_ID2Conn
void x_ReadReply(CID2_Reply &reply)
Helper class: installs hooks in constructor, and uninstalls in destructor.
Definition: objhook.hpp:397
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
CObjectStreamCopier –.
Definition: objcopy.hpp:71
CObject –.
Definition: ncbiobj.hpp:180
Note about the "buf_size" parameter for streams in this API.
Definition: rwstream.hpp:122
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
CRef –.
Definition: ncbiobj.hpp:618
CStopWatch –.
Definition: ncbitime.hpp:1937
static string GetUserName(void)
Get actual user name for the current process.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Template class for iteration on objects of class C.
Definition: iterator.hpp:673
CZipStreamDecompressor – zlib based decompression stream processor.
Definition: zlib.hpp:817
A very basic data-read interface.
std::ofstream out("events_result.xml")
main entry point for tests
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
char data[12]
Definition: iconv.c:80
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
Definition: ncbimisc.hpp:480
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:305
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:819
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1195
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
Int8 TIntId
Definition: ncbimisc.hpp:999
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
element_type * release(void)
Release will release ownership of pointer to caller.
Definition: ncbimisc.hpp:472
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
void AddFlag(const string &name, const string &comment, CBoolEnum< EFlagValue > set_value=eFlagHasValueIfSet, TFlags flags=0)
Add description for flag argument.
Definition: ncbiargs.cpp:2459
void SetConstraint(const string &name, const CArgAllow *constraint, EConstraintNegate negate=eConstraint)
Set additional user defined constraint on argument value.
Definition: ncbiargs.cpp:2591
void SetUsageContext(const string &usage_name, const string &usage_description, bool usage_sort_args=false, SIZE_TYPE usage_width=78)
Set extra info to be used by PrintUsage().
Definition: ncbiargs.cpp:3304
void AddOptionalKey(const string &name, const string &synopsis, const string &comment, EType type, TFlags flags=0)
Add description for optional key without default value.
Definition: ncbiargs.cpp:2427
void AddDefaultKey(const string &name, const string &synopsis, const string &comment, EType type, const string &default_value, TFlags flags=0, const string &env_var=kEmptyStr, const char *display_value=nullptr)
Add description for optional key with default value.
Definition: ncbiargs.cpp:2442
@ fBinary
Open as binary file; for eInputFile, eOutputFile, eIOFile.
Definition: ncbiargs.hpp:620
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eIntId
Convertible to TIntId (int or Int8 depending on NCBI_INT8_GI)
Definition: ncbiargs.hpp:593
@ eString
An arbitrary string.
Definition: ncbiargs.hpp:589
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
@ eInteger
Convertible into an integer number (int or Int8)
Definition: ncbiargs.hpp:592
CONN GetCONN(void) const
char * CONN_Description(CONN conn)
Return a human-readable description of the connection as a character '\0'-terminated string.
EIO_Status CONN_Wait(CONN conn, EIO_Event event, const STimeout *timeout)
Block on the connection until it becomes available for either reading or writing (depending on "event...
I_DriverContext * GetDriverContext(const string &driver_name, string *err_msg=0, const map< string, string > *attr=0)
Definition: driver_mgr.cpp:308
@ eDB_RowResult
Definition: interfaces.hpp:387
virtual EDB_ResType ResultType() const
Get type of the result.
Definition: public.cpp:603
virtual CDB_LangCmd * LangCmd(const string &lang_query)
Make language command.
Definition: public.cpp:355
virtual size_t ReadItem(void *buffer, size_t buffer_size, bool *is_null=0)
Read a result item body (for BLOB columns, mostly).
Definition: public.cpp:678
virtual CDB_RPCCmd * RPC(const string &rpc_name)
Make remote procedure call command.
Definition: public.cpp:362
void SetValue(const void *v, size_t v_size)
Definition: types.cpp:1759
#define ERR_FATAL(message)
Posting fatal error and abort.
Definition: ncbidiag.hpp:240
void SetDiagPostFlag(EDiagPostFlag flag)
Set the specified flag (globally).
Definition: ncbidiag.cpp:6070
EDiagSev SetDiagPostLevel(EDiagSev post_sev=eDiag_Error)
Set the threshold severity for posting the messages.
Definition: ncbidiag.cpp:6129
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void SetDiagStream(CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
Set diagnostic stream.
Definition: ncbidiag.cpp:8083
@ eDPF_All
All flags (except for the "unusual" ones!)
Definition: ncbidiag.hpp:718
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
CBeginInfo Begin(C &obj)
Get starting point of object hierarchy.
Definition: iterator.hpp:1004
void Read(const CObjectInfo &object)
Read object of know type.
Definition: objistr.cpp:952
virtual bool EndOfData(void)
Check if there is still some meaningful data that can be read; in text streams this function will ski...
Definition: objistr.cpp:588
CObjectTypeInfo GetMemberType(void) const
Get data type information.
TObjectPtr GetObjectPtr(void) const
Get pointer to object.
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
virtual string ReadFileHeader(void)
Read file header.
Definition: objistr.cpp:1121
const CObjectInfo & GetClassObject(void) const
Get containing class data.
void Write(const CConstObjectInfo &object)
Definition: objostr.cpp:593
TTypeInfo GetTypeInfo(void) const
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
void UseMemoryPool(void)
Definition: objistr.cpp:775
void FlushBuffer(void)
void Copy(const CObjectTypeInfo &type)
Copy data.
Definition: objcopy.cpp:74
virtual void ReadClassMember(CObjectIStream &in, const CObjectInfoMI &member)=0
This method will be called at approriate time when the object of requested type is to be read.
void Flush(void)
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
@ fSERV_Any
Definition: ncbi_service.h:79
EIO_Status SOCK_ShutdownAPI(void)
Cleanup; destroy all internal/system data & resources used by the SOCK API.
Definition: ncbi_socket.c:1019
ERW_Result
Result codes for I/O operations.
#define NcbiEndl
Definition: ncbistre.hpp:548
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
@ eRW_NotImplemented
Action / information is not available.
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Success
Everything is okay, I/O completed.
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:3461
static CStringUTF8 SQLEncode(const CStringUTF8 &str, ESqlEncode flag)
SQL-encode string.
Definition: ncbistr.cpp:6140
#define NPOS
Definition: ncbistr.hpp:133
@ eSqlEnc_TagNonASCII
Produce N'...' when input's not pure ASCII.
Definition: ncbistr.hpp:3168
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2775
@ eStart
Start timer immediately after creating.
Definition: ncbitime.hpp:1941
void CONNECT_Init(const IRWRegistry *reg=0, CRWLock *lock=0, TConnectInitFlags flag=eConnectInit_OwnNothing, FSSLSetup ssl=0)
Init [X]CONNECT library with the specified "reg" and "lock" (ownership for either or both can be deta...
unsigned int usec
microseconds (modulo 1,000,000)
Definition: ncbi_types.h:78
unsigned int sec
seconds
Definition: ncbi_types.h:77
@ eIO_Write
write
Definition: ncbi_core.h:121
#define dump(b)
void SetSerial_number(TSerial_number value)
Assign a value to Serial_number data member.
void SetSat_key(TSat_key value)
Assign a value to Sat_key data member.
bool IsSetSerial_number(void) const
request's serial number, can be used in asynchronic clients server should copy it to corresponding fi...
Tdata & Set(void)
Assign a value to data member.
list< CRef< CID2_Request > > Tdata
void SetSat(TSat value)
Assign a value to Sat data member.
void SetRequest(TRequest &value)
Assign a value to Request data member.
bool IsSetEnd_of_reply(void) const
true if this reply is the last one for the request false if more replies will follow Check if a value...
Definition: ID2_Reply_.hpp:904
USING_SCOPE(objects)
int main(int argc, const char *argv[])
USING_NCBI_SCOPE
static CStopWatch sw
char * buf
int i
static void text(MDB_val *v)
Definition: mdb_dump.c:62
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
Process information in the NCBI Registry, including working with configuration files.
T min(T x_, T y_)
static Format format
Definition: njn_ioutil.cpp:53
std::istream & in(std::istream &in_, double &x_)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
static int buffer_size
Definition: pcretest.c:1050
#define MAX_ASN_IN
Reader-writer based streams.
Timeout structure.
Definition: ncbi_types.h:76
Definition: type.c:6
#define _ASSERT
else result
Definition: token2.c:20
ZLib Compression API.
Modified on Mon May 20 05:05:03 2024 by modify_doxy.py rev. 669887