PCL
MetaModule.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/MetaModule.h - Released 2024-01-13T15:47:58Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_MetaModule_h
53 #define __PCL_MetaModule_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 #include <pcl/Diagnostics.h>
61 
62 #include <pcl/MetaObject.h>
63 #include <pcl/String.h>
64 #include <pcl/Variant.h>
65 
66 namespace pcl
67 {
68 
69 // ----------------------------------------------------------------------------
70 
101 class MetaModule : public MetaObject
102 {
103 public:
104 
108  MetaModule();
109 
116  ~MetaModule() override;
117 
122  MetaModule( const MetaModule& ) = delete;
123 
128  MetaModule& operator =( const MetaModule& ) = delete;
129 
134  virtual const char* UniqueId() const;
135 
195  virtual const char* Version() const = 0;
196 
225  void GetVersion( int& major, int& minor, int& release, int& build,
226  IsoString& language, IsoString& status ) const;
227 
240  IsoString ReadableVersion() const;
241 
256  virtual IsoString Name() const = 0;
257 
276  virtual String Description() const
277  {
278  return String();
279  }
280 
291  virtual String Company() const
292  {
293  return String();
294  }
295 
303  virtual String Author() const
304  {
305  return String();
306  }
307 
316  virtual String Copyright() const
317  {
318  return String();
319  }
320 
328  virtual String TradeMarks() const
329  {
330  return String();
331  }
332 
338  virtual String OriginalFileName() const
339  {
340  return String();
341  }
342 
361  virtual void GetReleaseDate( int& year, int& month, int& day ) const
362  {
363  year = month = day = 0; // unspecified
364  }
365 
388  bool GetPhysicalMemoryStatus( size_type& totalBytes, size_type& availableBytes ) const;
389 
404  {
405  size_type dum, availableBytes;
406  if ( GetPhysicalMemoryStatus( dum, availableBytes ) )
407  return availableBytes;
408  return 0;
409  }
410 
423  float PhysicalMemoryLoad() const
424  {
425  size_type totalBytes, availableBytes;
426  if ( GetPhysicalMemoryStatus( totalBytes, availableBytes ) )
427  return float( 1 - double( availableBytes )/totalBytes );
428  return 0;
429  }
430 
446  virtual void* Allocate( size_type sz )
447  {
448  PCL_PRECONDITION( sz != 0 )
449  return reinterpret_cast<void*>( ::operator new( sz ) );
450  }
451 
467  virtual void Deallocate( void* p )
468  {
469  PCL_PRECONDITION( p != nullptr )
470  ::operator delete( p );
471  }
472 
481  virtual void OnLoad()
482  {
483  }
484 
495  virtual void OnUnload()
496  {
497  }
498 
504  bool IsInstalled() const;
505 
540  void ProcessEvents( bool excludeUserInputEvents = false );
541 
608  void LoadResource( const String& filePath, const String& rootPath = String() );
609 
625  void UnloadResource( const String& filePath, const String& rootPath = String() );
626 
663  Variant EvaluateScript( const String& sourceCode, const IsoString& language = IsoString() );
664 
680  bool HasEntitlement( const IsoString& entitlement );
681 
682 private:
683 
684  void PerformAPIDefinitions() const override;
685 
686  friend class APIInitializer;
687 };
688 
689 // ----------------------------------------------------------------------------
690 
691 extern MetaModule* Module;
692 
693 // ----------------------------------------------------------------------------
694 
695 } // pcl
696 
697 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
698 
699 namespace pcl
700 {
701 
702 // ----------------------------------------------------------------------------
703 
721 namespace InstallMode
722 {
723  enum value_type
724  {
725  FullInstall, // Normal, full installation
726  QueryModuleInfo, // Temporary load to gather module properties
727  VerifyModule // Temporary load to verify module integrity
728  };
729 }
730 
731 // ----------------------------------------------------------------------------
732 
744 #define PCL_MODULE_UNIQUE_ID( uid ) \
745  ("PIXINSIGHT_MODULE_UNIQUE_ID_" PCL_STRINGIFY( uid ))
746 
808 #define PCL_MODULE_VERSION( MM, mm, rr, bbbb, lan ) \
809  ("PIXINSIGHT_MODULE_VERSION_" \
810  PCL_STRINGIFY( MM ) "." \
811  PCL_STRINGIFY( mm ) "." \
812  PCL_STRINGIFY( rr ) "." \
813  PCL_STRINGIFY( bbbb ) "." \
814  PCL_STRINGIFY( lan ))
815 
881 #define PCL_MODULE_VERSION_S( MM, mm, rr, bbbb, lan, status ) \
882  ("PIXINSIGHT_MODULE_VERSION_" \
883  PCL_STRINGIFY( MM ) "." \
884  PCL_STRINGIFY( mm ) "." \
885  PCL_STRINGIFY( rr ) "." \
886  PCL_STRINGIFY( bbbb ) "." \
887  PCL_STRINGIFY( lan ) "." \
888  PCL_STRINGIFY( status ))
889 
890 // ----------------------------------------------------------------------------
891 
892 } // pcl
893 
894 // ----------------------------------------------------------------------------
895 
1030 // ----------------------------------------------------------------------------
1031 
1032 // end global namespace
1033 
1034 #endif // __PCL_MetaModule_h
1035 
1036 // ----------------------------------------------------------------------------
1037 // EOF pcl/MetaModule.h - Released 2024-01-13T15:47:58Z
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::MetaModule::Company
virtual String Company() const
Definition: MetaModule.h:291
pcl::MetaModule::Deallocate
virtual void Deallocate(void *p)
Definition: MetaModule.h:467
pcl::MetaModule::Allocate
virtual void * Allocate(size_type sz)
Definition: MetaModule.h:446
pcl::MetaModule::HasEntitlement
bool HasEntitlement(const IsoString &entitlement)
pcl::MetaModule::UniqueId
virtual const char * UniqueId() const
pcl::String
Unicode (UTF-16) string.
Definition: String.h:8112
pcl::Variant
Acts like a union to store instances of different data types.
Definition: Variant.h:331
pcl::MetaModule::OnUnload
virtual void OnUnload()
Definition: MetaModule.h:495
pcl::IsoString
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5424
pcl::MetaModule::OnLoad
virtual void OnLoad()
Definition: MetaModule.h:481
pcl::MetaModule::Copyright
virtual String Copyright() const
Definition: MetaModule.h:316
pcl::MetaModule::EvaluateScript
Variant EvaluateScript(const String &sourceCode, const IsoString &language=IsoString())
pcl::MetaModule::TradeMarks
virtual String TradeMarks() const
Definition: MetaModule.h:328
pcl::MetaModule::ReadableVersion
IsoString ReadableVersion() const
pcl::MetaModule::Description
virtual String Description() const
Definition: MetaModule.h:276
pcl::MetaModule::operator=
MetaModule & operator=(const MetaModule &)=delete
MetaObject.h
pcl::MetaModule::Version
virtual const char * Version() const =0
pcl::MetaModule::LoadResource
void LoadResource(const String &filePath, const String &rootPath=String())
pcl::size_type
size_t size_type
Definition: Defs.h:612
pcl::MetaModule::PhysicalMemoryLoad
float PhysicalMemoryLoad() const
Definition: MetaModule.h:423
pcl::MetaModule::ProcessEvents
void ProcessEvents(bool excludeUserInputEvents=false)
pcl::MetaModule::MetaModule
MetaModule()
pcl::MetaModule::GetPhysicalMemoryStatus
bool GetPhysicalMemoryStatus(size_type &totalBytes, size_type &availableBytes) const
pcl::MetaModule::GetReleaseDate
virtual void GetReleaseDate(int &year, int &month, int &day) const
Definition: MetaModule.h:361
pcl::MetaModule
A formal description of a PixInsight module.
Definition: MetaModule.h:101
pcl::MetaModule::Author
virtual String Author() const
Definition: MetaModule.h:303
pcl::MetaModule::GetVersion
void GetVersion(int &major, int &minor, int &release, int &build, IsoString &language, IsoString &status) const
pcl::MetaModule::~MetaModule
~MetaModule() override
pcl::MetaObject
Root base class for all PixInsight module components.
Definition: MetaObject.h:85
Variant.h
pcl::MetaModule::IsInstalled
bool IsInstalled() const
String.h
pcl::MetaModule::UnloadResource
void UnloadResource(const String &filePath, const String &rootPath=String())
pcl::MetaModule::OriginalFileName
virtual String OriginalFileName() const
Definition: MetaModule.h:338
pcl::MetaModule::AvailablePhysicalMemory
size_type AvailablePhysicalMemory() const
Definition: MetaModule.h:403
Defs.h
pcl::MetaModule::Name
virtual IsoString Name() const =0