1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_INITIALIZE_H
6 #define ICE_INITIALIZE_H
7 
8 #include <IceUtil/Timer.h>
9 #include <Ice/Communicator.h>
10 #include <Ice/PropertiesF.h>
11 #include <Ice/InstanceF.h>
12 #include <Ice/LoggerF.h>
13 #include <Ice/InstrumentationF.h>
14 #include <Ice/Dispatcher.h>
15 #include <Ice/FactoryTable.h>
16 #include <Ice/BuiltinSequences.h>
17 #include <Ice/Version.h>
18 #include <Ice/Plugin.h>
19 #include <Ice/BatchRequestInterceptor.h>
20 
21 #ifdef ICE_CPP11_MAPPING
22 #   define ICE_CONFIG_FILE_STRING const std::string&
23 #else
24 #   define ICE_CONFIG_FILE_STRING const char*
25 #endif
26 
27 namespace Ice
28 {
29 
30 /**
31  * Converts an argument vector into a string sequence.
32  * @param argc The number of arguments in argv.
33  * @param argv The arguments.
34  * @return A string sequence containing the arguments.
35  */
36 ICE_API StringSeq argsToStringSeq(int argc, const char* const argv[]);
37 
38 #ifdef _WIN32
39 /**
40  * Converts an argument vector into a string sequence.
41  * @param argc The number of arguments in argv.
42  * @param argv The arguments.
43  * @return A string sequence containing the arguments.
44  */
45 ICE_API StringSeq argsToStringSeq(int argc, const wchar_t* const argv[]);
46 #endif
47 
48 /**
49  * Updates the argument vector to match the contents of the string sequence.
50  * This function assumes that the string sequence only contains
51  * elements of the argument vector. The function shifts the
52  * the argument vector elements so that the vector matches the
53  * contents of the sequence.
54  * @param seq The string sequence returned from a call to argsToStringSeq.
55  * @param argc Updated to reflect the size of the sequence.
56  * @param argv Elements are shifted to match the sequence.
57  */
58 ICE_API void stringSeqToArgs(const StringSeq& seq, int& argc, const char* argv[]);
59 
60 /**
61  * Updates the argument vector to match the contents of the string sequence.
62  * This function assumes that the string sequence only contains
63  * elements of the argument vector. The function shifts the
64  * the argument vector elements so that the vector matches the
65  * contents of the sequence.
66  * @param seq The string sequence returned from a call to argsToStringSeq.
67  * @param argc Updated to reflect the size of the sequence.
68  * @param argv Elements are shifted to match the sequence.
69  */
stringSeqToArgs(const StringSeq & seq,int & argc,char * argv[])70 inline void stringSeqToArgs(const StringSeq& seq, int& argc, char* argv[])
71 {
72     return stringSeqToArgs(seq, argc, const_cast<const char**>(argv));
73 }
74 
75 #ifdef _WIN32
76 /**
77  * Updates the argument vector to match the contents of the string sequence.
78  * This function assumes that the string sequence only contains
79  * elements of the argument vector. The function shifts the
80  * the argument vector elements so that the vector matches the
81  * contents of the sequence.
82  * @param seq The string sequence returned from a call to argsToStringSeq.
83  */
84 ICE_API void stringSeqToArgs(const StringSeq& seq, int& argc, const wchar_t* argv[]);
85 
86 /**
87  * Updates the argument vector to match the contents of the string sequence.
88  * This function assumes that the string sequence only contains
89  * elements of the argument vector. The function shifts the
90  * the argument vector elements so that the vector matches the
91  * contents of the sequence.
92  * @param seq The string sequence returned from a call to argsToStringSeq.
93  */
stringSeqToArgs(const StringSeq & seq,int & argc,wchar_t * argv[])94 inline void stringSeqToArgs(const StringSeq& seq, int& argc, wchar_t* argv[])
95 {
96     return stringSeqToArgs(seq, argc, const_cast<const wchar_t**>(argv));
97 }
98 #endif
99 
100 /**
101  * Creates a new empty property set.
102  *
103  * @return A new empty property set.
104  */
105 ICE_API PropertiesPtr createProperties();
106 
107 /**
108  * Creates a property set initialized from command-line arguments
109  * and a default property set.
110  *
111  * @param seq Command-line arguments, possibly containing
112  * options to set properties. If the arguments include
113  * a <code>--Ice.Config</code> option, the corresponding configuration
114  * files are parsed. If the same property is set in a configuration
115  * file and in the arguments, the arguments take precedence.
116  * Recognized options are removed from this container upon return.
117  *
118  * @param defaults Default values for the property set. Settings in
119  * configuration files and the arguments override these defaults.
120  *
121  * @return A new property set initialized with the property settings
122  * that were removed from the argument vector.
123  */
124 ICE_API PropertiesPtr createProperties(StringSeq& seq, const PropertiesPtr& defaults = 0);
125 
126 /**
127  * Creates a property set initialized from command-line arguments
128  * and a default property set.
129  *
130  * @param argc The number of arguments in argv. Upon return, this argument
131  * is updated to reflect the arguments still remaining in argv.
132  * @param argv Command-line arguments, possibly containing
133  * options to set properties. If the arguments include
134  * a <code>--Ice.Config</code> option, the corresponding configuration
135  * files are parsed. If the same property is set in a configuration
136  * file and in the arguments, the arguments take precedence.
137  * Recognized options are removed from this vector upon return.
138  *
139  * @param defaults Default values for the property set. Settings in
140  * configuration files and the arguments override these defaults.
141  *
142  * @return A new property set initialized with the property settings
143  * that were removed from the argument vector.
144  */
145 ICE_API PropertiesPtr createProperties(int& argc, const char* argv[], const PropertiesPtr& defaults = 0);
146 
147 /**
148  * Creates a property set initialized from command-line arguments
149  * and a default property set.
150  *
151  * @param argc The number of arguments in argv. Upon return, this argument
152  * is updated to reflect the arguments still remaining in argv.
153  * @param argv Command-line arguments, possibly containing
154  * options to set properties. If the arguments include
155  * a <code>--Ice.Config</code> option, the corresponding configuration
156  * files are parsed. If the same property is set in a configuration
157  * file and in the arguments, the arguments take precedence.
158  * Recognized options are removed from this vector upon return.
159  *
160  * @param defaults Default values for the property set. Settings in
161  * configuration files and the arguments override these defaults.
162  *
163  * @return A new property set initialized with the property settings
164  * that were removed from the argument vector.
165  */
166 inline PropertiesPtr createProperties(int& argc, char* argv[], const PropertiesPtr& defaults = 0)
167 {
168     return createProperties(argc, const_cast<const char**>(argv), defaults);
169 }
170 
171 #ifdef _WIN32
172 /**
173  * Creates a property set initialized from command-line arguments
174  * and a default property set.
175  *
176  * @param argc The number of arguments in argv. Upon return, this argument
177  * is updated to reflect the arguments still remaining in argv.
178  * @param argv Command-line arguments, possibly containing
179  * options to set properties. If the arguments include
180  * a <code>--Ice.Config</code> option, the corresponding configuration
181  * files are parsed. If the same property is set in a configuration
182  * file and in the arguments, the arguments take precedence.
183  * Recognized options are removed from this vector upon return.
184  *
185  * @param defaults Default values for the property set. Settings in
186  * configuration files and the arguments override these defaults.
187  *
188  * @return A new property set initialized with the property settings
189  * that were removed from the argument vector.
190  */
191 ICE_API PropertiesPtr createProperties(int& argc, const wchar_t* argv[], const PropertiesPtr& defaults = 0);
192 
193 /**
194  * Creates a property set initialized from command-line arguments
195  * and a default property set.
196  *
197  * @param argc The number of arguments in argv. Upon return, this argument
198  * is updated to reflect the arguments still remaining in argv.
199  * @param argv Command-line arguments, possibly containing
200  * options to set properties. If the arguments include
201  * a <code>--Ice.Config</code> option, the corresponding configuration
202  * files are parsed. If the same property is set in a configuration
203  * file and in the arguments, the arguments take precedence.
204  * Recognized options are removed from this vector upon return.
205  *
206  * @param defaults Default values for the property set. Settings in
207  * configuration files and the arguments override these defaults.
208  *
209  * @return A new property set initialized with the property settings
210  * that were removed from the argument vector.
211  */
212 inline PropertiesPtr createProperties(int& argc, wchar_t* argv[], const PropertiesPtr& defaults = 0)
213 {
214     return createProperties(argc, const_cast<const wchar_t**>(argv), defaults);
215 }
216 #endif
217 
218 /**
219  * Base class for a thread notification hook. An application can subclass this class,
220  * implement start and stop, and install an instance in InitializationData in order
221  * to receive notifications when Ice threads are started and stopped.
222  * \headerfile Ice/Ice.h
223  */
224 class ICE_API ThreadNotification : public IceUtil::Shared
225 {
226 public:
227 
228     /**
229      * Called from the new Ice thread at startup.
230      */
231     virtual void start() = 0;
232 
233     /**
234      * Called from an Ice thread that is about to stop.
235      */
236     virtual void stop() = 0;
237 };
238 
239 typedef IceUtil::Handle<ThreadNotification> ThreadNotificationPtr;
240 
241 /**
242  * A special plug-in that installs a thread hook during a communicator's initialization.
243  * Both initialize and destroy are no-op. See InitializationData.
244  * \headerfile Ice/Ice.h
245  */
246 class ICE_API ThreadHookPlugin : public Ice::Plugin
247 {
248 public:
249 
250 #ifdef ICE_CPP11_MAPPING
251     /**
252      * Installs the thread hooks.
253      * @param communicator The communicator in which to install the thread hooks.
254      * @param start The start callback.
255      * @param stop The stop callback.
256      */
257     ThreadHookPlugin(const CommunicatorPtr& communicator, std::function<void()> start, std::function<void()> stop);
258 #else
259     /**
260      * Installs the thread hooks.
261      * @param communicator The communicator in which to install the thread hooks.
262      * @param hook The thread notification callback object.
263      */
264     ThreadHookPlugin(const CommunicatorPtr& communicator, const ThreadNotificationPtr& hook);
265 #endif
266 
267     /** Not used. */
268     virtual void initialize();
269 
270     /** Not used. */
271     virtual void destroy();
272 };
273 
274 /**
275  * Encapsulates data to initialize a communicator.
276  * \headerfile Ice/Ice.h
277  */
278 struct InitializationData
279 {
280     /**
281      * The properties for the communicator.
282      */
283     PropertiesPtr properties;
284 
285     /**
286      * The logger for the communicator.
287      */
288     LoggerPtr logger;
289 
290     /**
291      * The communicator observer used by the Ice run-time.
292      */
293     Instrumentation::CommunicatorObserverPtr observer;
294 
295 #ifdef ICE_CPP11_MAPPING
296 
297 #if defined(__clang__)
298 #   pragma clang diagnostic push
299 #   pragma clang diagnostic ignored "-Wdocumentation" // param/return is not recognized for std::function data members
300 #endif
301 
302     /**
303      * Called whenever the communicator starts a new thread.
304      */
305     std::function<void()> threadStart;
306 
307     /**
308      * Called whenever a thread created by the communicator is about to be destroyed.
309      */
310     std::function<void()> threadStop;
311 
312     /**
313       * You can control which thread receives operation invocations and AMI
314       * callbacks by supplying a dispatcher.
315       *
316       * For example, you can use this dispatching facility to ensure that
317       * all invocations and callbacks are dispatched in a GUI event loop
318       * thread so that it is safe to invoke directly on GUI objects.
319       *
320       * The dispatcher is responsible for running (dispatching) the
321       * invocation or AMI callback on its favorite thread.
322       * @param call Represents the invocation. The dispatcher must eventually invoke this function.
323       * @param con The connection associated with this dispatch, or nil if no connection is
324       * associated with it.
325       */
326     std::function<void(std::function<void()> call, const std::shared_ptr<Ice::Connection>& con)> dispatcher;
327 
328     /**
329      * Applications that make use of compact type IDs to conserve space
330      * when marshaling class instances, and also use the streaming API to
331      * extract such classes, can intercept the translation between compact
332      * type IDs and their corresponding string type IDs by installing a
333      * compact ID resolver.
334      * @param id The compact ID.
335      * @return The fully-scoped type ID such as "::Module::Class", or an empty string if
336      * the compact ID is unknown.
337      */
338     std::function<std::string(int id)> compactIdResolver;
339 
340     /**
341      * The batch request interceptor, which is called by the Ice run time to enqueue a batch request.
342      * @param req An object representing the batch request.
343      * @param count The number of requests currently in the queue.
344      * @param size The number of bytes consumed by the requests currently in the queue.
345      */
346     std::function<void(const Ice::BatchRequest& req, int count, int size)> batchRequestInterceptor;
347 
348 #if defined(__clang__)
349 #   pragma clang diagnostic pop
350 #endif
351 
352 #else
353     /**
354      * The thread hook for the communicator.
355      */
356     ThreadNotificationPtr threadHook;
357 
358     /**
359       * You can control which thread receives operation invocations and AMI
360       * callbacks by supplying a dispatcher.
361       *
362       * For example, you can use this dispatching facility to ensure that
363       * all invocations and callbacks are dispatched in a GUI event loop
364       * thread so that it is safe to invoke directly on GUI objects.
365       *
366       * The dispatcher is responsible for running (dispatching) the
367       * invocation or AMI callback on its favorite thread. It must eventually
368       * execute the provided call.
369       */
370     DispatcherPtr dispatcher;
371 
372     /**
373      * Applications that make use of compact type IDs to conserve space
374      * when marshaling class instances, and also use the streaming API to
375      * extract such classes, can intercept the translation between compact
376      * type IDs and their corresponding string type IDs by installing a
377      * compact ID resolver.
378      */
379     CompactIdResolverPtr compactIdResolver;
380 
381     /**
382      * The batch request interceptor.
383      */
384     BatchRequestInterceptorPtr batchRequestInterceptor;
385 #endif
386 
387     /**
388      * The value factory manager.
389      */
390     ValueFactoryManagerPtr valueFactoryManager;
391 };
392 
393 /**
394  * Initializes a new communicator.
395  * @param argc The number of arguments in argv. Upon return, this argument
396  * is updated to reflect the arguments still remaining in argv.
397  * @param argv Command-line arguments, possibly containing
398  * options to set properties. If the arguments include
399  * a <code>--Ice.Config</code> option, the corresponding configuration
400  * files are parsed. If the same property is set in a configuration
401  * file and in the arguments, the arguments take precedence.
402  * Recognized options are removed from this vector upon return.
403  * @param initData Configuration data for the new Communicator.
404  * @param version Indicates the Ice version with which the application is compatible. If not
405  * specified, the version of the Ice installation is used.
406  * @return The new communicator.
407  */
408 ICE_API CommunicatorPtr initialize(int& argc, const char* argv[],
409                                    const InitializationData& initData = InitializationData(),
410                                    int version = ICE_INT_VERSION);
411 
412 /**
413  * Initializes a new communicator.
414  * @param argc The number of arguments in argv. Upon return, this argument
415  * is updated to reflect the arguments still remaining in argv.
416  * @param argv Command-line arguments, possibly containing
417  * options to set properties. If the arguments include
418  * a <code>--Ice.Config</code> option, the corresponding configuration
419  * files are parsed. If the same property is set in a configuration
420  * file and in the arguments, the arguments take precedence.
421  * Recognized options are removed from this vector upon return.
422  * @param initData Configuration data for the new Communicator.
423  * @param version Indicates the Ice version with which the application is compatible. If not
424  * specified, the version of the Ice installation is used.
425  * @return The new communicator.
426  */
427 inline CommunicatorPtr initialize(int& argc, char* argv[], const InitializationData& initData = InitializationData(),
428                                    int version = ICE_INT_VERSION)
429 {
430     return initialize(argc, const_cast<const char**>(argv), initData, version);
431 }
432 
433 /**
434  * Initializes a new communicator.
435  * @param argc The number of arguments in argv. Upon return, this argument
436  * is updated to reflect the arguments still remaining in argv.
437  * @param argv Command-line arguments, possibly containing
438  * options to set properties. If the arguments include
439  * a <code>--Ice.Config</code> option, the corresponding configuration
440  * files are parsed. If the same property is set in a configuration
441  * file and in the arguments, the arguments take precedence.
442  * Recognized options are removed from this vector upon return.
443  * @param configFile The name of an Ice configuration file.
444  * @param version Indicates the Ice version with which the application is compatible. If not
445  * specified, the version of the Ice installation is used.
446  * @return The new communicator.
447  */
448 ICE_API CommunicatorPtr initialize(int& argc, const char* argv[], ICE_CONFIG_FILE_STRING configFile,
449                                    int version = ICE_INT_VERSION);
450 
451 /**
452  * Initializes a new communicator.
453  * @param argc The number of arguments in argv. Upon return, this argument
454  * is updated to reflect the arguments still remaining in argv.
455  * @param argv Command-line arguments, possibly containing
456  * options to set properties. If the arguments include
457  * a <code>--Ice.Config</code> option, the corresponding configuration
458  * files are parsed. If the same property is set in a configuration
459  * file and in the arguments, the arguments take precedence.
460  * Recognized options are removed from this vector upon return.
461  * @param configFile The name of an Ice configuration file.
462  * @param version Indicates the Ice version with which the application is compatible. If not
463  * specified, the version of the Ice installation is used.
464  * @return The new communicator.
465  */
466 inline CommunicatorPtr initialize(int& argc, char* argv[], ICE_CONFIG_FILE_STRING configFile,
467                                   int version = ICE_INT_VERSION)
468 {
469     return initialize(argc, const_cast<const char**>(argv), configFile, version);
470 }
471 
472 #ifdef _WIN32
473 /**
474  * Initializes a new communicator.
475  * @param argc The number of arguments in argv. Upon return, this argument
476  * is updated to reflect the arguments still remaining in argv.
477  * @param argv Command-line arguments, possibly containing
478  * options to set properties. If the arguments include
479  * a <code>--Ice.Config</code> option, the corresponding configuration
480  * files are parsed. If the same property is set in a configuration
481  * file and in the arguments, the arguments take precedence.
482  * Recognized options are removed from this vector upon return.
483  * @param initData Configuration data for the new Communicator.
484  * @param version Indicates the Ice version with which the application is compatible. If not
485  * specified, the version of the Ice installation is used.
486  * @return The new communicator.
487  */
488 ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[],
489                                    const InitializationData& initData = InitializationData(),
490                                    int version = ICE_INT_VERSION);
491 
492 /**
493  * Initializes a new communicator.
494  * @param argc The number of arguments in argv. Upon return, this argument
495  * is updated to reflect the arguments still remaining in argv.
496  * @param argv Command-line arguments, possibly containing
497  * options to set properties. If the arguments include
498  * a <code>--Ice.Config</code> option, the corresponding configuration
499  * files are parsed. If the same property is set in a configuration
500  * file and in the arguments, the arguments take precedence.
501  * Recognized options are removed from this vector upon return.
502  * @param initData Configuration data for the new Communicator.
503  * @param version Indicates the Ice version with which the application is compatible. If not
504  * specified, the version of the Ice installation is used.
505  * @return The new communicator.
506  */
507 inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], const InitializationData& initData = InitializationData(),
508                                    int version = ICE_INT_VERSION)
509 {
510     return initialize(argc, const_cast<const wchar_t**>(argv), initData, version);
511 }
512 
513 /**
514  * Initializes a new communicator.
515  * @param argc The number of arguments in argv. Upon return, this argument
516  * is updated to reflect the arguments still remaining in argv.
517  * @param argv Command-line arguments, possibly containing
518  * options to set properties. If the arguments include
519  * a <code>--Ice.Config</code> option, the corresponding configuration
520  * files are parsed. If the same property is set in a configuration
521  * file and in the arguments, the arguments take precedence.
522  * Recognized options are removed from this vector upon return.
523  * @param configFile The name of an Ice configuration file.
524  * @param version Indicates the Ice version with which the application is compatible. If not
525  * specified, the version of the Ice installation is used.
526  * @return The new communicator.
527  */
528 ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[], ICE_CONFIG_FILE_STRING configFile,
529                                    int version = ICE_INT_VERSION);
530 
531 /**
532  * Initializes a new communicator.
533  * @param argc The number of arguments in argv. Upon return, this argument
534  * is updated to reflect the arguments still remaining in argv.
535  * @param argv Command-line arguments, possibly containing
536  * options to set properties. If the arguments include
537  * a <code>--Ice.Config</code> option, the corresponding configuration
538  * files are parsed. If the same property is set in a configuration
539  * file and in the arguments, the arguments take precedence.
540  * Recognized options are removed from this vector upon return.
541  * @param configFile The name of an Ice configuration file.
542  * @param version Indicates the Ice version with which the application is compatible. If not
543  * specified, the version of the Ice installation is used.
544  * @return The new communicator.
545  */
546 inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], ICE_CONFIG_FILE_STRING configFile,
547                                   int version = ICE_INT_VERSION)
548 {
549     return initialize(argc, const_cast<const wchar_t**>(argv), configFile, version);
550 }
551 #endif
552 
553 /**
554  * Initializes a new communicator.
555  * @param seq Command-line arguments, possibly containing
556  * options to set properties. If the arguments include
557  * a <code>--Ice.Config</code> option, the corresponding configuration
558  * files are parsed. If the same property is set in a configuration
559  * file and in the arguments, the arguments take precedence.
560  * Recognized options are removed from this container upon return.
561  * @param initData Configuration data for the new Communicator.
562  * @param version Indicates the Ice version with which the application is compatible. If not
563  * specified, the version of the Ice installation is used.
564  * @return The new communicator.
565  */
566 ICE_API CommunicatorPtr initialize(StringSeq& seq, const InitializationData& initData = InitializationData(),
567                                    int version = ICE_INT_VERSION);
568 
569 /**
570  * Initializes a new communicator.
571  * @param seq Command-line arguments, possibly containing
572  * options to set properties. If the arguments include
573  * a <code>--Ice.Config</code> option, the corresponding configuration
574  * files are parsed. If the same property is set in a configuration
575  * file and in the arguments, the arguments take precedence.
576  * Recognized options are removed from this container upon return.
577  * @param configFile The name of an Ice configuration file.
578  * @param version Indicates the Ice version with which the application is compatible. If not
579  * specified, the version of the Ice installation is used.
580  * @return The new communicator.
581  */
582 ICE_API CommunicatorPtr initialize(StringSeq& seq, ICE_CONFIG_FILE_STRING configFile, int version = ICE_INT_VERSION);
583 
584 /**
585  * Initializes a new communicator.
586  * @param initData Configuration data for the new Communicator.
587  * @param version Indicates the Ice version with which the application is compatible. If not
588  * specified, the version of the Ice installation is used.
589  * @return The new communicator.
590  */
591 ICE_API CommunicatorPtr initialize(const InitializationData& initData = InitializationData(),
592                                    int version = ICE_INT_VERSION);
593 
594 /**
595  * Initializes a new communicator.
596  * @param configFile The name of an Ice configuration file.
597  * @param version Indicates the Ice version with which the application is compatible. If not
598  * specified, the version of the Ice installation is used.
599  * @return The new communicator.
600  */
601 ICE_API CommunicatorPtr initialize(ICE_CONFIG_FILE_STRING configFile, int version = ICE_INT_VERSION);
602 
603 /**
604  * Obtains the per-process logger. This logger is used by all communicators that do not have their
605  * own specific logger established at the time a communicator is created.
606  * @return The current per-process logger instance.
607  */
608 ICE_API LoggerPtr getProcessLogger();
609 
610 /**
611  * Sets the per-process logger. This logger is used by all communicators that do not have their
612  * own specific logger established at the time a communicator is created.
613  * @param logger The new per-process logger instance.
614  */
615 ICE_API void setProcessLogger(const LoggerPtr& logger);
616 
617 /**
618  * A plug-in factory function is responsible for creating an Ice plug-in.
619  * @param communicator The communicator in which the plug-in will be installed.
620  * @param name The name assigned to the plug-in.
621  * @param args Additional arguments included in the plug-in's configuration.
622  * @return The new plug-in object. Returning nil will cause the run time to raise PluginInitializationException.
623  */
624 typedef Ice::Plugin* (*PluginFactory)(const ::Ice::CommunicatorPtr& communicator, const std::string& name,
625                                       const ::Ice::StringSeq& args);
626 
627 /**
628  * Manually registers a plug-in factory function.
629  * @param name The name assigned to the plug-in.
630  * @param factory The factory function.
631  * @param loadOnInit If true, the plug-in is always loaded (created) during communicator initialization,
632  * even if Ice.Plugin.name is not set. When false, the plug-in is loaded (created) during communication
633  * initialization only if Ice.Plugin.name  is set to a non-empty value (e.g.: Ice.Plugin.IceSSL=1).
634  */
635 ICE_API void registerPluginFactory(const std::string& name, PluginFactory factory, bool loadOnInit);
636 
637 /**
638  * A helper class that uses Resource Acquisition Is Initialization (RAII) to initialize and hold a
639  * communicator instance, and automatically destroy the communicator when the holder goes out of scope.
640  * \headerfile Ice/Ice.h
641  */
642 class ICE_API CommunicatorHolder
643 {
644 public:
645 
646     /**
647      * The holder's initial state is empty.
648      */
649     CommunicatorHolder();
650 
651 #ifdef ICE_CPP11_MAPPING
652 
653     /**
654      * Calls initialize to create a communicator with the provided arguments.
655      * This constructor accepts all of the same overloaded argument styles as
656      * initialize.
657      */
658     template<class... T>
CommunicatorHolder(T &&...args)659     explicit CommunicatorHolder(T&&... args) :
660         _communicator(std::move(initialize(std::forward<T>(args)...)))
661     {
662     }
663 
664     /**
665      * Adopts the given communicator.
666      * @param communicator The new communicator instance to hold.
667      */
668     CommunicatorHolder(std::shared_ptr<Communicator> communicator);
669 
670     /**
671      * Adopts the given communicator. If this holder currently holds a communicator,
672      * it will be destroyed.
673      * @param communicator The new communicator instance to hold.
674      */
675     CommunicatorHolder& operator=(std::shared_ptr<Communicator> communicator);
676 
677     CommunicatorHolder(const CommunicatorHolder&) = delete;
678     CommunicatorHolder(CommunicatorHolder&&) = default;
679 
680     /**
681      * Adopts the communicator in the given holder. If this holder currently holds a communicator,
682      * it will be destroyed.
683      * @param holder The holder from which to adopt a communicator.
684      */
685     CommunicatorHolder& operator=(CommunicatorHolder&& holder);
686 
687     /**
688      * Determines whether the holder contains an instance.
689      * @return True if the holder currently holds an instance, false otherwise.
690      */
691     explicit operator bool() const;
692 
693 #else // C++98 mapping
694 
695     /**
696      * Initializes a new communicator.
697      * @param argc The number of arguments in argv. Upon return, this argument
698      * is updated to reflect the arguments still remaining in argv.
699      * @param argv Command-line arguments, possibly containing
700      * options to set properties. If the arguments include
701      * a <code>--Ice.Config</code> option, the corresponding configuration
702      * files are parsed. If the same property is set in a configuration
703      * file and in the arguments, the arguments take precedence.
704      * Recognized options are removed from this vector upon return.
705      * @param initData Configuration data for the new Communicator.
706      * @param version Indicates the Ice version with which the application is compatible. If not
707      * specified, the version of the Ice installation is used.
708      */
709     CommunicatorHolder(int& argc, const char* argv[], const InitializationData& initData = InitializationData(),
710                        int version = ICE_INT_VERSION);
711 
712     /**
713      * Initializes a new communicator.
714      * @param argc The number of arguments in argv. Upon return, this argument
715      * is updated to reflect the arguments still remaining in argv.
716      * @param argv Command-line arguments, possibly containing
717      * options to set properties. If the arguments include
718      * a <code>--Ice.Config</code> option, the corresponding configuration
719      * files are parsed. If the same property is set in a configuration
720      * file and in the arguments, the arguments take precedence.
721      * Recognized options are removed from this vector upon return.
722      * @param initData Configuration data for the new Communicator.
723      * @param version Indicates the Ice version with which the application is compatible. If not
724      * specified, the version of the Ice installation is used.
725      */
726     CommunicatorHolder(int& argc, char* argv[], const InitializationData& initData = InitializationData(),
727                        int version = ICE_INT_VERSION);
728 
729     /**
730      * Initializes a new communicator.
731      * @param argc The number of arguments in argv. Upon return, this argument
732      * is updated to reflect the arguments still remaining in argv.
733      * @param argv Command-line arguments, possibly containing
734      * options to set properties. If the arguments include
735      * a <code>--Ice.Config</code> option, the corresponding configuration
736      * files are parsed. If the same property is set in a configuration
737      * file and in the arguments, the arguments take precedence.
738      * Recognized options are removed from this vector upon return.
739      * @param configFile The name of an Ice configuration file.
740      * @param version Indicates the Ice version with which the application is compatible. If not
741      * specified, the version of the Ice installation is used.
742      */
743     CommunicatorHolder(int& argc, const char* argv[], const char* configFile, int version = ICE_INT_VERSION);
744 
745     /**
746      * Initializes a new communicator.
747      * @param argc The number of arguments in argv. Upon return, this argument
748      * is updated to reflect the arguments still remaining in argv.
749      * @param argv Command-line arguments, possibly containing
750      * options to set properties. If the arguments include
751      * a <code>--Ice.Config</code> option, the corresponding configuration
752      * files are parsed. If the same property is set in a configuration
753      * file and in the arguments, the arguments take precedence.
754      * Recognized options are removed from this vector upon return.
755      * @param configFile The name of an Ice configuration file.
756      * @param version Indicates the Ice version with which the application is compatible. If not
757      * specified, the version of the Ice installation is used.
758      */
759     CommunicatorHolder(int& argc, char* argv[], const char* configFile, int version = ICE_INT_VERSION);
760 
761 #   ifdef _WIN32
762     /**
763      * Initializes a new communicator.
764      * @param argc The number of arguments in argv. Upon return, this argument
765      * is updated to reflect the arguments still remaining in argv.
766      * @param argv Command-line arguments, possibly containing
767      * options to set properties. If the arguments include
768      * a <code>--Ice.Config</code> option, the corresponding configuration
769      * files are parsed. If the same property is set in a configuration
770      * file and in the arguments, the arguments take precedence.
771      * Recognized options are removed from this vector upon return.
772      * @param initData Configuration data for the new Communicator.
773      * @param version Indicates the Ice version with which the application is compatible. If not
774      * specified, the version of the Ice installation is used.
775      */
776     CommunicatorHolder(int& argc, const wchar_t* argv[], const InitializationData& initData = InitializationData(),
777                        int version = ICE_INT_VERSION);
778 
779     /**
780      * Initializes a new communicator.
781      * @param argc The number of arguments in argv. Upon return, this argument
782      * is updated to reflect the arguments still remaining in argv.
783      * @param argv Command-line arguments, possibly containing
784      * options to set properties. If the arguments include
785      * a <code>--Ice.Config</code> option, the corresponding configuration
786      * files are parsed. If the same property is set in a configuration
787      * file and in the arguments, the arguments take precedence.
788      * Recognized options are removed from this vector upon return.
789      * @param initData Configuration data for the new Communicator.
790      * @param version Indicates the Ice version with which the application is compatible. If not
791      * specified, the version of the Ice installation is used.
792      */
793     CommunicatorHolder(int& argc, wchar_t* argv[], const InitializationData& initData = InitializationData(),
794                        int version = ICE_INT_VERSION);
795 
796     /**
797      * Initializes a new communicator.
798      * @param argc The number of arguments in argv. Upon return, this argument
799      * is updated to reflect the arguments still remaining in argv.
800      * @param argv Command-line arguments, possibly containing
801      * options to set properties. If the arguments include
802      * a <code>--Ice.Config</code> option, the corresponding configuration
803      * files are parsed. If the same property is set in a configuration
804      * file and in the arguments, the arguments take precedence.
805      * Recognized options are removed from this vector upon return.
806      * @param configFile The name of an Ice configuration file.
807      * @param version Indicates the Ice version with which the application is compatible. If not
808      * specified, the version of the Ice installation is used.
809      */
810     CommunicatorHolder(int& argc, const wchar_t* argv[], const char* configFile, int version = ICE_INT_VERSION);
811 
812     /**
813      * Initializes a new communicator.
814      * @param argc The number of arguments in argv. Upon return, this argument
815      * is updated to reflect the arguments still remaining in argv.
816      * @param argv Command-line arguments, possibly containing
817      * options to set properties. If the arguments include
818      * a <code>--Ice.Config</code> option, the corresponding configuration
819      * files are parsed. If the same property is set in a configuration
820      * file and in the arguments, the arguments take precedence.
821      * Recognized options are removed from this vector upon return.
822      * @param configFile The name of an Ice configuration file.
823      * @param version Indicates the Ice version with which the application is compatible. If not
824      * specified, the version of the Ice installation is used.
825      */
826     CommunicatorHolder(int& argc, wchar_t* argv[], const char* configFile, int version = ICE_INT_VERSION);
827 #   endif
828 
829     /**
830      * Initializes a new communicator.
831      * @param seq Command-line arguments, possibly containing
832      * options to set properties. If the arguments include
833      * a <code>--Ice.Config</code> option, the corresponding configuration
834      * files are parsed. If the same property is set in a configuration
835      * file and in the arguments, the arguments take precedence.
836      * Recognized options are removed from this container upon return.
837      * @param initData Configuration data for the new Communicator.
838      * @param version Indicates the Ice version with which the application is compatible. If not
839      * specified, the version of the Ice installation is used.
840      */
841     explicit CommunicatorHolder(StringSeq& seq, const InitializationData& initData = InitializationData(),
842                                 int version = ICE_INT_VERSION);
843 
844     /**
845      * Initializes a new communicator.
846      * @param seq Command-line arguments, possibly containing
847      * options to set properties. If the arguments include
848      * a <code>--Ice.Config</code> option, the corresponding configuration
849      * files are parsed. If the same property is set in a configuration
850      * file and in the arguments, the arguments take precedence.
851      * Recognized options are removed from this container upon return.
852      * @param configFile The name of an Ice configuration file.
853      * @param version Indicates the Ice version with which the application is compatible. If not
854      * specified, the version of the Ice installation is used.
855      */
856     CommunicatorHolder(StringSeq& seq, const char* configFile, int version = ICE_INT_VERSION);
857 
858     /**
859      * Initializes a new communicator.
860      * @param initData Configuration data for the new Communicator.
861      * @param version Indicates the Ice version with which the application is compatible. If not
862      * specified, the version of the Ice installation is used.
863      */
864     explicit CommunicatorHolder(const InitializationData& initData, int version = ICE_INT_VERSION);
865 
866     /**
867      * Initializes a new communicator.
868      * @param configFile The name of an Ice configuration file.
869      * @param version Indicates the Ice version with which the application is compatible. If not
870      * specified, the version of the Ice installation is used.
871      */
872     explicit CommunicatorHolder(const char* configFile, int version = ICE_INT_VERSION);
873 
874     /**
875      * Adopts the given communicator.
876      * @param communicator The new communicator instance to hold.
877      */
878     CommunicatorHolder(const CommunicatorPtr& communicator);
879 
880     /**
881      * Adopts the given communicator. If this holder currently holds a communicator,
882      * it will be destroyed.
883      * @param communicator The new communicator instance to hold.
884      */
885     CommunicatorHolder& operator=(const CommunicatorPtr& communicator);
886 
887     /**
888      * Determines whether the holder contains an instance.
889      * @return True if the holder currently holds an instance, false otherwise.
890      */
891     operator bool() const;
892 
893     /// \cond INTERNAL
894     //
895     // Required for successful copy-initialization, but not
896     // defined as it should always be elided by the compiler.
897     CommunicatorHolder(const CommunicatorHolder&);
898     /// \endcond
899 
900 #endif
901 
902     ~CommunicatorHolder();
903 
904     /**
905      * Obtains the communicator instance.
906      * @return The communicator held by this holder, or nil if the holder is empty.
907      */
908     const CommunicatorPtr& communicator() const;
909 
910     /**
911      * Obtains the communicator instance.
912      * @return The communicator held by this holder, or nil if the holder is empty.
913      */
914     const CommunicatorPtr& operator->() const;
915 
916     /**
917      * Obtains the communicator instance and clears the reference held by the holder.
918      * @return The communicator held by this holder, or nil if the holder is empty.
919      */
920     CommunicatorPtr release();
921 
922 private:
923 
924     CommunicatorPtr  _communicator;
925 };
926 
927 /**
928  * Converts a stringified identity into an Identity.
929  * @param str The stringified identity.
930  * @return An Identity structure containing the name and category components.
931  */
932 ICE_API Identity stringToIdentity(const std::string& str);
933 
934 /**
935  * Converts an Identity structure into a string using the specified mode.
936  * @param id The identity structure.
937  * @param mode Affects the handling of non-ASCII characters and non-printable ASCII characters.
938  * @return The stringified identity.
939  */
940 ICE_API std::string identityToString(const Identity& id, ToStringMode mode = ICE_ENUM(ToStringMode, Unicode));
941 
942 }
943 
944 namespace IceInternal
945 {
946 
947 //
948 // Some Ice extensions need access to the Ice internal instance. Do
949 // not use this operation for regular application code! It is intended
950 // to be used by modules such as Freeze.
951 //
952 ICE_API InstancePtr getInstance(const ::Ice::CommunicatorPtr&);
953 ICE_API IceUtil::TimerPtr getInstanceTimer(const ::Ice::CommunicatorPtr&);
954 
955 }
956 
957 #endif
958