Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/icuplug.h
48725 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3******************************************************************************4*5* Copyright (C) 2009-2015, International Business Machines6* Corporation and others. All Rights Reserved.7*8******************************************************************************9*10* FILE NAME : icuplug.h11*12* Date Name Description13* 10/29/2009 sl New.14******************************************************************************15*/1617/**18* \file19* \brief C API: ICU Plugin API20*21* <h2>C API: ICU Plugin API</h2>22*23* <p>C API allowing run-time loadable modules that extend or modify ICU functionality.</p>24*25* <h3>Loading and Configuration</h3>26*27* <p>At ICU startup time, the environment variable "ICU_PLUGINS" will be28* queried for a directory name. If it is not set, the preprocessor symbol29* "DEFAULT_ICU_PLUGINS" will be checked for a default value.</p>30*31* <p>Within the above-named directory, the file "icuplugins##.txt" will be32* opened, if present, where ## is the major+minor number of the currently33* running ICU (such as, 44 for ICU 4.4, thus icuplugins44.txt)</p>34*35* <p>The configuration file has this format:</p>36*37* <ul>38* <li>Hash (#) begins a comment line</li>39*40* <li>Non-comment lines have two or three components:41* LIBRARYNAME ENTRYPOINT [ CONFIGURATION .. ]</li>42*43* <li>Tabs or spaces separate the three items.</li>44*45* <li>LIBRARYNAME is the name of a shared library, either a short name if46* it is on the loader path, or a full pathname.</li>47*48* <li>ENTRYPOINT is the short (undecorated) symbol name of the plugin's49* entrypoint, as above.</li>50*51* <li>CONFIGURATION is the entire rest of the line . It's passed as-is to52* the plugin.</li>53* </ul>54*55* <p>An example configuration file is, in its entirety:</p>56*57* \code58* # this is icuplugins44.txt59* testplug.dll myPlugin hello=world60* \endcode61* <p>Plugins are categorized as "high" or "low" level. Low level are those62* which must be run BEFORE high level plugins, and before any operations63* which cause ICU to be 'initialized'. If a plugin is low level but64* causes ICU to allocate memory or become initialized, that plugin is said65* to cause a 'level change'. </p>66*67* <p>At load time, ICU first queries all plugins to determine their level,68* then loads all 'low' plugins first, and then loads all 'high' plugins.69* Plugins are otherwise loaded in the order listed in the configuration file.</p>70*71* <h3>Implementing a Plugin</h3>72* \code73* U_CAPI UPlugTokenReturn U_EXPORT274* myPlugin (UPlugData *plug, UPlugReason reason, UErrorCode *status) {75* if(reason==UPLUG_REASON_QUERY) {76* uplug_setPlugName(plug, "Simple Plugin");77* uplug_setPlugLevel(plug, UPLUG_LEVEL_HIGH);78* } else if(reason==UPLUG_REASON_LOAD) {79* ... Set up some ICU things here....80* } else if(reason==UPLUG_REASON_UNLOAD) {81* ... unload, clean up ...82* }83* return UPLUG_TOKEN;84* }85* \endcode86*87* <p>The UPlugData* is an opaque pointer to the plugin-specific data, and is88* used in all other API calls.</p>89*90* <p>The API contract is:</p>91* <ol><li>The plugin MUST always return UPLUG_TOKEN as a return value- to92* indicate that it is a valid plugin.</li>93*94* <li>When the 'reason' parameter is set to UPLUG_REASON_QUERY, the95* plugin MUST call uplug_setPlugLevel() to indicate whether it is a high96* level or low level plugin.</li>97*98* <li>When the 'reason' parameter is UPLUG_REASON_QUERY, the plugin99* SHOULD call uplug_setPlugName to indicate a human readable plugin name.</li></ol>100*101*102* \internal ICU 4.4 Technology Preview103*/104105106#ifndef ICUPLUG_H107#define ICUPLUG_H108109#include "unicode/utypes.h"110111112#if UCONFIG_ENABLE_PLUGINS || defined(U_IN_DOXYGEN)113114115116/* === Basic types === */117118#ifndef U_HIDE_INTERNAL_API119/**120* @{121* Opaque structure passed to/from a plugin.122* use the APIs to access it.123* @internal ICU 4.4 Technology Preview124*/125126struct UPlugData;127typedef struct UPlugData UPlugData;128129/** @} */130131/**132* Random Token to identify a valid ICU plugin. Plugins must return this133* from the entrypoint.134* @internal ICU 4.4 Technology Preview135*/136#define UPLUG_TOKEN 0x54762486137138/**139* Max width of names, symbols, and configuration strings140* @internal ICU 4.4 Technology Preview141*/142#define UPLUG_NAME_MAX 100143144145/**146* Return value from a plugin entrypoint.147* Must always be set to UPLUG_TOKEN148* @see UPLUG_TOKEN149* @internal ICU 4.4 Technology Preview150*/151typedef uint32_t UPlugTokenReturn;152153/**154* Reason code for the entrypoint's call155* @internal ICU 4.4 Technology Preview156*/157typedef enum {158UPLUG_REASON_QUERY = 0, /**< The plugin is being queried for info. **/159UPLUG_REASON_LOAD = 1, /**< The plugin is being loaded. **/160UPLUG_REASON_UNLOAD = 2, /**< The plugin is being unloaded. **/161/**162* Number of known reasons.163* @internal The numeric value may change over time, see ICU ticket #12420.164*/165UPLUG_REASON_COUNT166} UPlugReason;167168169/**170* Level of plugin loading171* INITIAL: UNKNOWN172* QUERY: INVALID -> { LOW | HIGH }173* ERR -> INVALID174* @internal ICU 4.4 Technology Preview175*/176typedef enum {177UPLUG_LEVEL_INVALID = 0, /**< The plugin is invalid, hasn't called uplug_setLevel, or can't load. **/178UPLUG_LEVEL_UNKNOWN = 1, /**< The plugin is waiting to be installed. **/179UPLUG_LEVEL_LOW = 2, /**< The plugin must be called before u_init completes **/180UPLUG_LEVEL_HIGH = 3, /**< The plugin can run at any time. **/181/**182* Number of known levels.183* @internal The numeric value may change over time, see ICU ticket #12420.184*/185UPLUG_LEVEL_COUNT186} UPlugLevel;187188/**189* Entrypoint for an ICU plugin.190* @param plug the UPlugData handle.191* @param status the plugin's extended status code.192* @return A valid plugin must return UPLUG_TOKEN193* @internal ICU 4.4 Technology Preview194*/195typedef UPlugTokenReturn (U_EXPORT2 UPlugEntrypoint) (196UPlugData *plug,197UPlugReason reason,198UErrorCode *status);199200/* === Needed for Implementing === */201202/**203* Request that this plugin not be unloaded at cleanup time.204* This is appropriate for plugins which cannot be cleaned up.205* @see u_cleanup()206* @param plug plugin207* @param dontUnload set true if this plugin can't be unloaded208* @internal ICU 4.4 Technology Preview209*/210U_INTERNAL void U_EXPORT2211uplug_setPlugNoUnload(UPlugData *plug, UBool dontUnload);212213/**214* Set the level of this plugin.215* @param plug plugin data handle216* @param level the level of this plugin217* @internal ICU 4.4 Technology Preview218*/219U_INTERNAL void U_EXPORT2220uplug_setPlugLevel(UPlugData *plug, UPlugLevel level);221222/**223* Get the level of this plugin.224* @param plug plugin data handle225* @return the level of this plugin226* @internal ICU 4.4 Technology Preview227*/228U_INTERNAL UPlugLevel U_EXPORT2229uplug_getPlugLevel(UPlugData *plug);230231/**232* Get the lowest level of plug which can currently load.233* For example, if UPLUG_LEVEL_LOW is returned, then low level plugins may load234* if UPLUG_LEVEL_HIGH is returned, then only high level plugins may load.235* @return the lowest level of plug which can currently load236* @internal ICU 4.4 Technology Preview237*/238U_INTERNAL UPlugLevel U_EXPORT2239uplug_getCurrentLevel(void);240241242/**243* Get plug load status244* @return The error code of this plugin's load attempt.245* @internal ICU 4.4 Technology Preview246*/247U_INTERNAL UErrorCode U_EXPORT2248uplug_getPlugLoadStatus(UPlugData *plug);249250/**251* Set the human-readable name of this plugin.252* @param plug plugin data handle253* @param name the name of this plugin. The first UPLUG_NAME_MAX characters willi be copied into a new buffer.254* @internal ICU 4.4 Technology Preview255*/256U_INTERNAL void U_EXPORT2257uplug_setPlugName(UPlugData *plug, const char *name);258259/**260* Get the human-readable name of this plugin.261* @param plug plugin data handle262* @return the name of this plugin263* @internal ICU 4.4 Technology Preview264*/265U_INTERNAL const char * U_EXPORT2266uplug_getPlugName(UPlugData *plug);267268/**269* Return the symbol name for this plugin, if known.270* @param plug plugin data handle271* @return the symbol name, or NULL272* @internal ICU 4.4 Technology Preview273*/274U_INTERNAL const char * U_EXPORT2275uplug_getSymbolName(UPlugData *plug);276277/**278* Return the library name for this plugin, if known.279* @param plug plugin data handle280* @param status error code281* @return the library name, or NULL282* @internal ICU 4.4 Technology Preview283*/284U_INTERNAL const char * U_EXPORT2285uplug_getLibraryName(UPlugData *plug, UErrorCode *status);286287/**288* Return the library used for this plugin, if known.289* Plugins could use this to load data out of their290* @param plug plugin data handle291* @return the library, or NULL292* @internal ICU 4.4 Technology Preview293*/294U_INTERNAL void * U_EXPORT2295uplug_getLibrary(UPlugData *plug);296297/**298* Return the plugin-specific context data.299* @param plug plugin data handle300* @return the context, or NULL if not set301* @internal ICU 4.4 Technology Preview302*/303U_INTERNAL void * U_EXPORT2304uplug_getContext(UPlugData *plug);305306/**307* Set the plugin-specific context data.308* @param plug plugin data handle309* @param context new context to set310* @internal ICU 4.4 Technology Preview311*/312U_INTERNAL void U_EXPORT2313uplug_setContext(UPlugData *plug, void *context);314315316/**317* Get the configuration string, if available.318* The string is in the platform default codepage.319* @param plug plugin data handle320* @return configuration string, or else null.321* @internal ICU 4.4 Technology Preview322*/323U_INTERNAL const char * U_EXPORT2324uplug_getConfiguration(UPlugData *plug);325326/**327* Return all currently installed plugins, from newest to oldest328* Usage Example:329* \code330* UPlugData *plug = NULL;331* while(plug=uplug_nextPlug(plug)) {332* ... do something with 'plug' ...333* }334* \endcode335* Not thread safe- do not call while plugs are added or removed.336* @param prior pass in 'NULL' to get the first (most recent) plug,337* otherwise pass the value returned on a prior call to uplug_nextPlug338* @return the next oldest plugin, or NULL if no more.339* @internal ICU 4.4 Technology Preview340*/341U_INTERNAL UPlugData* U_EXPORT2342uplug_nextPlug(UPlugData *prior);343344/**345* Inject a plugin as if it were loaded from a library.346* This is useful for testing plugins.347* Note that it will have a 'NULL' library pointer associated348* with it, and therefore no llibrary will be closed at cleanup time.349* Low level plugins may not be able to load, as ordering can't be enforced.350* @param entrypoint entrypoint to install351* @param config user specified configuration string, if available, or NULL.352* @param status error result353* @return the new UPlugData associated with this plugin, or NULL if error.354* @internal ICU 4.4 Technology Preview355*/356U_INTERNAL UPlugData* U_EXPORT2357uplug_loadPlugFromEntrypoint(UPlugEntrypoint *entrypoint, const char *config, UErrorCode *status);358359360/**361* Inject a plugin from a library, as if the information came from a config file.362* Low level plugins may not be able to load, and ordering can't be enforced.363* @param libName DLL name to load364* @param sym symbol of plugin (UPlugEntrypoint function)365* @param config configuration string, or NULL366* @param status error result367* @return the new UPlugData associated with this plugin, or NULL if error.368* @internal ICU 4.4 Technology Preview369*/370U_INTERNAL UPlugData* U_EXPORT2371uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *config, UErrorCode *status);372373/**374* Remove a plugin.375* Will request the plugin to be unloaded, and close the library if needed376* @param plug plugin handle to close377* @param status error result378* @internal ICU 4.4 Technology Preview379*/380U_INTERNAL void U_EXPORT2381uplug_removePlug(UPlugData *plug, UErrorCode *status);382#endif /* U_HIDE_INTERNAL_API */383384#endif /* UCONFIG_ENABLE_PLUGINS */385386#endif /* _ICUPLUG */387388389390