xref: /aosp_15_r20/external/icu/libicu/cts_headers/serv.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /**
4*0e209d39SAndroid Build Coastguard Worker  *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker  * Copyright (C) 2001-2011, International Business Machines Corporation.       *
6*0e209d39SAndroid Build Coastguard Worker  * All Rights Reserved.                                                        *
7*0e209d39SAndroid Build Coastguard Worker  *******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker  */
9*0e209d39SAndroid Build Coastguard Worker 
10*0e209d39SAndroid Build Coastguard Worker #ifndef ICUSERV_H
11*0e209d39SAndroid Build Coastguard Worker #define ICUSERV_H
12*0e209d39SAndroid Build Coastguard Worker 
13*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
14*0e209d39SAndroid Build Coastguard Worker 
15*0e209d39SAndroid Build Coastguard Worker #if UCONFIG_NO_SERVICE
16*0e209d39SAndroid Build Coastguard Worker 
17*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker /*
20*0e209d39SAndroid Build Coastguard Worker  * Allow the declaration of APIs with pointers to ICUService
21*0e209d39SAndroid Build Coastguard Worker  * even when service is removed from the build.
22*0e209d39SAndroid Build Coastguard Worker  */
23*0e209d39SAndroid Build Coastguard Worker class ICUService;
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker #else
28*0e209d39SAndroid Build Coastguard Worker 
29*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
30*0e209d39SAndroid Build Coastguard Worker #include "unicode/locid.h"
31*0e209d39SAndroid Build Coastguard Worker #include "unicode/umisc.h"
32*0e209d39SAndroid Build Coastguard Worker 
33*0e209d39SAndroid Build Coastguard Worker #include "hash.h"
34*0e209d39SAndroid Build Coastguard Worker #include "uvector.h"
35*0e209d39SAndroid Build Coastguard Worker #include "servnotf.h"
36*0e209d39SAndroid Build Coastguard Worker 
37*0e209d39SAndroid Build Coastguard Worker class ICUServiceTest;
38*0e209d39SAndroid Build Coastguard Worker 
39*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
40*0e209d39SAndroid Build Coastguard Worker 
41*0e209d39SAndroid Build Coastguard Worker class ICUServiceKey;
42*0e209d39SAndroid Build Coastguard Worker class ICUServiceFactory;
43*0e209d39SAndroid Build Coastguard Worker class SimpleFactory;
44*0e209d39SAndroid Build Coastguard Worker class ServiceListener;
45*0e209d39SAndroid Build Coastguard Worker class ICUService;
46*0e209d39SAndroid Build Coastguard Worker 
47*0e209d39SAndroid Build Coastguard Worker class DNCache;
48*0e209d39SAndroid Build Coastguard Worker 
49*0e209d39SAndroid Build Coastguard Worker /*******************************************************************
50*0e209d39SAndroid Build Coastguard Worker  * ICUServiceKey
51*0e209d39SAndroid Build Coastguard Worker  */
52*0e209d39SAndroid Build Coastguard Worker 
53*0e209d39SAndroid Build Coastguard Worker /**
54*0e209d39SAndroid Build Coastguard Worker  * <p>ICUServiceKeys are used to communicate with factories to
55*0e209d39SAndroid Build Coastguard Worker  * generate an instance of the service.  ICUServiceKeys define how
56*0e209d39SAndroid Build Coastguard Worker  * ids are canonicalized, provide both a current id and a current
57*0e209d39SAndroid Build Coastguard Worker  * descriptor to use in querying the cache and factories, and
58*0e209d39SAndroid Build Coastguard Worker  * determine the fallback strategy.</p>
59*0e209d39SAndroid Build Coastguard Worker  *
60*0e209d39SAndroid Build Coastguard Worker  * <p>ICUServiceKeys provide both a currentDescriptor and a currentID.
61*0e209d39SAndroid Build Coastguard Worker  * The descriptor contains an optional prefix, followed by '/'
62*0e209d39SAndroid Build Coastguard Worker  * and the currentID.  Factories that handle complex keys,
63*0e209d39SAndroid Build Coastguard Worker  * for example number format factories that generate multiple
64*0e209d39SAndroid Build Coastguard Worker  * kinds of formatters for the same locale, use the descriptor
65*0e209d39SAndroid Build Coastguard Worker  * to provide a fully unique identifier for the service object,
66*0e209d39SAndroid Build Coastguard Worker  * while using the currentID (in this case, the locale string),
67*0e209d39SAndroid Build Coastguard Worker  * as the visible IDs that can be localized.</p>
68*0e209d39SAndroid Build Coastguard Worker  *
69*0e209d39SAndroid Build Coastguard Worker  * <p>The default implementation of ICUServiceKey has no fallbacks and
70*0e209d39SAndroid Build Coastguard Worker  * has no custom descriptors.</p>
71*0e209d39SAndroid Build Coastguard Worker  */
72*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API ICUServiceKey : public UObject {
73*0e209d39SAndroid Build Coastguard Worker  private:
74*0e209d39SAndroid Build Coastguard Worker   const UnicodeString _id;
75*0e209d39SAndroid Build Coastguard Worker 
76*0e209d39SAndroid Build Coastguard Worker  protected:
77*0e209d39SAndroid Build Coastguard Worker   static const char16_t PREFIX_DELIMITER;
78*0e209d39SAndroid Build Coastguard Worker 
79*0e209d39SAndroid Build Coastguard Worker  public:
80*0e209d39SAndroid Build Coastguard Worker 
81*0e209d39SAndroid Build Coastguard Worker   /**
82*0e209d39SAndroid Build Coastguard Worker    * <p>Construct a key from an id.</p>
83*0e209d39SAndroid Build Coastguard Worker    *
84*0e209d39SAndroid Build Coastguard Worker    * @param id the ID from which to construct the key.
85*0e209d39SAndroid Build Coastguard Worker    */
86*0e209d39SAndroid Build Coastguard Worker   ICUServiceKey(const UnicodeString& id);
87*0e209d39SAndroid Build Coastguard Worker 
88*0e209d39SAndroid Build Coastguard Worker   /**
89*0e209d39SAndroid Build Coastguard Worker    * <p>Virtual destructor.</p>
90*0e209d39SAndroid Build Coastguard Worker    */
91*0e209d39SAndroid Build Coastguard Worker   virtual ~ICUServiceKey();
92*0e209d39SAndroid Build Coastguard Worker 
93*0e209d39SAndroid Build Coastguard Worker  /**
94*0e209d39SAndroid Build Coastguard Worker   * <p>Return the original ID used to construct this key.</p>
95*0e209d39SAndroid Build Coastguard Worker   *
96*0e209d39SAndroid Build Coastguard Worker   * @return the ID used to construct this key.
97*0e209d39SAndroid Build Coastguard Worker   */
98*0e209d39SAndroid Build Coastguard Worker   virtual const UnicodeString& getID() const;
99*0e209d39SAndroid Build Coastguard Worker 
100*0e209d39SAndroid Build Coastguard Worker  /**
101*0e209d39SAndroid Build Coastguard Worker   * <p>Return the canonical version of the original ID.  This implementation
102*0e209d39SAndroid Build Coastguard Worker   * appends the original ID to result.  Result is returned as a convenience.</p>
103*0e209d39SAndroid Build Coastguard Worker   *
104*0e209d39SAndroid Build Coastguard Worker   * @param result the output parameter to which the id will be appended.
105*0e209d39SAndroid Build Coastguard Worker   * @return the modified result.
106*0e209d39SAndroid Build Coastguard Worker   */
107*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& canonicalID(UnicodeString& result) const;
108*0e209d39SAndroid Build Coastguard Worker 
109*0e209d39SAndroid Build Coastguard Worker  /**
110*0e209d39SAndroid Build Coastguard Worker   * <p>Return the (canonical) current ID.  This implementation appends
111*0e209d39SAndroid Build Coastguard Worker   * the canonical ID to result.  Result is returned as a convenience.</p>
112*0e209d39SAndroid Build Coastguard Worker   *
113*0e209d39SAndroid Build Coastguard Worker   * @param result the output parameter to which the current id will be appended.
114*0e209d39SAndroid Build Coastguard Worker   * @return the modified result.
115*0e209d39SAndroid Build Coastguard Worker   */
116*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& currentID(UnicodeString& result) const;
117*0e209d39SAndroid Build Coastguard Worker 
118*0e209d39SAndroid Build Coastguard Worker  /**
119*0e209d39SAndroid Build Coastguard Worker   * <p>Return the current descriptor.  This implementation appends
120*0e209d39SAndroid Build Coastguard Worker   * the current descriptor to result.  Result is returned as a convenience.</p>
121*0e209d39SAndroid Build Coastguard Worker   *
122*0e209d39SAndroid Build Coastguard Worker   * <p>The current descriptor is used to fully
123*0e209d39SAndroid Build Coastguard Worker   * identify an instance of the service in the cache.  A
124*0e209d39SAndroid Build Coastguard Worker   * factory may handle all descriptors for an ID, or just a
125*0e209d39SAndroid Build Coastguard Worker   * particular descriptor.  The factory can either parse the
126*0e209d39SAndroid Build Coastguard Worker   * descriptor or use custom API on the key in order to
127*0e209d39SAndroid Build Coastguard Worker   * instantiate the service.</p>
128*0e209d39SAndroid Build Coastguard Worker   *
129*0e209d39SAndroid Build Coastguard Worker   * @param result the output parameter to which the current id will be appended.
130*0e209d39SAndroid Build Coastguard Worker   * @return the modified result.
131*0e209d39SAndroid Build Coastguard Worker   */
132*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& currentDescriptor(UnicodeString& result) const;
133*0e209d39SAndroid Build Coastguard Worker 
134*0e209d39SAndroid Build Coastguard Worker  /**
135*0e209d39SAndroid Build Coastguard Worker   * <p>If the key has a fallback, modify the key and return true,
136*0e209d39SAndroid Build Coastguard Worker   * otherwise return false.  The current ID will change if there
137*0e209d39SAndroid Build Coastguard Worker   * is a fallback.  No currentIDs should be repeated, and fallback
138*0e209d39SAndroid Build Coastguard Worker   * must eventually return false.  This implementation has no fallbacks
139*0e209d39SAndroid Build Coastguard Worker   * and always returns false.</p>
140*0e209d39SAndroid Build Coastguard Worker   *
141*0e209d39SAndroid Build Coastguard Worker   * @return true if the ICUServiceKey changed to a valid fallback value.
142*0e209d39SAndroid Build Coastguard Worker   */
143*0e209d39SAndroid Build Coastguard Worker   virtual UBool fallback();
144*0e209d39SAndroid Build Coastguard Worker 
145*0e209d39SAndroid Build Coastguard Worker  /**
146*0e209d39SAndroid Build Coastguard Worker   * <p>Return true if a key created from id matches, or would eventually
147*0e209d39SAndroid Build Coastguard Worker   * fallback to match, the canonical ID of this ICUServiceKey.</p>
148*0e209d39SAndroid Build Coastguard Worker   *
149*0e209d39SAndroid Build Coastguard Worker   * @param id the id to test.
150*0e209d39SAndroid Build Coastguard Worker   * @return true if this ICUServiceKey's canonical ID is a fallback of id.
151*0e209d39SAndroid Build Coastguard Worker   */
152*0e209d39SAndroid Build Coastguard Worker   virtual UBool isFallbackOf(const UnicodeString& id) const;
153*0e209d39SAndroid Build Coastguard Worker 
154*0e209d39SAndroid Build Coastguard Worker  /**
155*0e209d39SAndroid Build Coastguard Worker   * <p>Return the prefix.  This implementation leaves result unchanged.
156*0e209d39SAndroid Build Coastguard Worker   * Result is returned as a convenience.</p>
157*0e209d39SAndroid Build Coastguard Worker   *
158*0e209d39SAndroid Build Coastguard Worker   * @param result the output parameter to which the prefix will be appended.
159*0e209d39SAndroid Build Coastguard Worker   * @return the modified result.
160*0e209d39SAndroid Build Coastguard Worker   */
161*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& prefix(UnicodeString& result) const;
162*0e209d39SAndroid Build Coastguard Worker 
163*0e209d39SAndroid Build Coastguard Worker  /**
164*0e209d39SAndroid Build Coastguard Worker   * <p>A utility to parse the prefix out of a descriptor string.  Only
165*0e209d39SAndroid Build Coastguard Worker   * the (undelimited) prefix, if any, remains in result.  Result is returned as a
166*0e209d39SAndroid Build Coastguard Worker   * convenience.</p>
167*0e209d39SAndroid Build Coastguard Worker   *
168*0e209d39SAndroid Build Coastguard Worker   * @param result an input/output parameter that on entry is a descriptor, and
169*0e209d39SAndroid Build Coastguard Worker   * on exit is the prefix of that descriptor.
170*0e209d39SAndroid Build Coastguard Worker   * @return the modified result.
171*0e209d39SAndroid Build Coastguard Worker   */
172*0e209d39SAndroid Build Coastguard Worker   static UnicodeString& parsePrefix(UnicodeString& result);
173*0e209d39SAndroid Build Coastguard Worker 
174*0e209d39SAndroid Build Coastguard Worker   /**
175*0e209d39SAndroid Build Coastguard Worker   * <p>A utility to parse the suffix out of a descriptor string.  Only
176*0e209d39SAndroid Build Coastguard Worker   * the (undelimited) suffix, if any, remains in result.  Result is returned as a
177*0e209d39SAndroid Build Coastguard Worker   * convenience.</p>
178*0e209d39SAndroid Build Coastguard Worker   *
179*0e209d39SAndroid Build Coastguard Worker   * @param result an input/output parameter that on entry is a descriptor, and
180*0e209d39SAndroid Build Coastguard Worker   * on exit is the suffix of that descriptor.
181*0e209d39SAndroid Build Coastguard Worker   * @return the modified result.
182*0e209d39SAndroid Build Coastguard Worker   */
183*0e209d39SAndroid Build Coastguard Worker   static UnicodeString& parseSuffix(UnicodeString& result);
184*0e209d39SAndroid Build Coastguard Worker 
185*0e209d39SAndroid Build Coastguard Worker public:
186*0e209d39SAndroid Build Coastguard Worker   /**
187*0e209d39SAndroid Build Coastguard Worker    * UObject RTTI boilerplate.
188*0e209d39SAndroid Build Coastguard Worker    */
189*0e209d39SAndroid Build Coastguard Worker   static UClassID U_EXPORT2 getStaticClassID();
190*0e209d39SAndroid Build Coastguard Worker 
191*0e209d39SAndroid Build Coastguard Worker   /**
192*0e209d39SAndroid Build Coastguard Worker    * UObject RTTI boilerplate.
193*0e209d39SAndroid Build Coastguard Worker    */
194*0e209d39SAndroid Build Coastguard Worker   virtual UClassID getDynamicClassID() const override;
195*0e209d39SAndroid Build Coastguard Worker 
196*0e209d39SAndroid Build Coastguard Worker #ifdef SERVICE_DEBUG
197*0e209d39SAndroid Build Coastguard Worker  public:
198*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& debug(UnicodeString& result) const;
199*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& debugClass(UnicodeString& result) const;
200*0e209d39SAndroid Build Coastguard Worker #endif
201*0e209d39SAndroid Build Coastguard Worker 
202*0e209d39SAndroid Build Coastguard Worker };
203*0e209d39SAndroid Build Coastguard Worker 
204*0e209d39SAndroid Build Coastguard Worker  /*******************************************************************
205*0e209d39SAndroid Build Coastguard Worker   * ICUServiceFactory
206*0e209d39SAndroid Build Coastguard Worker   */
207*0e209d39SAndroid Build Coastguard Worker 
208*0e209d39SAndroid Build Coastguard Worker  /**
209*0e209d39SAndroid Build Coastguard Worker   * <p>An implementing ICUServiceFactory generates the service objects maintained by the
210*0e209d39SAndroid Build Coastguard Worker   * service.  A factory generates a service object from a key,
211*0e209d39SAndroid Build Coastguard Worker   * updates id->factory mappings, and returns the display name for
212*0e209d39SAndroid Build Coastguard Worker   * a supported id.</p>
213*0e209d39SAndroid Build Coastguard Worker   */
214*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API ICUServiceFactory : public UObject {
215*0e209d39SAndroid Build Coastguard Worker  public:
216*0e209d39SAndroid Build Coastguard Worker     virtual ~ICUServiceFactory();
217*0e209d39SAndroid Build Coastguard Worker 
218*0e209d39SAndroid Build Coastguard Worker     /**
219*0e209d39SAndroid Build Coastguard Worker      * <p>Create a service object from the key, if this factory
220*0e209d39SAndroid Build Coastguard Worker      * supports the key.  Otherwise, return nullptr.</p>
221*0e209d39SAndroid Build Coastguard Worker      *
222*0e209d39SAndroid Build Coastguard Worker      * <p>If the factory supports the key, then it can call
223*0e209d39SAndroid Build Coastguard Worker      * the service's getKey(ICUServiceKey, String[], ICUServiceFactory) method
224*0e209d39SAndroid Build Coastguard Worker      * passing itself as the factory to get the object that
225*0e209d39SAndroid Build Coastguard Worker      * the service would have created prior to the factory's
226*0e209d39SAndroid Build Coastguard Worker      * registration with the service.  This can change the
227*0e209d39SAndroid Build Coastguard Worker      * key, so any information required from the key should
228*0e209d39SAndroid Build Coastguard Worker      * be extracted before making such a callback.</p>
229*0e209d39SAndroid Build Coastguard Worker      *
230*0e209d39SAndroid Build Coastguard Worker      * @param key the service key.
231*0e209d39SAndroid Build Coastguard Worker      * @param service the service with which this factory is registered.
232*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
233*0e209d39SAndroid Build Coastguard Worker      * @return the service object, or nullptr if the factory does not support the key.
234*0e209d39SAndroid Build Coastguard Worker      */
235*0e209d39SAndroid Build Coastguard Worker     virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const = 0;
236*0e209d39SAndroid Build Coastguard Worker 
237*0e209d39SAndroid Build Coastguard Worker     /**
238*0e209d39SAndroid Build Coastguard Worker      * <p>Update result to reflect the IDs (not descriptors) that this
239*0e209d39SAndroid Build Coastguard Worker      * factory publicly handles.  Result contains mappings from ID to
240*0e209d39SAndroid Build Coastguard Worker      * factory.  On entry it will contain all (visible) mappings from
241*0e209d39SAndroid Build Coastguard Worker      * previously-registered factories.</p>
242*0e209d39SAndroid Build Coastguard Worker      *
243*0e209d39SAndroid Build Coastguard Worker      * <p>This function, together with getDisplayName, are used to
244*0e209d39SAndroid Build Coastguard Worker      * support ICUService::getDisplayNames.  The factory determines
245*0e209d39SAndroid Build Coastguard Worker      * which IDs (of those it supports) it will make visible, and of
246*0e209d39SAndroid Build Coastguard Worker      * those, which it will provide localized display names for.  In
247*0e209d39SAndroid Build Coastguard Worker      * most cases it will register mappings from all IDs it supports
248*0e209d39SAndroid Build Coastguard Worker      * to itself.</p>
249*0e209d39SAndroid Build Coastguard Worker      *
250*0e209d39SAndroid Build Coastguard Worker      * @param result the mapping table to update.
251*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
252*0e209d39SAndroid Build Coastguard Worker      */
253*0e209d39SAndroid Build Coastguard Worker     virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const = 0;
254*0e209d39SAndroid Build Coastguard Worker 
255*0e209d39SAndroid Build Coastguard Worker     /**
256*0e209d39SAndroid Build Coastguard Worker      * <p>Return, in result, the display name of the id in the provided locale.
257*0e209d39SAndroid Build Coastguard Worker      * This is an id, not a descriptor.  If the id is
258*0e209d39SAndroid Build Coastguard Worker      * not visible, sets result to bogus.  If the
259*0e209d39SAndroid Build Coastguard Worker      * incoming result is bogus, it remains bogus.  Result is returned as a
260*0e209d39SAndroid Build Coastguard Worker      * convenience.  Results are not defined if id is not one supported by this
261*0e209d39SAndroid Build Coastguard Worker          * factory.</p>
262*0e209d39SAndroid Build Coastguard Worker      *
263*0e209d39SAndroid Build Coastguard Worker      * @param id a visible id supported by this factory.
264*0e209d39SAndroid Build Coastguard Worker      * @param locale the locale for which to generate the corresponding localized display name.
265*0e209d39SAndroid Build Coastguard Worker      * @param result output parameter to hold the display name.
266*0e209d39SAndroid Build Coastguard Worker      * @return result.
267*0e209d39SAndroid Build Coastguard Worker      */
268*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const = 0;
269*0e209d39SAndroid Build Coastguard Worker };
270*0e209d39SAndroid Build Coastguard Worker 
271*0e209d39SAndroid Build Coastguard Worker /*
272*0e209d39SAndroid Build Coastguard Worker  ******************************************************************
273*0e209d39SAndroid Build Coastguard Worker  */
274*0e209d39SAndroid Build Coastguard Worker 
275*0e209d39SAndroid Build Coastguard Worker  /**
276*0e209d39SAndroid Build Coastguard Worker   * <p>A default implementation of factory.  This provides default
277*0e209d39SAndroid Build Coastguard Worker   * implementations for subclasses, and implements a singleton
278*0e209d39SAndroid Build Coastguard Worker   * factory that matches a single ID and returns a single
279*0e209d39SAndroid Build Coastguard Worker   * (possibly deferred-initialized) instance.  This implements
280*0e209d39SAndroid Build Coastguard Worker   * updateVisibleIDs to add a mapping from its ID to itself
281*0e209d39SAndroid Build Coastguard Worker   * if visible is true, or to remove any existing mapping
282*0e209d39SAndroid Build Coastguard Worker   * for its ID if visible is false.  No localization of display
283*0e209d39SAndroid Build Coastguard Worker   * names is performed.</p>
284*0e209d39SAndroid Build Coastguard Worker   */
285*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API SimpleFactory : public ICUServiceFactory {
286*0e209d39SAndroid Build Coastguard Worker  protected:
287*0e209d39SAndroid Build Coastguard Worker   UObject* _instance;
288*0e209d39SAndroid Build Coastguard Worker   const UnicodeString _id;
289*0e209d39SAndroid Build Coastguard Worker   const UBool _visible;
290*0e209d39SAndroid Build Coastguard Worker 
291*0e209d39SAndroid Build Coastguard Worker  public:
292*0e209d39SAndroid Build Coastguard Worker   /**
293*0e209d39SAndroid Build Coastguard Worker    * <p>Construct a SimpleFactory that maps a single ID to a single
294*0e209d39SAndroid Build Coastguard Worker    * service instance.  If visible is true, the ID will be visible.
295*0e209d39SAndroid Build Coastguard Worker    * The instance must not be nullptr.  The SimpleFactory will adopt
296*0e209d39SAndroid Build Coastguard Worker    * the instance, which must not be changed subsequent to this call.</p>
297*0e209d39SAndroid Build Coastguard Worker    *
298*0e209d39SAndroid Build Coastguard Worker    * @param instanceToAdopt the service instance to adopt.
299*0e209d39SAndroid Build Coastguard Worker    * @param id the ID to assign to this service instance.
300*0e209d39SAndroid Build Coastguard Worker    * @param visible if true, the ID will be visible.
301*0e209d39SAndroid Build Coastguard Worker    */
302*0e209d39SAndroid Build Coastguard Worker   SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible = true);
303*0e209d39SAndroid Build Coastguard Worker 
304*0e209d39SAndroid Build Coastguard Worker   /**
305*0e209d39SAndroid Build Coastguard Worker    * <p>Destructor.</p>
306*0e209d39SAndroid Build Coastguard Worker    */
307*0e209d39SAndroid Build Coastguard Worker   virtual ~SimpleFactory();
308*0e209d39SAndroid Build Coastguard Worker 
309*0e209d39SAndroid Build Coastguard Worker   /**
310*0e209d39SAndroid Build Coastguard Worker    * <p>This implementation returns a clone of the service instance if the factory's ID is equal to
311*0e209d39SAndroid Build Coastguard Worker    * the key's currentID.  Service and prefix are ignored.</p>
312*0e209d39SAndroid Build Coastguard Worker    *
313*0e209d39SAndroid Build Coastguard Worker    * @param key the service key.
314*0e209d39SAndroid Build Coastguard Worker    * @param service the service with which this factory is registered.
315*0e209d39SAndroid Build Coastguard Worker    * @param status the error code status.
316*0e209d39SAndroid Build Coastguard Worker    * @return the service object, or nullptr if the factory does not support the key.
317*0e209d39SAndroid Build Coastguard Worker    */
318*0e209d39SAndroid Build Coastguard Worker   virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const override;
319*0e209d39SAndroid Build Coastguard Worker 
320*0e209d39SAndroid Build Coastguard Worker   /**
321*0e209d39SAndroid Build Coastguard Worker    * <p>This implementation adds a mapping from ID -> this to result if visible is true,
322*0e209d39SAndroid Build Coastguard Worker    * otherwise it removes ID from result.</p>
323*0e209d39SAndroid Build Coastguard Worker    *
324*0e209d39SAndroid Build Coastguard Worker    * @param result the mapping table to update.
325*0e209d39SAndroid Build Coastguard Worker    * @param status the error code status.
326*0e209d39SAndroid Build Coastguard Worker    */
327*0e209d39SAndroid Build Coastguard Worker   virtual void updateVisibleIDs(Hashtable& result, UErrorCode& status) const override;
328*0e209d39SAndroid Build Coastguard Worker 
329*0e209d39SAndroid Build Coastguard Worker   /**
330*0e209d39SAndroid Build Coastguard Worker    * <p>This implementation returns the factory ID if it equals id and visible is true,
331*0e209d39SAndroid Build Coastguard Worker    * otherwise it returns the empty string.  (This implementation provides
332*0e209d39SAndroid Build Coastguard Worker    * no localized id information.)</p>
333*0e209d39SAndroid Build Coastguard Worker    *
334*0e209d39SAndroid Build Coastguard Worker    * @param id a visible id supported by this factory.
335*0e209d39SAndroid Build Coastguard Worker    * @param locale the locale for which to generate the corresponding localized display name.
336*0e209d39SAndroid Build Coastguard Worker    * @param result output parameter to hold the display name.
337*0e209d39SAndroid Build Coastguard Worker    * @return result.
338*0e209d39SAndroid Build Coastguard Worker    */
339*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const override;
340*0e209d39SAndroid Build Coastguard Worker 
341*0e209d39SAndroid Build Coastguard Worker public:
342*0e209d39SAndroid Build Coastguard Worker  /**
343*0e209d39SAndroid Build Coastguard Worker   * UObject RTTI boilerplate.
344*0e209d39SAndroid Build Coastguard Worker   */
345*0e209d39SAndroid Build Coastguard Worker   static UClassID U_EXPORT2 getStaticClassID();
346*0e209d39SAndroid Build Coastguard Worker 
347*0e209d39SAndroid Build Coastguard Worker  /**
348*0e209d39SAndroid Build Coastguard Worker   * UObject RTTI boilerplate.
349*0e209d39SAndroid Build Coastguard Worker   */
350*0e209d39SAndroid Build Coastguard Worker   virtual UClassID getDynamicClassID() const override;
351*0e209d39SAndroid Build Coastguard Worker 
352*0e209d39SAndroid Build Coastguard Worker #ifdef SERVICE_DEBUG
353*0e209d39SAndroid Build Coastguard Worker  public:
354*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& debug(UnicodeString& toAppendTo) const;
355*0e209d39SAndroid Build Coastguard Worker   virtual UnicodeString& debugClass(UnicodeString& toAppendTo) const;
356*0e209d39SAndroid Build Coastguard Worker #endif
357*0e209d39SAndroid Build Coastguard Worker 
358*0e209d39SAndroid Build Coastguard Worker };
359*0e209d39SAndroid Build Coastguard Worker 
360*0e209d39SAndroid Build Coastguard Worker /*
361*0e209d39SAndroid Build Coastguard Worker  ******************************************************************
362*0e209d39SAndroid Build Coastguard Worker  */
363*0e209d39SAndroid Build Coastguard Worker 
364*0e209d39SAndroid Build Coastguard Worker /**
365*0e209d39SAndroid Build Coastguard Worker  * <p>ServiceListener is the listener that ICUService provides by default.
366*0e209d39SAndroid Build Coastguard Worker  * ICUService will notify this listener when factories are added to
367*0e209d39SAndroid Build Coastguard Worker  * or removed from the service.  Subclasses can provide
368*0e209d39SAndroid Build Coastguard Worker  * different listener interfaces that extend EventListener, and modify
369*0e209d39SAndroid Build Coastguard Worker  * acceptsListener and notifyListener as appropriate.</p>
370*0e209d39SAndroid Build Coastguard Worker  */
371*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API ServiceListener : public EventListener {
372*0e209d39SAndroid Build Coastguard Worker public:
373*0e209d39SAndroid Build Coastguard Worker     virtual ~ServiceListener();
374*0e209d39SAndroid Build Coastguard Worker 
375*0e209d39SAndroid Build Coastguard Worker     /**
376*0e209d39SAndroid Build Coastguard Worker      * <p>This method is called when the service changes. At the time of the
377*0e209d39SAndroid Build Coastguard Worker      * call this listener is registered with the service.  It must
378*0e209d39SAndroid Build Coastguard Worker      * not modify the notifier in the context of this call.</p>
379*0e209d39SAndroid Build Coastguard Worker      *
380*0e209d39SAndroid Build Coastguard Worker      * @param service the service that changed.
381*0e209d39SAndroid Build Coastguard Worker      */
382*0e209d39SAndroid Build Coastguard Worker     virtual void serviceChanged(const ICUService& service) const = 0;
383*0e209d39SAndroid Build Coastguard Worker 
384*0e209d39SAndroid Build Coastguard Worker public:
385*0e209d39SAndroid Build Coastguard Worker     /**
386*0e209d39SAndroid Build Coastguard Worker      * UObject RTTI boilerplate.
387*0e209d39SAndroid Build Coastguard Worker      */
388*0e209d39SAndroid Build Coastguard Worker     static UClassID U_EXPORT2 getStaticClassID();
389*0e209d39SAndroid Build Coastguard Worker 
390*0e209d39SAndroid Build Coastguard Worker     /**
391*0e209d39SAndroid Build Coastguard Worker      * UObject RTTI boilerplate.
392*0e209d39SAndroid Build Coastguard Worker      */
393*0e209d39SAndroid Build Coastguard Worker     virtual UClassID getDynamicClassID() const override;
394*0e209d39SAndroid Build Coastguard Worker 
395*0e209d39SAndroid Build Coastguard Worker };
396*0e209d39SAndroid Build Coastguard Worker 
397*0e209d39SAndroid Build Coastguard Worker /*
398*0e209d39SAndroid Build Coastguard Worker  ******************************************************************
399*0e209d39SAndroid Build Coastguard Worker  */
400*0e209d39SAndroid Build Coastguard Worker 
401*0e209d39SAndroid Build Coastguard Worker /**
402*0e209d39SAndroid Build Coastguard Worker  * <p>A StringPair holds a displayName/ID pair.  ICUService uses it
403*0e209d39SAndroid Build Coastguard Worker  * as the array elements returned by getDisplayNames.
404*0e209d39SAndroid Build Coastguard Worker  */
405*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API StringPair : public UMemory {
406*0e209d39SAndroid Build Coastguard Worker public:
407*0e209d39SAndroid Build Coastguard Worker   /**
408*0e209d39SAndroid Build Coastguard Worker    * <p>The display name of the pair.</p>
409*0e209d39SAndroid Build Coastguard Worker    */
410*0e209d39SAndroid Build Coastguard Worker   const UnicodeString displayName;
411*0e209d39SAndroid Build Coastguard Worker 
412*0e209d39SAndroid Build Coastguard Worker   /**
413*0e209d39SAndroid Build Coastguard Worker    * <p>The ID of the pair.</p>
414*0e209d39SAndroid Build Coastguard Worker    */
415*0e209d39SAndroid Build Coastguard Worker   const UnicodeString id;
416*0e209d39SAndroid Build Coastguard Worker 
417*0e209d39SAndroid Build Coastguard Worker   /**
418*0e209d39SAndroid Build Coastguard Worker    * <p>Creates a string pair from a displayName and an ID.</p>
419*0e209d39SAndroid Build Coastguard Worker    *
420*0e209d39SAndroid Build Coastguard Worker    * @param displayName the displayName.
421*0e209d39SAndroid Build Coastguard Worker    * @param id the ID.
422*0e209d39SAndroid Build Coastguard Worker    * @param status the error code status.
423*0e209d39SAndroid Build Coastguard Worker    * @return a StringPair if the creation was successful, otherwise nullptr.
424*0e209d39SAndroid Build Coastguard Worker    */
425*0e209d39SAndroid Build Coastguard Worker   static StringPair* create(const UnicodeString& displayName,
426*0e209d39SAndroid Build Coastguard Worker                             const UnicodeString& id,
427*0e209d39SAndroid Build Coastguard Worker                             UErrorCode& status);
428*0e209d39SAndroid Build Coastguard Worker 
429*0e209d39SAndroid Build Coastguard Worker   /**
430*0e209d39SAndroid Build Coastguard Worker    * <p>Return true if either string of the pair is bogus.</p>
431*0e209d39SAndroid Build Coastguard Worker    * @return true if either string of the pair is bogus.
432*0e209d39SAndroid Build Coastguard Worker    */
433*0e209d39SAndroid Build Coastguard Worker   UBool isBogus() const;
434*0e209d39SAndroid Build Coastguard Worker 
435*0e209d39SAndroid Build Coastguard Worker private:
436*0e209d39SAndroid Build Coastguard Worker   StringPair(const UnicodeString& displayName, const UnicodeString& id);
437*0e209d39SAndroid Build Coastguard Worker };
438*0e209d39SAndroid Build Coastguard Worker 
439*0e209d39SAndroid Build Coastguard Worker /*******************************************************************
440*0e209d39SAndroid Build Coastguard Worker  * ICUService
441*0e209d39SAndroid Build Coastguard Worker  */
442*0e209d39SAndroid Build Coastguard Worker 
443*0e209d39SAndroid Build Coastguard Worker  /**
444*0e209d39SAndroid Build Coastguard Worker  * <p>A Service provides access to service objects that implement a
445*0e209d39SAndroid Build Coastguard Worker  * particular service, e.g. transliterators.  Users provide a String
446*0e209d39SAndroid Build Coastguard Worker  * id (for example, a locale string) to the service, and get back an
447*0e209d39SAndroid Build Coastguard Worker  * object for that id.  Service objects can be any kind of object.  A
448*0e209d39SAndroid Build Coastguard Worker  * new service object is returned for each query. The caller is
449*0e209d39SAndroid Build Coastguard Worker  * responsible for deleting it.</p>
450*0e209d39SAndroid Build Coastguard Worker  *
451*0e209d39SAndroid Build Coastguard Worker  * <p>Services 'canonicalize' the query ID and use the canonical ID to
452*0e209d39SAndroid Build Coastguard Worker  * query for the service.  The service also defines a mechanism to
453*0e209d39SAndroid Build Coastguard Worker  * 'fallback' the ID multiple times.  Clients can optionally request
454*0e209d39SAndroid Build Coastguard Worker  * the actual ID that was matched by a query when they use an ID to
455*0e209d39SAndroid Build Coastguard Worker  * retrieve a service object.</p>
456*0e209d39SAndroid Build Coastguard Worker  *
457*0e209d39SAndroid Build Coastguard Worker  * <p>Service objects are instantiated by ICUServiceFactory objects
458*0e209d39SAndroid Build Coastguard Worker  * registered with the service.  The service queries each
459*0e209d39SAndroid Build Coastguard Worker  * ICUServiceFactory in turn, from most recently registered to
460*0e209d39SAndroid Build Coastguard Worker  * earliest registered, until one returns a service object.  If none
461*0e209d39SAndroid Build Coastguard Worker  * responds with a service object, a fallback ID is generated, and the
462*0e209d39SAndroid Build Coastguard Worker  * process repeats until a service object is returned or until the ID
463*0e209d39SAndroid Build Coastguard Worker  * has no further fallbacks.</p>
464*0e209d39SAndroid Build Coastguard Worker  *
465*0e209d39SAndroid Build Coastguard Worker  * <p>In ICU 2.4, UObject (the base class of service instances) does
466*0e209d39SAndroid Build Coastguard Worker  * not define a polymorphic clone function.  ICUService uses clones to
467*0e209d39SAndroid Build Coastguard Worker  * manage ownership.  Thus, for now, ICUService defines an abstract
468*0e209d39SAndroid Build Coastguard Worker  * method, cloneInstance, that clients must implement to create clones
469*0e209d39SAndroid Build Coastguard Worker  * of the service instances.  This may change in future releases of
470*0e209d39SAndroid Build Coastguard Worker  * ICU.</p>
471*0e209d39SAndroid Build Coastguard Worker  *
472*0e209d39SAndroid Build Coastguard Worker  * <p>ICUServiceFactories can be dynamically registered and
473*0e209d39SAndroid Build Coastguard Worker  * unregistered with the service.  When registered, an
474*0e209d39SAndroid Build Coastguard Worker  * ICUServiceFactory is installed at the head of the factory list, and
475*0e209d39SAndroid Build Coastguard Worker  * so gets 'first crack' at any keys or fallback keys.  When
476*0e209d39SAndroid Build Coastguard Worker  * unregistered, it is removed from the service and can no longer be
477*0e209d39SAndroid Build Coastguard Worker  * located through it.  Service objects generated by this factory and
478*0e209d39SAndroid Build Coastguard Worker  * held by the client are unaffected.</p>
479*0e209d39SAndroid Build Coastguard Worker  *
480*0e209d39SAndroid Build Coastguard Worker  * <p>If a service has variants (e.g., the different variants of
481*0e209d39SAndroid Build Coastguard Worker  * BreakIterator) an ICUServiceFactory can use the prefix of the
482*0e209d39SAndroid Build Coastguard Worker  * ICUServiceKey to determine the variant of a service to generate.
483*0e209d39SAndroid Build Coastguard Worker  * If it does not support all variants, it can request
484*0e209d39SAndroid Build Coastguard Worker  * previously-registered factories to handle the ones it does not
485*0e209d39SAndroid Build Coastguard Worker  * support.</p>
486*0e209d39SAndroid Build Coastguard Worker  *
487*0e209d39SAndroid Build Coastguard Worker  * <p>ICUService uses ICUServiceKeys to query factories and perform
488*0e209d39SAndroid Build Coastguard Worker  * fallback.  The ICUServiceKey defines the canonical form of the ID,
489*0e209d39SAndroid Build Coastguard Worker  * and implements the fallback strategy.  Custom ICUServiceKeys can be
490*0e209d39SAndroid Build Coastguard Worker  * defined that parse complex IDs into components that
491*0e209d39SAndroid Build Coastguard Worker  * ICUServiceFactories can more easily use.  The ICUServiceKey can
492*0e209d39SAndroid Build Coastguard Worker  * cache the results of this parsing to save repeated effort.
493*0e209d39SAndroid Build Coastguard Worker  * ICUService provides convenience APIs that take UnicodeStrings and
494*0e209d39SAndroid Build Coastguard Worker  * generate default ICUServiceKeys for use in querying.</p>
495*0e209d39SAndroid Build Coastguard Worker  *
496*0e209d39SAndroid Build Coastguard Worker  * <p>ICUService provides API to get the list of IDs publicly
497*0e209d39SAndroid Build Coastguard Worker  * supported by the service (although queries aren't restricted to
498*0e209d39SAndroid Build Coastguard Worker  * this list).  This list contains only 'simple' IDs, and not fully
499*0e209d39SAndroid Build Coastguard Worker  * unique IDs.  ICUServiceFactories are associated with each simple ID
500*0e209d39SAndroid Build Coastguard Worker  * and the responsible factory can also return a human-readable
501*0e209d39SAndroid Build Coastguard Worker  * localized version of the simple ID, for use in user interfaces.
502*0e209d39SAndroid Build Coastguard Worker  * ICUService can also provide an array of the all the localized
503*0e209d39SAndroid Build Coastguard Worker  * visible IDs and their corresponding internal IDs.</p>
504*0e209d39SAndroid Build Coastguard Worker  *
505*0e209d39SAndroid Build Coastguard Worker  * <p>ICUService implements ICUNotifier, so that clients can register
506*0e209d39SAndroid Build Coastguard Worker  * to receive notification when factories are added or removed from
507*0e209d39SAndroid Build Coastguard Worker  * the service.  ICUService provides a default EventListener
508*0e209d39SAndroid Build Coastguard Worker  * subinterface, ServiceListener, which can be registered with the
509*0e209d39SAndroid Build Coastguard Worker  * service.  When the service changes, the ServiceListener's
510*0e209d39SAndroid Build Coastguard Worker  * serviceChanged method is called with the service as the
511*0e209d39SAndroid Build Coastguard Worker  * argument.</p>
512*0e209d39SAndroid Build Coastguard Worker  *
513*0e209d39SAndroid Build Coastguard Worker  * <p>The ICUService API is both rich and generic, and it is expected
514*0e209d39SAndroid Build Coastguard Worker  * that most implementations will statically 'wrap' ICUService to
515*0e209d39SAndroid Build Coastguard Worker  * present a more appropriate API-- for example, to declare the type
516*0e209d39SAndroid Build Coastguard Worker  * of the objects returned from get, to limit the factories that can
517*0e209d39SAndroid Build Coastguard Worker  * be registered with the service, or to define their own listener
518*0e209d39SAndroid Build Coastguard Worker  * interface with a custom callback method.  They might also customize
519*0e209d39SAndroid Build Coastguard Worker  * ICUService by overriding it, for example, to customize the
520*0e209d39SAndroid Build Coastguard Worker  * ICUServiceKey and fallback strategy.  ICULocaleService is a
521*0e209d39SAndroid Build Coastguard Worker  * subclass of ICUService that uses Locale names as IDs and uses
522*0e209d39SAndroid Build Coastguard Worker  * ICUServiceKeys that implement the standard resource bundle fallback
523*0e209d39SAndroid Build Coastguard Worker  * strategy.  Most clients will wish to subclass it instead of
524*0e209d39SAndroid Build Coastguard Worker  * ICUService.</p>
525*0e209d39SAndroid Build Coastguard Worker  */
526*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API ICUService : public ICUNotifier {
527*0e209d39SAndroid Build Coastguard Worker  protected:
528*0e209d39SAndroid Build Coastguard Worker     /**
529*0e209d39SAndroid Build Coastguard Worker      * Name useful for debugging.
530*0e209d39SAndroid Build Coastguard Worker      */
531*0e209d39SAndroid Build Coastguard Worker     const UnicodeString name;
532*0e209d39SAndroid Build Coastguard Worker 
533*0e209d39SAndroid Build Coastguard Worker  private:
534*0e209d39SAndroid Build Coastguard Worker 
535*0e209d39SAndroid Build Coastguard Worker     /**
536*0e209d39SAndroid Build Coastguard Worker      * Timestamp so iterators can be fail-fast.
537*0e209d39SAndroid Build Coastguard Worker      */
538*0e209d39SAndroid Build Coastguard Worker     uint32_t timestamp;
539*0e209d39SAndroid Build Coastguard Worker 
540*0e209d39SAndroid Build Coastguard Worker     /**
541*0e209d39SAndroid Build Coastguard Worker      * All the factories registered with this service.
542*0e209d39SAndroid Build Coastguard Worker      */
543*0e209d39SAndroid Build Coastguard Worker     UVector* factories;
544*0e209d39SAndroid Build Coastguard Worker 
545*0e209d39SAndroid Build Coastguard Worker     /**
546*0e209d39SAndroid Build Coastguard Worker      * The service cache.
547*0e209d39SAndroid Build Coastguard Worker      */
548*0e209d39SAndroid Build Coastguard Worker     Hashtable* serviceCache;
549*0e209d39SAndroid Build Coastguard Worker 
550*0e209d39SAndroid Build Coastguard Worker     /**
551*0e209d39SAndroid Build Coastguard Worker      * The ID cache.
552*0e209d39SAndroid Build Coastguard Worker      */
553*0e209d39SAndroid Build Coastguard Worker     Hashtable* idCache;
554*0e209d39SAndroid Build Coastguard Worker 
555*0e209d39SAndroid Build Coastguard Worker     /**
556*0e209d39SAndroid Build Coastguard Worker      * The name cache.
557*0e209d39SAndroid Build Coastguard Worker      */
558*0e209d39SAndroid Build Coastguard Worker     DNCache* dnCache;
559*0e209d39SAndroid Build Coastguard Worker 
560*0e209d39SAndroid Build Coastguard Worker     /**
561*0e209d39SAndroid Build Coastguard Worker      * Constructor.
562*0e209d39SAndroid Build Coastguard Worker      */
563*0e209d39SAndroid Build Coastguard Worker  public:
564*0e209d39SAndroid Build Coastguard Worker     /**
565*0e209d39SAndroid Build Coastguard Worker      * <p>Construct a new ICUService.</p>
566*0e209d39SAndroid Build Coastguard Worker      */
567*0e209d39SAndroid Build Coastguard Worker     ICUService();
568*0e209d39SAndroid Build Coastguard Worker 
569*0e209d39SAndroid Build Coastguard Worker     /**
570*0e209d39SAndroid Build Coastguard Worker      * <p>Construct with a name (useful for debugging).</p>
571*0e209d39SAndroid Build Coastguard Worker      *
572*0e209d39SAndroid Build Coastguard Worker      * @param name a name to use in debugging.
573*0e209d39SAndroid Build Coastguard Worker      */
574*0e209d39SAndroid Build Coastguard Worker     ICUService(const UnicodeString& name);
575*0e209d39SAndroid Build Coastguard Worker 
576*0e209d39SAndroid Build Coastguard Worker     /**
577*0e209d39SAndroid Build Coastguard Worker      * <p>Destructor.</p>
578*0e209d39SAndroid Build Coastguard Worker      */
579*0e209d39SAndroid Build Coastguard Worker     virtual ~ICUService();
580*0e209d39SAndroid Build Coastguard Worker 
581*0e209d39SAndroid Build Coastguard Worker     /**
582*0e209d39SAndroid Build Coastguard Worker      * <p>Return the name of this service. This will be the empty string if none was assigned.
583*0e209d39SAndroid Build Coastguard Worker      * Returns result as a convenience.</p>
584*0e209d39SAndroid Build Coastguard Worker      *
585*0e209d39SAndroid Build Coastguard Worker      * @param result an output parameter to contain the name of this service.
586*0e209d39SAndroid Build Coastguard Worker      * @return the name of this service.
587*0e209d39SAndroid Build Coastguard Worker      */
588*0e209d39SAndroid Build Coastguard Worker     UnicodeString& getName(UnicodeString& result) const;
589*0e209d39SAndroid Build Coastguard Worker 
590*0e209d39SAndroid Build Coastguard Worker     /**
591*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override for get(ICUServiceKey&, UnicodeString*). This uses
592*0e209d39SAndroid Build Coastguard Worker      * createKey to create a key for the provided descriptor.</p>
593*0e209d39SAndroid Build Coastguard Worker      *
594*0e209d39SAndroid Build Coastguard Worker      * @param descriptor the descriptor.
595*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
596*0e209d39SAndroid Build Coastguard Worker      * @return the service instance, or nullptr.
597*0e209d39SAndroid Build Coastguard Worker      */
598*0e209d39SAndroid Build Coastguard Worker     UObject* get(const UnicodeString& descriptor, UErrorCode& status) const;
599*0e209d39SAndroid Build Coastguard Worker 
600*0e209d39SAndroid Build Coastguard Worker     /**
601*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override for get(ICUServiceKey&, UnicodeString*).  This uses
602*0e209d39SAndroid Build Coastguard Worker      * createKey to create a key from the provided descriptor.</p>
603*0e209d39SAndroid Build Coastguard Worker      *
604*0e209d39SAndroid Build Coastguard Worker      * @param descriptor the descriptor.
605*0e209d39SAndroid Build Coastguard Worker      * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or nullptr.
606*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
607*0e209d39SAndroid Build Coastguard Worker      * @return the service instance, or nullptr.
608*0e209d39SAndroid Build Coastguard Worker      */
609*0e209d39SAndroid Build Coastguard Worker     UObject* get(const UnicodeString& descriptor, UnicodeString* actualReturn, UErrorCode& status) const;
610*0e209d39SAndroid Build Coastguard Worker 
611*0e209d39SAndroid Build Coastguard Worker     /**
612*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override for get(ICUServiceKey&, UnicodeString*).</p>
613*0e209d39SAndroid Build Coastguard Worker      *
614*0e209d39SAndroid Build Coastguard Worker      * @param key the key.
615*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
616*0e209d39SAndroid Build Coastguard Worker      * @return the service instance, or nullptr.
617*0e209d39SAndroid Build Coastguard Worker      */
618*0e209d39SAndroid Build Coastguard Worker     UObject* getKey(ICUServiceKey& key, UErrorCode& status) const;
619*0e209d39SAndroid Build Coastguard Worker 
620*0e209d39SAndroid Build Coastguard Worker     /**
621*0e209d39SAndroid Build Coastguard Worker      * <p>Given a key, return a service object, and, if actualReturn
622*0e209d39SAndroid Build Coastguard Worker      * is not nullptr, the descriptor with which it was found in the
623*0e209d39SAndroid Build Coastguard Worker      * first element of actualReturn.  If no service object matches
624*0e209d39SAndroid Build Coastguard Worker      * this key, returns nullptr and leaves actualReturn unchanged.</p>
625*0e209d39SAndroid Build Coastguard Worker      *
626*0e209d39SAndroid Build Coastguard Worker      * <p>This queries the cache using the key's descriptor, and if no
627*0e209d39SAndroid Build Coastguard Worker      * object in the cache matches, tries the key on each
628*0e209d39SAndroid Build Coastguard Worker      * registered factory, in order.  If none generates a service
629*0e209d39SAndroid Build Coastguard Worker      * object for the key, repeats the process with each fallback of
630*0e209d39SAndroid Build Coastguard Worker      * the key, until either a factory returns a service object, or the key
631*0e209d39SAndroid Build Coastguard Worker      * has no fallback.  If no object is found, the result of handleDefault
632*0e209d39SAndroid Build Coastguard Worker      * is returned.</p>
633*0e209d39SAndroid Build Coastguard Worker      *
634*0e209d39SAndroid Build Coastguard Worker      * <p>Subclasses can override this method to further customize the
635*0e209d39SAndroid Build Coastguard Worker      * result before returning it.
636*0e209d39SAndroid Build Coastguard Worker      *
637*0e209d39SAndroid Build Coastguard Worker      * @param key the key.
638*0e209d39SAndroid Build Coastguard Worker      * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or nullptr.
639*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
640*0e209d39SAndroid Build Coastguard Worker      * @return the service instance, or nullptr.
641*0e209d39SAndroid Build Coastguard Worker      */
642*0e209d39SAndroid Build Coastguard Worker     virtual UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const;
643*0e209d39SAndroid Build Coastguard Worker 
644*0e209d39SAndroid Build Coastguard Worker     /**
645*0e209d39SAndroid Build Coastguard Worker      * <p>This version of getKey is only called by ICUServiceFactories within the scope
646*0e209d39SAndroid Build Coastguard Worker      * of a previous getKey call, to determine what previously-registered factories would
647*0e209d39SAndroid Build Coastguard Worker      * have returned.  For details, see getKey(ICUServiceKey&, UErrorCode&).  Subclasses
648*0e209d39SAndroid Build Coastguard Worker      * should not call it directly, but call through one of the other get functions.</p>
649*0e209d39SAndroid Build Coastguard Worker      *
650*0e209d39SAndroid Build Coastguard Worker      * @param key the key.
651*0e209d39SAndroid Build Coastguard Worker      * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or nullptr.
652*0e209d39SAndroid Build Coastguard Worker      * @param factory the factory making the recursive call.
653*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
654*0e209d39SAndroid Build Coastguard Worker      * @return the service instance, or nullptr.
655*0e209d39SAndroid Build Coastguard Worker      */
656*0e209d39SAndroid Build Coastguard Worker     UObject* getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUServiceFactory* factory, UErrorCode& status) const;
657*0e209d39SAndroid Build Coastguard Worker 
658*0e209d39SAndroid Build Coastguard Worker     /**
659*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override for getVisibleIDs(String) that passes null
660*0e209d39SAndroid Build Coastguard Worker      * as the fallback, thus returning all visible IDs.</p>
661*0e209d39SAndroid Build Coastguard Worker      *
662*0e209d39SAndroid Build Coastguard Worker      * @param result a vector to hold the returned IDs.
663*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
664*0e209d39SAndroid Build Coastguard Worker      * @return the result vector.
665*0e209d39SAndroid Build Coastguard Worker      */
666*0e209d39SAndroid Build Coastguard Worker     UVector& getVisibleIDs(UVector& result, UErrorCode& status) const;
667*0e209d39SAndroid Build Coastguard Worker 
668*0e209d39SAndroid Build Coastguard Worker     /**
669*0e209d39SAndroid Build Coastguard Worker      * <p>Return a snapshot of the visible IDs for this service.  This
670*0e209d39SAndroid Build Coastguard Worker      * list will not change as ICUServiceFactories are added or removed, but the
671*0e209d39SAndroid Build Coastguard Worker      * supported IDs will, so there is no guarantee that all and only
672*0e209d39SAndroid Build Coastguard Worker      * the IDs in the returned list will be visible and supported by the
673*0e209d39SAndroid Build Coastguard Worker      * service in subsequent calls.</p>
674*0e209d39SAndroid Build Coastguard Worker      *
675*0e209d39SAndroid Build Coastguard Worker      * <p>The IDs are returned as pointers to UnicodeStrings.  The
676*0e209d39SAndroid Build Coastguard Worker      * caller owns the IDs.  Previous contents of result are discarded before
677*0e209d39SAndroid Build Coastguard Worker      * new elements, if any, are added.</p>
678*0e209d39SAndroid Build Coastguard Worker      *
679*0e209d39SAndroid Build Coastguard Worker      * <p>matchID is passed to createKey to create a key.  If the key
680*0e209d39SAndroid Build Coastguard Worker      * is not nullptr, its isFallbackOf method is used to filter out IDs
681*0e209d39SAndroid Build Coastguard Worker      * that don't match the key or have it as a fallback.</p>
682*0e209d39SAndroid Build Coastguard Worker      *
683*0e209d39SAndroid Build Coastguard Worker      * @param result a vector to hold the returned IDs.
684*0e209d39SAndroid Build Coastguard Worker      * @param matchID an ID used to filter the result, or nullptr if all IDs are desired.
685*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
686*0e209d39SAndroid Build Coastguard Worker      * @return the result vector.
687*0e209d39SAndroid Build Coastguard Worker      */
688*0e209d39SAndroid Build Coastguard Worker     UVector& getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorCode& status) const;
689*0e209d39SAndroid Build Coastguard Worker 
690*0e209d39SAndroid Build Coastguard Worker     /**
691*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override for getDisplayName(const UnicodeString&, const Locale&, UnicodeString&) that
692*0e209d39SAndroid Build Coastguard Worker      * uses the current default locale.</p>
693*0e209d39SAndroid Build Coastguard Worker      *
694*0e209d39SAndroid Build Coastguard Worker      * @param id the ID for which to retrieve the localized displayName.
695*0e209d39SAndroid Build Coastguard Worker      * @param result an output parameter to hold the display name.
696*0e209d39SAndroid Build Coastguard Worker      * @return the modified result.
697*0e209d39SAndroid Build Coastguard Worker      */
698*0e209d39SAndroid Build Coastguard Worker     UnicodeString& getDisplayName(const UnicodeString& id, UnicodeString& result) const;
699*0e209d39SAndroid Build Coastguard Worker 
700*0e209d39SAndroid Build Coastguard Worker     /**
701*0e209d39SAndroid Build Coastguard Worker      * <p>Given a visible ID, return the display name in the requested locale.
702*0e209d39SAndroid Build Coastguard Worker      * If there is no directly supported ID corresponding to this ID, result is
703*0e209d39SAndroid Build Coastguard Worker      * set to bogus.</p>
704*0e209d39SAndroid Build Coastguard Worker      *
705*0e209d39SAndroid Build Coastguard Worker      * @param id the ID for which to retrieve the localized displayName.
706*0e209d39SAndroid Build Coastguard Worker      * @param result an output parameter to hold the display name.
707*0e209d39SAndroid Build Coastguard Worker      * @param locale the locale in which to localize the ID.
708*0e209d39SAndroid Build Coastguard Worker      * @return the modified result.
709*0e209d39SAndroid Build Coastguard Worker      */
710*0e209d39SAndroid Build Coastguard Worker     UnicodeString& getDisplayName(const UnicodeString& id, UnicodeString& result, const Locale& locale) const;
711*0e209d39SAndroid Build Coastguard Worker 
712*0e209d39SAndroid Build Coastguard Worker     /**
713*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override of getDisplayNames(const Locale&, const UnicodeString*) that
714*0e209d39SAndroid Build Coastguard Worker      * uses the current default Locale as the locale and nullptr for
715*0e209d39SAndroid Build Coastguard Worker      * the matchID.</p>
716*0e209d39SAndroid Build Coastguard Worker      *
717*0e209d39SAndroid Build Coastguard Worker      * @param result a vector to hold the returned displayName/id StringPairs.
718*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
719*0e209d39SAndroid Build Coastguard Worker      * @return the modified result vector.
720*0e209d39SAndroid Build Coastguard Worker      */
721*0e209d39SAndroid Build Coastguard Worker     UVector& getDisplayNames(UVector& result, UErrorCode& status) const;
722*0e209d39SAndroid Build Coastguard Worker 
723*0e209d39SAndroid Build Coastguard Worker     /**
724*0e209d39SAndroid Build Coastguard Worker      * <p>Convenience override of getDisplayNames(const Locale&, const UnicodeString*) that
725*0e209d39SAndroid Build Coastguard Worker      * uses nullptr for the matchID.</p>
726*0e209d39SAndroid Build Coastguard Worker      *
727*0e209d39SAndroid Build Coastguard Worker      * @param result a vector to hold the returned displayName/id StringPairs.
728*0e209d39SAndroid Build Coastguard Worker      * @param locale the locale in which to localize the ID.
729*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
730*0e209d39SAndroid Build Coastguard Worker      * @return the modified result vector.
731*0e209d39SAndroid Build Coastguard Worker      */
732*0e209d39SAndroid Build Coastguard Worker     UVector& getDisplayNames(UVector& result, const Locale& locale, UErrorCode& status) const;
733*0e209d39SAndroid Build Coastguard Worker 
734*0e209d39SAndroid Build Coastguard Worker     /**
735*0e209d39SAndroid Build Coastguard Worker      * <p>Return a snapshot of the mapping from display names to visible
736*0e209d39SAndroid Build Coastguard Worker      * IDs for this service.  This set will not change as factories
737*0e209d39SAndroid Build Coastguard Worker      * are added or removed, but the supported IDs will, so there is
738*0e209d39SAndroid Build Coastguard Worker      * no guarantee that all and only the IDs in the returned map will
739*0e209d39SAndroid Build Coastguard Worker      * be visible and supported by the service in subsequent calls,
740*0e209d39SAndroid Build Coastguard Worker      * nor is there any guarantee that the current display names match
741*0e209d39SAndroid Build Coastguard Worker      * those in the result.</p>
742*0e209d39SAndroid Build Coastguard Worker      *
743*0e209d39SAndroid Build Coastguard Worker      * <p>The names are returned as pointers to StringPairs, which
744*0e209d39SAndroid Build Coastguard Worker      * contain both the displayName and the corresponding ID.  The
745*0e209d39SAndroid Build Coastguard Worker      * caller owns the StringPairs.  Previous contents of result are
746*0e209d39SAndroid Build Coastguard Worker      * discarded before new elements, if any, are added.</p>
747*0e209d39SAndroid Build Coastguard Worker      *
748*0e209d39SAndroid Build Coastguard Worker      * <p>matchID is passed to createKey to create a key.  If the key
749*0e209d39SAndroid Build Coastguard Worker      * is not nullptr, its isFallbackOf method is used to filter out IDs
750*0e209d39SAndroid Build Coastguard Worker      * that don't match the key or have it as a fallback.</p>
751*0e209d39SAndroid Build Coastguard Worker      *
752*0e209d39SAndroid Build Coastguard Worker      * @param result a vector to hold the returned displayName/id StringPairs.
753*0e209d39SAndroid Build Coastguard Worker      * @param locale the locale in which to localize the ID.
754*0e209d39SAndroid Build Coastguard Worker      * @param matchID an ID used to filter the result, or nullptr if all IDs are desired.
755*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
756*0e209d39SAndroid Build Coastguard Worker      * @return the result vector.  */
757*0e209d39SAndroid Build Coastguard Worker     UVector& getDisplayNames(UVector& result,
758*0e209d39SAndroid Build Coastguard Worker                              const Locale& locale,
759*0e209d39SAndroid Build Coastguard Worker                              const UnicodeString* matchID,
760*0e209d39SAndroid Build Coastguard Worker                              UErrorCode& status) const;
761*0e209d39SAndroid Build Coastguard Worker 
762*0e209d39SAndroid Build Coastguard Worker     /**
763*0e209d39SAndroid Build Coastguard Worker      * <p>A convenience override of registerInstance(UObject*, const UnicodeString&, UBool)
764*0e209d39SAndroid Build Coastguard Worker      * that defaults visible to true.</p>
765*0e209d39SAndroid Build Coastguard Worker      *
766*0e209d39SAndroid Build Coastguard Worker      * @param objToAdopt the object to register and adopt.
767*0e209d39SAndroid Build Coastguard Worker      * @param id the ID to assign to this object.
768*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
769*0e209d39SAndroid Build Coastguard Worker      * @return a registry key that can be passed to unregister to unregister
770*0e209d39SAndroid Build Coastguard Worker      * (and discard) this instance.
771*0e209d39SAndroid Build Coastguard Worker      */
772*0e209d39SAndroid Build Coastguard Worker     URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& id, UErrorCode& status);
773*0e209d39SAndroid Build Coastguard Worker 
774*0e209d39SAndroid Build Coastguard Worker     /**
775*0e209d39SAndroid Build Coastguard Worker      * <p>Register a service instance with the provided ID.  The ID will be
776*0e209d39SAndroid Build Coastguard Worker      * canonicalized.  The canonicalized ID will be returned by
777*0e209d39SAndroid Build Coastguard Worker      * getVisibleIDs if visible is true.  The service instance will be adopted and
778*0e209d39SAndroid Build Coastguard Worker      * must not be modified subsequent to this call.</p>
779*0e209d39SAndroid Build Coastguard Worker      *
780*0e209d39SAndroid Build Coastguard Worker      * <p>This issues a serviceChanged notification to registered listeners.</p>
781*0e209d39SAndroid Build Coastguard Worker      *
782*0e209d39SAndroid Build Coastguard Worker      * <p>This implementation wraps the object using
783*0e209d39SAndroid Build Coastguard Worker      * createSimpleFactory, and calls registerFactory.</p>
784*0e209d39SAndroid Build Coastguard Worker      *
785*0e209d39SAndroid Build Coastguard Worker      * @param objToAdopt the object to register and adopt.
786*0e209d39SAndroid Build Coastguard Worker      * @param id the ID to assign to this object.
787*0e209d39SAndroid Build Coastguard Worker      * @param visible true if getVisibleIDs is to return this ID.
788*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
789*0e209d39SAndroid Build Coastguard Worker      * @return a registry key that can be passed to unregister() to unregister
790*0e209d39SAndroid Build Coastguard Worker      * (and discard) this instance.
791*0e209d39SAndroid Build Coastguard Worker      */
792*0e209d39SAndroid Build Coastguard Worker     virtual URegistryKey registerInstance(UObject* objToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status);
793*0e209d39SAndroid Build Coastguard Worker 
794*0e209d39SAndroid Build Coastguard Worker     /**
795*0e209d39SAndroid Build Coastguard Worker      * <p>Register an ICUServiceFactory.  Returns a registry key that
796*0e209d39SAndroid Build Coastguard Worker      * can be used to unregister the factory.  The factory
797*0e209d39SAndroid Build Coastguard Worker      * must not be modified subsequent to this call.  The service owns
798*0e209d39SAndroid Build Coastguard Worker      * all registered factories. In case of an error, the factory is
799*0e209d39SAndroid Build Coastguard Worker      * deleted.</p>
800*0e209d39SAndroid Build Coastguard Worker      *
801*0e209d39SAndroid Build Coastguard Worker      * <p>This issues a serviceChanged notification to registered listeners.</p>
802*0e209d39SAndroid Build Coastguard Worker      *
803*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation accepts all factories.</p>
804*0e209d39SAndroid Build Coastguard Worker      *
805*0e209d39SAndroid Build Coastguard Worker      * @param factoryToAdopt the factory to register and adopt.
806*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
807*0e209d39SAndroid Build Coastguard Worker      * @return a registry key that can be passed to unregister to unregister
808*0e209d39SAndroid Build Coastguard Worker      * (and discard) this factory.
809*0e209d39SAndroid Build Coastguard Worker      */
810*0e209d39SAndroid Build Coastguard Worker     virtual URegistryKey registerFactory(ICUServiceFactory* factoryToAdopt, UErrorCode& status);
811*0e209d39SAndroid Build Coastguard Worker 
812*0e209d39SAndroid Build Coastguard Worker     /**
813*0e209d39SAndroid Build Coastguard Worker      * <p>Unregister a factory using a registry key returned by
814*0e209d39SAndroid Build Coastguard Worker      * registerInstance or registerFactory.  After a successful call,
815*0e209d39SAndroid Build Coastguard Worker      * the factory will be removed from the service factory list and
816*0e209d39SAndroid Build Coastguard Worker      * deleted, and the key becomes invalid.</p>
817*0e209d39SAndroid Build Coastguard Worker      *
818*0e209d39SAndroid Build Coastguard Worker      * <p>This issues a serviceChanged notification to registered
819*0e209d39SAndroid Build Coastguard Worker      * listeners.</p>
820*0e209d39SAndroid Build Coastguard Worker      *
821*0e209d39SAndroid Build Coastguard Worker      * @param rkey the registry key.
822*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
823*0e209d39SAndroid Build Coastguard Worker      * @return true if the call successfully unregistered the factory.
824*0e209d39SAndroid Build Coastguard Worker      */
825*0e209d39SAndroid Build Coastguard Worker     virtual UBool unregister(URegistryKey rkey, UErrorCode& status);
826*0e209d39SAndroid Build Coastguard Worker 
827*0e209d39SAndroid Build Coastguard Worker     /**
828*0e209d39SAndroid Build Coastguard Worker      * </p>Reset the service to the default factories.  The factory
829*0e209d39SAndroid Build Coastguard Worker      * lock is acquired and then reInitializeFactories is called.</p>
830*0e209d39SAndroid Build Coastguard Worker      *
831*0e209d39SAndroid Build Coastguard Worker      * <p>This issues a serviceChanged notification to registered listeners.</p>
832*0e209d39SAndroid Build Coastguard Worker      */
833*0e209d39SAndroid Build Coastguard Worker     virtual void reset();
834*0e209d39SAndroid Build Coastguard Worker 
835*0e209d39SAndroid Build Coastguard Worker     /**
836*0e209d39SAndroid Build Coastguard Worker      * <p>Return true if the service is in its default state.</p>
837*0e209d39SAndroid Build Coastguard Worker      *
838*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation returns true if there are no
839*0e209d39SAndroid Build Coastguard Worker      * factories registered.</p>
840*0e209d39SAndroid Build Coastguard Worker      */
841*0e209d39SAndroid Build Coastguard Worker     virtual UBool isDefault() const;
842*0e209d39SAndroid Build Coastguard Worker 
843*0e209d39SAndroid Build Coastguard Worker     /**
844*0e209d39SAndroid Build Coastguard Worker      * <p>Create a key from an ID.  If ID is nullptr, returns nullptr.</p>
845*0e209d39SAndroid Build Coastguard Worker      *
846*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation creates an ICUServiceKey instance.
847*0e209d39SAndroid Build Coastguard Worker      * Subclasses can override to define more useful keys appropriate
848*0e209d39SAndroid Build Coastguard Worker      * to the factories they accept.</p>
849*0e209d39SAndroid Build Coastguard Worker      *
850*0e209d39SAndroid Build Coastguard Worker      * @param a pointer to the ID for which to create a default ICUServiceKey.
851*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
852*0e209d39SAndroid Build Coastguard Worker      * @return the ICUServiceKey corresponding to ID, or nullptr.
853*0e209d39SAndroid Build Coastguard Worker      */
854*0e209d39SAndroid Build Coastguard Worker     virtual ICUServiceKey* createKey(const UnicodeString* id, UErrorCode& status) const;
855*0e209d39SAndroid Build Coastguard Worker 
856*0e209d39SAndroid Build Coastguard Worker     /**
857*0e209d39SAndroid Build Coastguard Worker      * <p>Clone object so that caller can own the copy.  In ICU2.4, UObject doesn't define
858*0e209d39SAndroid Build Coastguard Worker      * clone, so we need an instance-aware method that knows how to do this.
859*0e209d39SAndroid Build Coastguard Worker      * This is public so factories can call it, but should really be protected.</p>
860*0e209d39SAndroid Build Coastguard Worker      *
861*0e209d39SAndroid Build Coastguard Worker      * @param instance the service instance to clone.
862*0e209d39SAndroid Build Coastguard Worker      * @return a clone of the passed-in instance, or nullptr if cloning was unsuccessful.
863*0e209d39SAndroid Build Coastguard Worker      */
864*0e209d39SAndroid Build Coastguard Worker     virtual UObject* cloneInstance(UObject* instance) const = 0;
865*0e209d39SAndroid Build Coastguard Worker 
866*0e209d39SAndroid Build Coastguard Worker 
867*0e209d39SAndroid Build Coastguard Worker     /************************************************************************
868*0e209d39SAndroid Build Coastguard Worker      * Subclassing API
869*0e209d39SAndroid Build Coastguard Worker      */
870*0e209d39SAndroid Build Coastguard Worker 
871*0e209d39SAndroid Build Coastguard Worker  protected:
872*0e209d39SAndroid Build Coastguard Worker 
873*0e209d39SAndroid Build Coastguard Worker     /**
874*0e209d39SAndroid Build Coastguard Worker      * <p>Create a factory that wraps a single service object.  Called by registerInstance.</p>
875*0e209d39SAndroid Build Coastguard Worker      *
876*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation returns an instance of SimpleFactory.</p>
877*0e209d39SAndroid Build Coastguard Worker      *
878*0e209d39SAndroid Build Coastguard Worker      * @param instanceToAdopt the service instance to adopt.
879*0e209d39SAndroid Build Coastguard Worker      * @param id the ID to assign to this service instance.
880*0e209d39SAndroid Build Coastguard Worker      * @param visible if true, the ID will be visible.
881*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
882*0e209d39SAndroid Build Coastguard Worker      * @return an instance of ICUServiceFactory that maps this instance to the provided ID.
883*0e209d39SAndroid Build Coastguard Worker      */
884*0e209d39SAndroid Build Coastguard Worker     virtual ICUServiceFactory* createSimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible, UErrorCode& status);
885*0e209d39SAndroid Build Coastguard Worker 
886*0e209d39SAndroid Build Coastguard Worker     /**
887*0e209d39SAndroid Build Coastguard Worker      * <p>Reinitialize the factory list to its default state.  After this call, isDefault()
888*0e209d39SAndroid Build Coastguard Worker      * must return true.</p>
889*0e209d39SAndroid Build Coastguard Worker      *
890*0e209d39SAndroid Build Coastguard Worker      * <p>This issues a serviceChanged notification to registered listeners.</p>
891*0e209d39SAndroid Build Coastguard Worker      *
892*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation clears the factory list.
893*0e209d39SAndroid Build Coastguard Worker      * Subclasses can override to provide other default initialization
894*0e209d39SAndroid Build Coastguard Worker      * of the factory list.  Subclasses must not call this method
895*0e209d39SAndroid Build Coastguard Worker      * directly, since it must only be called while holding write
896*0e209d39SAndroid Build Coastguard Worker      * access to the factory list.</p>
897*0e209d39SAndroid Build Coastguard Worker      */
898*0e209d39SAndroid Build Coastguard Worker     virtual void reInitializeFactories();
899*0e209d39SAndroid Build Coastguard Worker 
900*0e209d39SAndroid Build Coastguard Worker     /**
901*0e209d39SAndroid Build Coastguard Worker      * <p>Default handler for this service if no factory in the factory list
902*0e209d39SAndroid Build Coastguard Worker      * handled the key passed to getKey.</p>
903*0e209d39SAndroid Build Coastguard Worker      *
904*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation returns nullptr.</p>
905*0e209d39SAndroid Build Coastguard Worker      *
906*0e209d39SAndroid Build Coastguard Worker      * @param key the key.
907*0e209d39SAndroid Build Coastguard Worker      * @param actualReturn a pointer to a UnicodeString to hold the matched descriptor, or nullptr.
908*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
909*0e209d39SAndroid Build Coastguard Worker      * @return the service instance, or nullptr.
910*0e209d39SAndroid Build Coastguard Worker      */
911*0e209d39SAndroid Build Coastguard Worker     virtual UObject* handleDefault(const ICUServiceKey& key, UnicodeString* actualReturn, UErrorCode& status) const;
912*0e209d39SAndroid Build Coastguard Worker 
913*0e209d39SAndroid Build Coastguard Worker     /**
914*0e209d39SAndroid Build Coastguard Worker      * <p>Clear caches maintained by this service.</p>
915*0e209d39SAndroid Build Coastguard Worker      *
916*0e209d39SAndroid Build Coastguard Worker      * <p>Subclasses can override if they implement additional caches
917*0e209d39SAndroid Build Coastguard Worker      * that need to be cleared when the service changes.  Subclasses
918*0e209d39SAndroid Build Coastguard Worker      * should generally not call this method directly, as it must only
919*0e209d39SAndroid Build Coastguard Worker      * be called while synchronized on the factory lock.</p>
920*0e209d39SAndroid Build Coastguard Worker      */
921*0e209d39SAndroid Build Coastguard Worker     virtual void clearCaches();
922*0e209d39SAndroid Build Coastguard Worker 
923*0e209d39SAndroid Build Coastguard Worker     /**
924*0e209d39SAndroid Build Coastguard Worker      * <p>Return true if the listener is accepted.</p>
925*0e209d39SAndroid Build Coastguard Worker      *
926*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation accepts the listener if it is
927*0e209d39SAndroid Build Coastguard Worker      * a ServiceListener.  Subclasses can override this to accept
928*0e209d39SAndroid Build Coastguard Worker      * different listeners.</p>
929*0e209d39SAndroid Build Coastguard Worker      *
930*0e209d39SAndroid Build Coastguard Worker      * @param l the listener to test.
931*0e209d39SAndroid Build Coastguard Worker      * @return true if the service accepts the listener.
932*0e209d39SAndroid Build Coastguard Worker      */
933*0e209d39SAndroid Build Coastguard Worker     virtual UBool acceptsListener(const EventListener& l) const override;
934*0e209d39SAndroid Build Coastguard Worker 
935*0e209d39SAndroid Build Coastguard Worker     /**
936*0e209d39SAndroid Build Coastguard Worker      * <p>Notify the listener of a service change.</p>
937*0e209d39SAndroid Build Coastguard Worker      *
938*0e209d39SAndroid Build Coastguard Worker      * <p>The default implementation assumes a ServiceListener.
939*0e209d39SAndroid Build Coastguard Worker      * If acceptsListener has been overridden to accept different
940*0e209d39SAndroid Build Coastguard Worker      * listeners, this should be overridden as well.</p>
941*0e209d39SAndroid Build Coastguard Worker      *
942*0e209d39SAndroid Build Coastguard Worker      * @param l the listener to notify.
943*0e209d39SAndroid Build Coastguard Worker      */
944*0e209d39SAndroid Build Coastguard Worker     virtual void notifyListener(EventListener& l) const override;
945*0e209d39SAndroid Build Coastguard Worker 
946*0e209d39SAndroid Build Coastguard Worker     /************************************************************************
947*0e209d39SAndroid Build Coastguard Worker      * Utilities for subclasses.
948*0e209d39SAndroid Build Coastguard Worker      */
949*0e209d39SAndroid Build Coastguard Worker 
950*0e209d39SAndroid Build Coastguard Worker     /**
951*0e209d39SAndroid Build Coastguard Worker      * <p>Clear only the service cache.</p>
952*0e209d39SAndroid Build Coastguard Worker      *
953*0e209d39SAndroid Build Coastguard Worker      * <p>This can be called by subclasses when a change affects the service
954*0e209d39SAndroid Build Coastguard Worker      * cache but not the ID caches, e.g., when the default locale changes
955*0e209d39SAndroid Build Coastguard Worker      * the resolution of IDs also changes, requiring the cache to be
956*0e209d39SAndroid Build Coastguard Worker      * flushed, but not the visible IDs themselves.</p>
957*0e209d39SAndroid Build Coastguard Worker      */
958*0e209d39SAndroid Build Coastguard Worker     void clearServiceCache();
959*0e209d39SAndroid Build Coastguard Worker 
960*0e209d39SAndroid Build Coastguard Worker     /**
961*0e209d39SAndroid Build Coastguard Worker      * <p>Return a map from visible IDs to factories.
962*0e209d39SAndroid Build Coastguard Worker      * This must only be called when the mutex is held.</p>
963*0e209d39SAndroid Build Coastguard Worker      *
964*0e209d39SAndroid Build Coastguard Worker      * @param status the error code status.
965*0e209d39SAndroid Build Coastguard Worker      * @return a Hashtable containing mappings from visible
966*0e209d39SAndroid Build Coastguard Worker      * IDs to factories.
967*0e209d39SAndroid Build Coastguard Worker      */
968*0e209d39SAndroid Build Coastguard Worker     const Hashtable* getVisibleIDMap(UErrorCode& status) const;
969*0e209d39SAndroid Build Coastguard Worker 
970*0e209d39SAndroid Build Coastguard Worker     /**
971*0e209d39SAndroid Build Coastguard Worker      * <p>Allow subclasses to read the time stamp.</p>
972*0e209d39SAndroid Build Coastguard Worker      *
973*0e209d39SAndroid Build Coastguard Worker      * @return the timestamp.
974*0e209d39SAndroid Build Coastguard Worker      */
975*0e209d39SAndroid Build Coastguard Worker     int32_t getTimestamp() const;
976*0e209d39SAndroid Build Coastguard Worker 
977*0e209d39SAndroid Build Coastguard Worker     /**
978*0e209d39SAndroid Build Coastguard Worker      * <p>Return the number of registered factories.</p>
979*0e209d39SAndroid Build Coastguard Worker      *
980*0e209d39SAndroid Build Coastguard Worker      * @return the number of factories registered at the time of the call.
981*0e209d39SAndroid Build Coastguard Worker      */
982*0e209d39SAndroid Build Coastguard Worker     int32_t countFactories() const;
983*0e209d39SAndroid Build Coastguard Worker 
984*0e209d39SAndroid Build Coastguard Worker private:
985*0e209d39SAndroid Build Coastguard Worker 
986*0e209d39SAndroid Build Coastguard Worker     friend class ::ICUServiceTest; // give tests access to countFactories.
987*0e209d39SAndroid Build Coastguard Worker };
988*0e209d39SAndroid Build Coastguard Worker 
989*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
990*0e209d39SAndroid Build Coastguard Worker 
991*0e209d39SAndroid Build Coastguard Worker     /* UCONFIG_NO_SERVICE */
992*0e209d39SAndroid Build Coastguard Worker #endif
993*0e209d39SAndroid Build Coastguard Worker 
994*0e209d39SAndroid Build Coastguard Worker     /* ICUSERV_H */
995*0e209d39SAndroid Build Coastguard Worker #endif
996*0e209d39SAndroid Build Coastguard Worker 
997