PCL
MetaModule.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.9.3
6 // ----------------------------------------------------------------------------
7 // pcl/MetaModule.h - Released 2025-02-21T12:13:32Z
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-2025 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 
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 
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 
383  int NumberOfProcessors() const;
384 
407  bool GetPhysicalMemoryStatus( size_type& totalBytes, size_type& availableBytes ) const;
408 
423  {
424  size_type dum, availableBytes;
425  if ( GetPhysicalMemoryStatus( dum, availableBytes ) )
426  return availableBytes;
427  return 0;
428  }
429 
442  float PhysicalMemoryLoad() const
443  {
444  size_type totalBytes, availableBytes;
445  if ( GetPhysicalMemoryStatus( totalBytes, availableBytes ) )
446  return float( 1 - double( availableBytes )/totalBytes );
447  return 0;
448  }
449 
465  virtual void* Allocate( size_type sz )
466  {
467  PCL_PRECONDITION( sz != 0 )
468  return reinterpret_cast<void*>( ::operator new( sz ) );
469  }
470 
486  virtual void Deallocate( void* p )
487  {
488  PCL_PRECONDITION( p != nullptr )
489  ::operator delete( p );
490  }
491 
500  virtual void OnLoad()
501  {
502  }
503 
514  virtual void OnUnload()
515  {
516  }
517 
523  bool IsInstalled() const;
524 
559  void ProcessEvents( bool excludeUserInputEvents = false );
560 
631  void LoadResource( const String& filePath, const String& rootPath = String() );
632 
652  void UnloadResource( const String& filePath, const String& rootPath = String() );
653 
690  Variant EvaluateScript( const String& sourceCode, const IsoString& language = IsoString() );
691 
711  bool HasEntitlement( const IsoString& entitlement );
712 
713 private:
714 
715  void PerformAPIDefinitions() const override;
716 
717  friend class APIInitializer;
718 };
719 
720 // ----------------------------------------------------------------------------
721 
722 extern MetaModule* Module;
723 
724 // ----------------------------------------------------------------------------
725 
726 } // pcl
727 
728 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
729 
730 namespace pcl
731 {
732 
733 // ----------------------------------------------------------------------------
734 
752 namespace InstallMode
753 {
754  enum value_type
755  {
756  FullInstall, // Normal, full installation
757  QueryModuleInfo, // Temporary load to gather module properties
758  VerifyModule // Temporary load to verify module integrity
759  };
760 }
761 
762 // ----------------------------------------------------------------------------
763 
775 #define PCL_MODULE_UNIQUE_ID( uid ) \
776  ("PIXINSIGHT_MODULE_UNIQUE_ID_" PCL_STRINGIFY( uid ))
777 
839 #define PCL_MODULE_VERSION( MM, mm, rr, bbbb, lan ) \
840  ("PIXINSIGHT_MODULE_VERSION_" \
841  PCL_STRINGIFY( MM ) "." \
842  PCL_STRINGIFY( mm ) "." \
843  PCL_STRINGIFY( rr ) "." \
844  PCL_STRINGIFY( bbbb ) "." \
845  PCL_STRINGIFY( lan ))
846 
912 #define PCL_MODULE_VERSION_S( MM, mm, rr, bbbb, lan, status ) \
913  ("PIXINSIGHT_MODULE_VERSION_" \
914  PCL_STRINGIFY( MM ) "." \
915  PCL_STRINGIFY( mm ) "." \
916  PCL_STRINGIFY( rr ) "." \
917  PCL_STRINGIFY( bbbb ) "." \
918  PCL_STRINGIFY( lan ) "." \
919  PCL_STRINGIFY( status ))
920 
921 // ----------------------------------------------------------------------------
922 
923 } // pcl
924 
925 // ----------------------------------------------------------------------------
926 
1061 // ----------------------------------------------------------------------------
1062 
1063 // end global namespace
1064 
1065 #endif // __PCL_MetaModule_h
1066 
1067 // ----------------------------------------------------------------------------
1068 // EOF pcl/MetaModule.h - Released 2025-02-21T12:13:32Z
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5445
A formal description of a PixInsight module.
Definition: MetaModule.h:102
void LoadResource(const String &filePath, const String &rootPath=String())
virtual void GetReleaseDate(int &year, int &month, int &day) const
Definition: MetaModule.h:361
virtual IsoString Name() const =0
virtual const char * UniqueId() const
float PhysicalMemoryLoad() const
Definition: MetaModule.h:442
virtual const char * Version() const =0
virtual String TradeMarks() const
Definition: MetaModule.h:328
int NumberOfProcessors() const
virtual String Description() const
Definition: MetaModule.h:276
Variant EvaluateScript(const String &sourceCode, const IsoString &language=IsoString())
virtual void OnUnload()
Definition: MetaModule.h:514
IsoString ReadableVersion() const
void ProcessEvents(bool excludeUserInputEvents=false)
~MetaModule() override
virtual void Deallocate(void *p)
Definition: MetaModule.h:486
bool HasEntitlement(const IsoString &entitlement)
virtual String Copyright() const
Definition: MetaModule.h:316
MetaModule & operator=(const MetaModule &)=delete
MetaModule(const MetaModule &)=delete
bool IsInstalled() const
virtual void * Allocate(size_type sz)
Definition: MetaModule.h:465
bool GetPhysicalMemoryStatus(size_type &totalBytes, size_type &availableBytes) const
virtual String Author() const
Definition: MetaModule.h:303
virtual String Company() const
Definition: MetaModule.h:291
virtual void OnLoad()
Definition: MetaModule.h:500
void UnloadResource(const String &filePath, const String &rootPath=String())
void GetVersion(int &major, int &minor, int &release, int &build, IsoString &language, IsoString &status) const
virtual String OriginalFileName() const
Definition: MetaModule.h:338
size_type AvailablePhysicalMemory() const
Definition: MetaModule.h:422
Root base class for all PixInsight module components.
Definition: MetaObject.h:86
Unicode (UTF-16) string.
Definition: String.h:8148
Acts like a union to store instances of different data types.
Definition: Variant.h:332
size_t size_type
Definition: Defs.h:609
PCL root namespace.
Definition: AbstractImage.h:77