1. --   (c) Copyright, Real-Time Innovations, 2025. 
  2. --   All rights reserved. 
  3. --   No duplications, whole or partial, manual or electronic, may be made 
  4. --   without express written permission.  Any such copies, or 
  5. --   revisions thereof, must display this notice unaltered. 
  6. --   This code contains trade secrets of Real-Time Innovations, Inc. 
  7.  
  8.  
  9. with RTIDDS.Obj_Impl; 
  10. with Interfaces.C_Streams; 
  11. with RTIDDS.Low_Level.ndds_ndds_config_c_h; 
  12. package DDS.Logger is 
  13.    type Ref (<>) is new RTIDDS.Obj_Impl.Ref with private; 
  14.    type Ref_Access is access all Ref'Class; 
  15.  
  16.  
  17.    function Get_Instance return Ref_Access; 
  18.    --  <dref>Logger_get_instance</dref> 
  19.  
  20.    function Get_Verbosity (This : not null access Ref) return LogVerbosity; 
  21.    --  <dref>Logger_get_verbosity</dref> 
  22.  
  23.    function Get_Verbosity (This                      :    not null access Ref; 
  24.                            Category                  : in LogCategory) return LogVerbosity; 
  25.    --  <dref>Logger_get_verbosity_by_category</dref> 
  26.  
  27.    procedure Set_Verbosity (This                       :    not null access Ref; 
  28.                             Verbosity                  : in LogVerbosity); 
  29.    --  <dref>Logger_set_verbosity</dref> 
  30.  
  31.    procedure Set_Verbosity (This                       :    not null access Ref; 
  32.                             Category                   : in LogCategory; 
  33.                             Verbosity                  : in LogVerbosity); 
  34.    --  <dref>Logger_set_verbosity_by_category</dref> 
  35.  
  36.    function Get_Print_Format (This : not null access Ref) return LogPrintFormat; 
  37.    --  <dref>Logger_get_print_format</dref> 
  38.  
  39.    procedure Set_Print_Format (This : not null access Ref; Format : LogPrintFormat); 
  40.    --  <dref>Logger_set_print_format</dref> 
  41.  
  42.  
  43.    function Get_Output_File 
  44.      (This : not null access Ref) return Interfaces.C_Streams.FILEs; 
  45.    --  Get the file to which the logged output is redirected. 
  46.    --  If no output file has been registered through set_output_file, 
  47.    --  this function will return NULL. In this case, 
  48.    --  logged output will on most platforms go to standard out. 
  49.  
  50.    procedure Set_Output_File 
  51.      (This : not null access Ref; To : Interfaces.C_Streams.FILEs); 
  52.    --  Set the file to which the logged output is redirected. 
  53.    --  The file passed may be NULL, in which case further logged output 
  54.    --  will be redirected to the platform-specific default output location 
  55.    --  (standard out on most platforms). 
  56.    --  For better performance when log messages are generated frequently, 
  57.    --  the log messages are not flushed into a file immediately after they 
  58.    --  are generated. In other words, while writing a log message, 
  59.    --  RTI Connext only calls the function fwrite() 
  60.    --  (see https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html); 
  61.    --  it does not call the function fflush() 
  62.    --  (see https://pubs.opengroup.org/onlinepubs/009695399/functions/fflush.html). 
  63.    --  If your application requires a different flushing behavior, 
  64.    --  you may use set_output_device to configure a custom logging device. 
  65.  
  66.    procedure Set_Output_File_Name 
  67.      (This : not null access Ref; File_Name : Standard.String); 
  68.    --  Set the name of the file to which the logged output is redirected. 
  69.    --  The name may be NULL, in which case further logged output will be 
  70.    --  redirected to the platform-specific default output location 
  71.    --  (standard out on most platforms). 
  72.    --  See output_file for the flushing behavior. 
  73.  
  74.    procedure Set_Output_File_Set 
  75.      (This : not null access Ref; 
  76.       File_Preffix   : Standard.String; 
  77.       File_Suffix    : Standard.String; 
  78.       Max_Capacity   : Natural; 
  79.       Max_Files      : Natural); 
  80.    --  Configure a set of files to redirect the logged output. 
  81.    --  The logged output will be redirected to a set of files whose names are 
  82.    --  configured with a prefix and a suffix. 
  83.    --  The maximum number of bytes configures how many bytes to write into 
  84.    --  a file before opening the next file. After reaching the maximum number 
  85.    --  of files, the first one is overwritten. 
  86.    --  For example, if the prefix is 'Foo', the suffix is '.txt', 
  87.    --  the max number of bytes is 1GB, and the max number of files is 3, 
  88.    --  the logger will create (at most) these files: 
  89.    --     Foo1.txt, Foo2.txt, and Foo3.txt. 
  90.    --  It will write to Foo1.txt, and after writing 1GB, 
  91.    --  it will move on to Foo2.txt, then to Foo3.txt, then to Foo1.txt again, 
  92.    --  and so on. 
  93.    --  To stop logging to these files and redirect the output to the 
  94.    --  platform-specific location, pass "", "", 0, 0. 
  95.  
  96.    --  See DDS.Logger.set_output_file for the flushing behavior. 
  97.  
  98.  
  99.    type LoggerDevice_Interface is limited interface; 
  100.    type LoggerDevice_Interface_Access is access all LoggerDevice_Interface'Class; 
  101.    procedure Write (Self : not null access LoggerDevice_Interface; Text : Standard.String; Level : LogVerbosity) is abstract; 
  102.    procedure Close (Self : not null access LoggerDevice_Interface) is null; 
  103.  
  104.  
  105.    function GetLogger 
  106.      (Self : access LoggerDevice_Interface) return DDS.Logger.Ref_Access is abstract; 
  107.  
  108.    procedure Set_Output_Device (Self                           : not null access DDS.Logger.Ref; 
  109.                                 Device                         : access LoggerDevice_Interface'Class); 
  110.    function GetDevice 
  111.      (Self : access LoggerDevice_Interface) return access 
  112.      RTIDDS.Low_Level.ndds_ndds_config_c_h.NDDS_Config_LoggerDevice is abstract; 
  113. private 
  114.    type Ref is new RTIDDS.Obj_Impl.Ref with null record; 
  115.  
  116.    procedure SetInterface (Self : not null access DDS.Logger.Ref; To : access RTIDDS.Low_Level.ndds_ndds_config_c_h.NDDS_Config_Logger); 
  117.    function GetInterface (Self : not null access DDS.Logger.Ref) return access RTIDDS.Low_Level.ndds_ndds_config_c_h.NDDS_Config_Logger; 
  118. end DDS.Logger;