View Javadoc
1   /*
2    * Copyright 2021-2025 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.jna.platform.mac;
6   
7   import com.sun.jna.Native;
8   
9   /**
10   * CoreFoundation class. This class should be considered non-API as it may be removed if/when its code is incorporated
11   * into the JNA project.
12   */
13  public interface CoreFoundation extends com.sun.jna.platform.mac.CoreFoundation {
14  
15      CoreFoundation INSTANCE = Native.load("CoreFoundation", CoreFoundation.class);
16  
17      /**
18       * The CFLocale opaque type provides support for obtaining available locales, obtaining localized locale names, and
19       * converting among locale data formats.
20       */
21      class CFLocale extends CFTypeRef {
22      }
23  
24      /**
25       * Returns a copy of the logical locale for the current user.
26       *
27       * @return The logical locale for the current user that is formed from the settings for the current user’s chosen
28       *         system locale overlaid with any custom settings the user has specified in System Preferences. May return
29       *         a retained cached object, not a new object.
30       *         <p>
31       *         This reference must be released with {@link #CFRelease} to avoid leaking references.
32       */
33      CFLocale CFLocaleCopyCurrent();
34  
35      /**
36       * CFDateFormatter objects format the textual representations of CFDate and CFAbsoluteTime objects, and convert
37       * textual representations of dates and times into CFDate and CFAbsoluteTime objects.
38       */
39      class CFDateFormatter extends CFTypeRef {
40      }
41  
42      /**
43       * Enum of values used for {@link CFDateFormatterStyle} in {@link #CFDateFormatterCreate}. Use
44       * {@link CFDateFormatterStyle#index} for the expected integer value corresponding to the C-style enum.
45       */
46      enum CFDateFormatterStyle {
47          kCFDateFormatterNoStyle, kCFDateFormatterShortStyle, kCFDateFormatterMediumStyle, kCFDateFormatterLongStyle,
48          kCFDateFormatterFullStyle;
49  
50          /**
51           * Style for the type of {@link CFDateFormatterStyle} stored.
52           *
53           * @return a {@link CFIndex} representing the enum ordinal.
54           */
55          public CFIndex index() {
56              return new CFIndex(this.ordinal());
57          }
58      }
59  
60      /**
61       * Creates a new CFDateFormatter object, localized to the given locale, which will format dates to the given date
62       * and time styles.
63       *
64       * @param allocator The allocator to use to allocate memory for the new object. Pass {@code null} or
65       *                  {@code kCFAllocatorDefault} to use the current default allocator.
66       * @param locale    The locale to use for localization. If {@code null} uses the default system locale. Use
67       *                  {@link #CFLocaleCopyCurrent()} to specify the locale of the current user.
68       * @param dateStyle The date style to use when formatting dates.
69       * @param timeStyle The time style to use when formatting times.
70       * @return A new date formatter, localized to the given locale, which will format dates to the given date and time
71       *         styles. Returns {@code null} if there was a problem creating the object.
72       *         <p>
73       *         This reference must be released with {@link #CFRelease} to avoid leaking references.
74       */
75      CFDateFormatter CFDateFormatterCreate(CFAllocatorRef allocator, CFLocale locale, CFIndex dateStyle,
76              CFIndex timeStyle);
77  
78      /**
79       * Returns a format string for the given date formatter object.
80       *
81       * @param formatter The date formatter to examine.
82       * @return The format string for {@code formatter}.
83       */
84      CFStringRef CFDateFormatterGetFormat(CFDateFormatter formatter);
85  }