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

Go to the SVN repository for this file.

00001 /* $Id: gbench_svc_cli.cpp 25561 2012-04-09 14:41:17Z voronov $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Author:  .......
00027  *
00028  * File Description:
00029  *   .......
00030  *
00031  * Remark:
00032  *   This code was originally generated by application DATATOOL
00033  *   using the following specifications:
00034  *   'gbench_svc.asn'.
00035  */
00036 
00037 // standard includes
00038 #include <ncbi_pch.hpp>
00039 
00040 // generated includes
00041 #include <gui/objects/gbench_svc_cli.hpp>
00042 #include <gui/objects/GBenchFeedbackRequest.hpp>
00043 #include <gui/objects/GBenchFeedbackAttachment.hpp>
00044 #include <gui/objects/GBenchInitRequest.hpp>
00045 #include <gui/objects/GBenchInitReply.hpp>
00046 
00047 #include <objects/general/Date.hpp>
00048 #include <objects/general/User_object.hpp>
00049 #include <objects/general/Object_id.hpp>
00050 
00051 // generated classes
00052 
00053 BEGIN_NCBI_SCOPE
00054 
00055 BEGIN_objects_SCOPE // namespace ncbi::objects::
00056 
00057 static const STimeout s_DefaultTimeout = {10, 0};
00058 
00059 // constructor
00060 CGBenchService::CGBenchService(void)
00061 {
00062     SetTimeout( &s_DefaultTimeout );
00063 }
00064 
00065 // destructor
00066 CGBenchService::~CGBenchService(void)
00067 {
00068 }
00069 
00070 CRef<CUser_object> CGBenchService::SendAppStart( const CGBenchVersionInfo& version )
00071 {
00072     m_Timer.Start();
00073 
00074     string gbenchVersion, osVersion, buildDate;
00075     version.GetVersionString(&gbenchVersion);
00076     version.GetOsString(&osVersion);
00077 
00078     if (version.IsSetBuild_date()) {
00079         buildDate = version.GetBuild_date().AsCTime().AsString();
00080     }
00081 
00082     CRef<CUser_object> req(new CUser_object());
00083     req->SetType().SetStr("app-start");
00084     req->AddField("gbench-version", gbenchVersion);
00085     req->AddField("os-version", osVersion);
00086     if( !buildDate.empty() ){
00087         req->AddField("build-date", buildDate);
00088     }
00089 
00090     return AskGeneric(*req);
00091 }
00092 
00093 bool CGBenchService::SendAppFinish( const CGBenchVersionInfo& version )
00094 {
00095     m_Timer.Stop();
00096 
00097     string gbenchVersion, osVersion, buildDate;
00098     version.GetVersionString(&gbenchVersion);
00099     version.GetOsString(&osVersion);
00100 
00101     if (version.IsSetBuild_date()) {
00102         buildDate = version.GetBuild_date().AsCTime().AsString();
00103     }
00104 
00105     CRef<CUser_object> req(new CUser_object());
00106     req->SetType().SetStr("app-finish");
00107     req->AddField("gbench-version", gbenchVersion);
00108     req->AddField("os-version", osVersion);
00109     if( !buildDate.empty() ){
00110         req->AddField("build-date", buildDate);
00111     }
00112 
00113     req->AddField( "uptime", (int)m_Timer.Elapsed() );
00114 
00115     //STimeout finish_timeout = {1, 0};
00116     //SetTimeout( &finish_timeout );
00117     AskGeneric(*req);
00118 
00119     SetTimeout( &s_DefaultTimeout );
00120 
00121     return true;
00122 }
00123 
00124 
00125 /// send an init message with information about our client
00126 CRef<CGBenchInitReply>
00127 CGBenchService::SendInit(const CGBenchVersionInfo& version)
00128 {
00129     CGBenchInitRequest req;
00130     req.SetVersion().Assign(version);
00131     return AskInit(req);
00132 }
00133 
00134 
00135 void CGBenchService::SendFeedbackReport(const string& msg,
00136                                         const string& email_addr,
00137                                         const CGBenchVersionInfo& version,
00138                                         CNcbiIstream* app_log_istr,
00139                                         CNcbiIstream* sys_config_istr)
00140 {
00141     ///
00142     /// format our feedback report
00143     ///
00144     CGBenchFeedbackRequest req;
00145 
00146     req.SetVersion().Assign(version);
00147     req.SetEmail_addr(email_addr);
00148     req.EncodeDesc(msg);
00149 
00150     if (app_log_istr) {
00151         req.EncodeApp_log(*app_log_istr);
00152     }
00153 
00154     if (sys_config_istr) {
00155         req.EncodeSys_config(*sys_config_istr);
00156     }
00157 
00158     ///
00159     /// send the report
00160     ///
00161     TReply reply;
00162     AskFeedback(req, &reply);
00163     LOG_POST(Info << "feedback sent");
00164 }
00165 
00166 void CGBenchService::x_Connect()
00167 {
00168     string url("http://www.ncbi.nlm.nih.gov/projects/gbench/service/gbench_svc.cgi");
00169     //string url("http://iwebdev2/staff/voronov/gbsvc/gbench_svc.cgi");
00170 
00171     x_ConnectURL( url );
00172 }
00173 
00174 
00175 END_objects_SCOPE // namespace ncbi::objects::
00176 
00177 END_NCBI_SCOPE
00178 
00179 /* Original file checksum: lines: 65, chars: 1900, CRC32: 786395d0 */
Modified on Fri Jul 25 19:51:14 2014 by modify_doxy.py rev. 426318