1 #ifndef CORELIB___NCBIAPP_API__HPP
2 #define CORELIB___NCBIAPP_API__HPP
50 #if !defined(NCBI_OS_UNIX) || defined(HAVE_NCBI_C)
54 # define GetArgs GetArgs
114 operator bool(
void)
const {
return m_App !=
nullptr; }
115 bool operator !(
void)
const {
return m_App ==
nullptr; }
173 static SSystemMutex& GetInstanceMutex(
void);
227 const char*
const* argv,
228 const char*
const* envp = 0,
234 #if defined(NCBI_OS_MSWIN) && defined(_UNICODE)
237 const TXChar*
const* argv,
238 const TXChar*
const* envp = 0,
250 virtual void Init(
void);
258 virtual int Run(
void) = 0;
266 virtual int DryRun(
void);
273 virtual void Exit(
void);
296 void SetEnvironment(
const string& name,
const string&
value);
299 bool HasLoadedConfig(
void)
const;
302 bool FinishedLoadingConfig(
void)
const;
318 const string& GetConfigPath(
void)
const;
358 const string& GetProgramDisplayName(
void)
const;
371 static string GetAppName(EAppNameType name_type = eBaseName,
372 int argc = 0,
const char*
const* argv =
NULL);
383 bool IsDryRun(
void)
const;
402 m_OnExitActions.AddAction(func);
407 static CRWLock& GetInstanceLock(
void);
417 virtual EPreparseArgs PreparseArgs(
int argc,
418 const char*
const* argv);
426 fDisableStdArgs = 0x01
429 void DisableArgDescriptions(
TDisableArgDesc disable = fDisableStdArgs);
456 fNoSyncWithStdio = 0x01,
460 fDefault_CinBufferSize = 0x02,
465 fDefault_SyncWithStdio = 0x00,
555 virtual bool LoadConfig(
CNcbiRegistry& reg,
const string* conf,
562 virtual bool LoadConfig(
CNcbiRegistry& reg,
const string* conf);
574 void SetProgramDisplayName(
const string& app_name);
590 static string FindProgramExecutablePath(
int argc,
const char*
const* argv,
591 string* real_path = 0);
597 virtual void AppStart(
void);
603 virtual void AppStop(
int exit_code);
614 void SetExitCode(
int exit_code, EExitMode when = eExceptionalExits);
617 fSkipSafeStaticDestroy = 1 << 0
626 void ExecuteOnExitActions();
654 void x_HonorStandardSettings(
IRegistry* reg = 0);
658 void x_ReadLogOptions();
661 void x_LogOptions(
int event);
671 void x_SetupStdio(
void);
673 void x_AddDefaultArgs(
void);
681 bool* got_exception);
730 virtual void Idle(
void);
830 #ifndef CORELIB___NCBIAPP__HPP
831 # define CNcbiApplication CNcbiApplicationAPI
CNcbiActionGuard class Executes registered callbacks on request or on destruction.
Interface for application idler.
Interface class for Phone Home Policy.
void AddOnExitAction(TFunc func)
Add callback to be executed from CNcbiApplicationAPI destructor.
EHideStdArgs
Which standard flag's descriptions should not be displayed in the usage message.
bool HasLoadedConfig(void) const
Check if the config file has been loaded.
unique_ptr< CNcbiArguments > m_Arguments
Command-line arguments.
bool ReloadConfig(CMetaRegistry::TFlags flags=CMetaRegistry::fReloadIfChanged, IRegistry::TFlags reg_flags=IRegistry::fWithNcbirc)
Reload the configuration file.
CNcbiApplicationAPI * m_App
unique_ptr< CNcbiOstream > m_DiagStream
Opt., aux., see eDS_ToMemory.
int TStdioSetupFlags
Binary OR of "EStdioSetup".
NCBI_EXCEPTION_DEFAULT(CAppException, CCoreException)
string m_ConfigPath
Path to .ini file used.
CNcbiActionGuard m_OnExitActions
Actions executed on app destruction.
TDisableArgDesc m_DisableArgDesc
Arg desc. disabled.
TStdioSetupFlags m_StdioFlags
Std C++ I/O adjustments.
string m_LogFileName
Log file name.
friend class CNcbiApplicationGuard
string m_ProgramDisplayName
Display name of app.
CNcbiApplicationAPI * operator->(void)
virtual int Run(void)=0
Run the application.
int m_LogOptions
logging of env, reg, args, path
void SetAppFlags(TAppFlags flags)
IPhoneHomePolicy * m_PhoneHomePolicy
Pointer to active Phone Home Policy, if any.
string m_ExePath
Program executable path.
const CNcbiEnvironment & GetEnvironment(void) const
Get the application's cached environment.
CNcbiEnvironment & SetEnvironment(void)
Get a non-const copy of the application's cached environment.
const string & GetProgramExecutablePath(EFollowLinks follow_links=eIgnoreLinks) const
Get the application's executable path.
EExitMode
When to return a user-set exit code.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
EStdioSetup
Flags to adjust standard I/O streams' behaviour.
int m_ExitCode
Exit code to force.
char * m_CinBuffer
Cin buffer if changed.
EPreparseArgs
Result of PreparseArgs()
INcbiIdler * GetIdler(EOwnership ownership=eNoOwnership)
Return currently installed idler or NULL.
const char * m_LogFile
Logfile if set in the command line.
EErrCode
Error types that an application can generate.
const CArgDescriptions * GetArgDescriptions(void) const
Get argument descriptions (set by SetupArgDescriptions)
shared_ptr< CReadLockGuard > m_AppLock
unique_ptr< CNcbiEnvironment > m_Environ
Cached application env.
const string & GetConfigPath(void) const
Get the full path to the configuration file (if any) we ended up using.
unique_ptr< CArgs > m_Args
Parsed cmd.-line args.
IPhoneHomePolicy * GetPhoneHomePolicy() const
Return pointer to current Phone Home Policy or NULL.
int THideStdArgs
Binary OR of "EHideStdArgs".
bool FinishedLoadingConfig(void) const
Check if the application has finished loading config file (successfully or not).
EFollowLinks
Whether to follow symbolic links (also known as shortcuts or aliases)
const string & GetProgramDisplayName(void) const
Get the application's "display" name.
bool IsDryRun(void) const
Check if it is a test run.
EExitMode m_ExitCodeCond
When to force it (if ever)
CNcbiRegistry & GetRWConfig(void)
Get the application's cached configuration parameters, accessible for read-write for an application's...
const CNcbiApplicationAPI * Get(void) const
unique_ptr< CArgDescriptions > m_ArgDesc
Cmd.-line arg descriptions.
virtual void Idle(void)=0
EDisableArgDesc
Disable argument descriptions.
int TDisableArgDesc
Binary OR of "EDisableArgDesc".
CNcbiApplicationAPI * Get(void)
CRef< CNcbiRegistry > m_Config
Guaranteed to be non-NULL.
static CNcbiApplicationAPI * m_Instance
Current app. instance.
CNcbiApplicationAPI & operator*(void)
ENcbiOwnership m_PhoneHomePolicy_Ownership
Phone Home Policy ownersheep.
void SetIdler(INcbiIdler *idler, EOwnership ownership=eTakeOwnership)
Set new idler and ownership.
virtual ~CDefaultIdler(void)
virtual ~INcbiIdler(void)
string m_RealExePath
Symlink-free executable path.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
void RunIdler(void)
Execute currently installed idler if any.
bool m_ConfigLoaded
Finished loading config.
THideStdArgs m_HideArgs
Std cmd.-line flags to hide.
string m_DefaultConfig
conf parameter to AppMain
CRef< CVersionAPI > m_Version
Program version.
@ eNoExits
never (stick to existing logic)
@ eExceptionalExits
when an (uncaught) exception occurs
@ ePreparse_Continue
Continue application execution.
@ eUnsetArgs
Command-line argument description not found.
@ eSecond
Second instance of CNcbiApplicationAPI is prohibited.
@ eLoadConfig
Registry data failed to load from config file.
@ eSetupDiag
Application diagnostic stream setup failed.
@ eIgnoreLinks
Do not follow symbolic links.
@ eFollowLinks
Follow symbolic links.
@ eFullName
per GetProgramExecutablePath(eIgnoreLinks)
@ eBaseName
per GetProgramDisplayName
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
@ fHideAll
Hide all standard argument descriptions.
@ fHideFullVersion
Hide full version description.
@ fHideConffile
Hide configuration file description.
@ fHideHelp
Hide help description.
@ fHideXmlHelp
Hide XML help description.
@ fHideLogfile
Hide log file description.
@ fHideVersion
Hide version description.
@ fHideFullHelp
Hide full help description.
@ fHideDryRun
Hide dryrun description.
EAppDiagStream
Where to write the application's diagnostics to.
@ eDS_Default
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
int TFlags
Binary OR of "EFlags".
@ fWithNcbirc
Include .ncbirc (used only by CNcbiReg.)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
NCBI_NS_STD::string::size_type SIZE_TYPE
enum ENcbiOwnership EOwnership
Ownership relations between objects.
ENcbiOwnership
Ownership relations between objects.
#define NCBI_XNCBI_EXPORT
const TYPE & Get(const CNamedParameterList *param)
const string version
version string
const GenericPointer< typename T::ValueType > T2 value
#define GetArgs
Avoid preprocessor name clash with the NCBI C Toolkit.
Defines command line argument related classes.
Defines unified interface to application:
Define IPhoneHomePolicy, interface class for Phone Home Policy.
This class allows to add build info (date and tag) to application version.