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

Go to the SVN repository for this file.

1 /* $Id: test_app_job.cpp 45952 2021-01-20 14:06:56Z 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  * Authors: Andrey Yazhuk
27  *
28  * File Description:
29  */
30 
31 #include <ncbi_pch.hpp>
32 
33 #include <corelib/ncbiapp.hpp>
34 #include <corelib/ncbienv.hpp>
35 #include <corelib/ncbiargs.hpp>
36 
37 #include <corelib/ncbi_system.hpp>
38 
39 #include <gui/utils/app_job.hpp>
42 //#include <gui/objutils/object_manager_engine.hpp>
44 
45 #include "test_client.hpp"
46 
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// CAppJobTestApplication
52 {
53 public:
54 
55  virtual void Init(void);
56  virtual int Run(void);
57  virtual void Exit(void);
58 
59  void CreateClients();
60  void ClientsPoll();
61 
64 };
65 
66 
67 
69 {
70  // Create command-line argument descriptions class
71  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
72 
73  // Specify USAGE context
74  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
75  "CLabel label interface test application");
76 
77  // Setup arg.descriptions for this application
78  SetupArgDescriptions(arg_desc.release());
79 }
80 
81 
83 {
84  // Get arguments
85  // const CArgs& args = GetArgs();
86 
87  m_Disp.RegisterEngine("ThreadPool", *new CThreadPoolEngine(2, 1000));
88  //m_Disp.RegisterEngine("ObjectManager", *new CObjectManagerEngine());
89  m_Disp.RegisterEngine("Scheduler", *new CSchedulerEngine());
90 
91  CreateClients();
92 
93  int delay = 400;
94  for(int i = 0; i < 100; i++ ) {
95  SleepMilliSec(delay);
96 
97  // let Clients to query the dispatcher
98  ClientsPoll();
99 
100  SleepMilliSec(delay);
101 
103 
104  SleepMilliSec(delay);
105 
106  if( i == 5 ) {
108  }
109  /// to pump Application Event Queue
111  }
112 
113  return 0;
114 }
115 
116 
118 {
120  m_Client1->StartJobs(3);
121 }
122 
123 
125 {
128 }
129 
130 
131 /////////////////////////////////////////////////////////////////////////////
132 // Cleanup
133 
134 
136 {
137  SetDiagStream(0);
138 }
139 
140 
141 /////////////////////////////////////////////////////////////////////////////
142 // MAIN
143 
144 
145 int NcbiSys_main(int argc, ncbi::TXChar* argv[])
146 {
147  // Execute main application function
148  return CAppJobTestApplication().AppMain(argc, argv);
149 }
CAppJobDispatcher.
CAppJobTestApplication.
CAppJobDispatcher m_Disp
virtual int Run(void)
Run the application.
CPrimeNumberClient * m_Client1
virtual void Init(void)
Initialize the application.
virtual void Exit(void)
Cleanup on application exit.
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CPrimeNumberClient.
Definition: test_client.hpp:79
void StartJobs(int n)
CSchedulerEngine CSchedulerEngine is an engine that can be used with CAppJobDispatcher.
CThreadPoolEngine.
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
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
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
static bool HandlePostRequest()
bool IdleCallback()
this function shall be called in the the application idle function.
bool RegisterEngine(const string &name, IAppJobEngine &engine)
Registers a new Engine, returns true if successful.
char TXChar
Definition: ncbistr.hpp:172
int i
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
USING_NCBI_SCOPE
Modified on Thu May 02 14:34:40 2024 by modify_doxy.py rev. 669887