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