PCL
MetaModule.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/MetaModule.h - Released 2024-05-07T15:27: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-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 
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 
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 
612  void LoadResource( const String& filePath, const String& rootPath = String() );
613 
633  void UnloadResource( const String& filePath, const String& rootPath = String() );
634 
671  Variant EvaluateScript( const String& sourceCode, const IsoString& language = IsoString() );
672 
692  bool HasEntitlement( const IsoString& entitlement );
693 
694 private:
695 
696  void PerformAPIDefinitions() const override;
697 
698  friend class APIInitializer;
699 };
700 
701 // ----------------------------------------------------------------------------
702 
703 extern MetaModule* Module;
704 
705 // ----------------------------------------------------------------------------
706 
707 } // pcl
708 
709 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
710 
711 namespace pcl
712 {
713 
714 // ----------------------------------------------------------------------------
715 
733 namespace InstallMode
734 {
735  enum value_type
736  {
737  FullInstall, // Normal, full installation
738  QueryModuleInfo, // Temporary load to gather module properties
739  VerifyModule // Temporary load to verify module integrity
740  };
741 }
742 
743 // ----------------------------------------------------------------------------
744 
756 #define PCL_MODULE_UNIQUE_ID( uid ) \
757  ("PIXINSIGHT_MODULE_UNIQUE_ID_" PCL_STRINGIFY( uid ))
758 
820 #define PCL_MODULE_VERSION( MM, mm, rr, bbbb, lan ) \
821  ("PIXINSIGHT_MODULE_VERSION_" \
822  PCL_STRINGIFY( MM ) "." \
823  PCL_STRINGIFY( mm ) "." \
824  PCL_STRINGIFY( rr ) "." \
825  PCL_STRINGIFY( bbbb ) "." \
826  PCL_STRINGIFY( lan ))
827 
893 #define PCL_MODULE_VERSION_S( MM, mm, rr, bbbb, lan, status ) \
894  ("PIXINSIGHT_MODULE_VERSION_" \
895  PCL_STRINGIFY( MM ) "." \
896  PCL_STRINGIFY( mm ) "." \
897  PCL_STRINGIFY( rr ) "." \
898  PCL_STRINGIFY( bbbb ) "." \
899  PCL_STRINGIFY( lan ) "." \
900  PCL_STRINGIFY( status ))
901 
902 // ----------------------------------------------------------------------------
903 
904 } // pcl
905 
906 // ----------------------------------------------------------------------------
907 
1042 // ----------------------------------------------------------------------------
1043 
1044 // end global namespace
1045 
1046 #endif // __PCL_MetaModule_h
1047 
1048 // ----------------------------------------------------------------------------
1049 // EOF pcl/MetaModule.h - Released 2024-05-07T15:27:32Z
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5425
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:423
virtual const char * Version() const =0
virtual String TradeMarks() const
Definition: MetaModule.h:328
virtual String Description() const
Definition: MetaModule.h:276
Variant EvaluateScript(const String &sourceCode, const IsoString &language=IsoString())
virtual void OnUnload()
Definition: MetaModule.h:495
IsoString ReadableVersion() const
void ProcessEvents(bool excludeUserInputEvents=false)
~MetaModule() override
virtual void Deallocate(void *p)
Definition: MetaModule.h:467
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:446
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:481
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:403
Root base class for all PixInsight module components.
Definition: MetaObject.h:86
Unicode (UTF-16) string.
Definition: String.h:8113
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