summaryrefslogtreecommitdiff
path: root/cpp/include/Ice/Initialize.h
blob: f595b126194c6d9079f49b11560a49500a375915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
// **********************************************************************
//
// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_INITIALIZE_H
#define ICE_INITIALIZE_H

#include <IceUtil/Timer.h>
#include <Ice/Communicator.h>
#include <Ice/PropertiesF.h>
#include <Ice/InstanceF.h>
#include <Ice/LoggerF.h>
#include <Ice/InstrumentationF.h>
#include <Ice/Dispatcher.h>
#include <Ice/FactoryTable.h>
#include <Ice/BuiltinSequences.h>
#include <Ice/Version.h>
#include <Ice/Plugin.h>
#include <Ice/BatchRequestInterceptor.h>

#ifdef ICE_CPP11_MAPPING
#   define ICE_CONFIG_FILE_STRING const std::string&
#else
#   define ICE_CONFIG_FILE_STRING const char*
#endif

namespace Ice
{

/**
 * Converts an argument vector into a string sequence.
 * @param argc The number of arguments in argv.
 * @param argv The arguments.
 * @return A string sequence containing the arguments.
 */
ICE_API StringSeq argsToStringSeq(int argc, const char* const argv[]);

#ifdef _WIN32
/**
 * Converts an argument vector into a string sequence.
 * @param argc The number of arguments in argv.
 * @param argv The arguments.
 * @return A string sequence containing the arguments.
 */
ICE_API StringSeq argsToStringSeq(int argc, const wchar_t* const argv[]);
#endif

/**
 * Updates the argument vector to match the contents of the string sequence.
 * This function assumes that the string sequence only contains
 * elements of the argument vector. The function shifts the
 * the argument vector elements so that the vector matches the
 * contents of the sequence.
 * @param seq The string sequence returned from a call to argsToStringSeq.
 * @param argc Updated to reflect the size of the sequence.
 * @param argv Elements are shifted to match the sequence.
 */
ICE_API void stringSeqToArgs(const StringSeq& seq, int& argc, const char* argv[]);

/**
 * Updates the argument vector to match the contents of the string sequence.
 * This function assumes that the string sequence only contains
 * elements of the argument vector. The function shifts the
 * the argument vector elements so that the vector matches the
 * contents of the sequence.
 * @param seq The string sequence returned from a call to argsToStringSeq.
 * @param argc Updated to reflect the size of the sequence.
 * @param argv Elements are shifted to match the sequence.
 */
inline void stringSeqToArgs(const StringSeq& seq, int& argc, char* argv[])
{
    return stringSeqToArgs(seq, argc, const_cast<const char**>(argv));
}

#ifdef _WIN32
/**
 * Updates the argument vector to match the contents of the string sequence.
 * This function assumes that the string sequence only contains
 * elements of the argument vector. The function shifts the
 * the argument vector elements so that the vector matches the
 * contents of the sequence.
 * @param seq The string sequence returned from a call to argsToStringSeq.
 */
ICE_API void stringSeqToArgs(const StringSeq& seq, int& argc, const wchar_t* argv[]);

/**
 * Updates the argument vector to match the contents of the string sequence.
 * This function assumes that the string sequence only contains
 * elements of the argument vector. The function shifts the
 * the argument vector elements so that the vector matches the
 * contents of the sequence.
 * @param seq The string sequence returned from a call to argsToStringSeq.
 */
inline void stringSeqToArgs(const StringSeq& seq, int& argc, wchar_t* argv[])
{
    return stringSeqToArgs(seq, argc, const_cast<const wchar_t**>(argv));
}
#endif

/**
 * Creates a new empty property set.
 *
 * @return A new empty property set.
 */
ICE_API PropertiesPtr createProperties();

/**
 * Creates a property set initialized from command-line arguments
 * and a default property set.
 *
 * @param seq Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this container upon return.
 *
 * @param defaults Default values for the property set. Settings in
 * configuration files and the arguments override these defaults.
 *
 * @return A new property set initialized with the property settings
 * that were removed from the argument vector.
 */
ICE_API PropertiesPtr createProperties(StringSeq& seq, const PropertiesPtr& defaults = 0);

/**
 * Creates a property set initialized from command-line arguments
 * and a default property set.
 *
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 *
 * @param defaults Default values for the property set. Settings in
 * configuration files and the arguments override these defaults.
 *
 * @return A new property set initialized with the property settings
 * that were removed from the argument vector.
 */
ICE_API PropertiesPtr createProperties(int& argc, const char* argv[], const PropertiesPtr& defaults = 0);

/**
 * Creates a property set initialized from command-line arguments
 * and a default property set.
 *
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 *
 * @param defaults Default values for the property set. Settings in
 * configuration files and the arguments override these defaults.
 *
 * @return A new property set initialized with the property settings
 * that were removed from the argument vector.
 */
inline PropertiesPtr createProperties(int& argc, char* argv[], const PropertiesPtr& defaults = 0)
{
    return createProperties(argc, const_cast<const char**>(argv), defaults);
}

#ifdef _WIN32
/**
 * Creates a property set initialized from command-line arguments
 * and a default property set.
 *
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 *
 * @param defaults Default values for the property set. Settings in
 * configuration files and the arguments override these defaults.
 *
 * @return A new property set initialized with the property settings
 * that were removed from the argument vector.
 */
ICE_API PropertiesPtr createProperties(int& argc, const wchar_t* argv[], const PropertiesPtr& defaults = 0);

/**
 * Creates a property set initialized from command-line arguments
 * and a default property set.
 *
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 *
 * @param defaults Default values for the property set. Settings in
 * configuration files and the arguments override these defaults.
 *
 * @return A new property set initialized with the property settings
 * that were removed from the argument vector.
 */
inline PropertiesPtr createProperties(int& argc, wchar_t* argv[], const PropertiesPtr& defaults = 0)
{
    return createProperties(argc, const_cast<const wchar_t**>(argv), defaults);
}
#endif

/**
 * Base class for a thread notification hook. An application can subclass this class,
 * implement start and stop, and install an instance in InitializationData in order
 * to receive notifications when Ice threads are started and stopped.
 * \headerfile Ice/Ice.h
 */
class ICE_API ThreadNotification : public IceUtil::Shared
{
public:

    /**
     * Called from the new Ice thread at startup.
     */
    virtual void start() = 0;

    /**
     * Called from an Ice thread that is about to stop.
     */
    virtual void stop() = 0;
};

typedef IceUtil::Handle<ThreadNotification> ThreadNotificationPtr;

/**
 * A special plug-in that installs a thread hook during a communicator's initialization.
 * Both initialize and destroy are no-op. See InitializationData.
 * \headerfile Ice/Ice.h
 */
class ICE_API ThreadHookPlugin : public Ice::Plugin
{
public:

#ifdef ICE_CPP11_MAPPING
    /**
     * Installs the thread hooks.
     * @param communicator The communicator in which to install the thread hooks.
     * @param start The start callback.
     * @param stop The stop callback.
     */
    ThreadHookPlugin(const CommunicatorPtr& communicator, std::function<void()> start, std::function<void()> stop);
#else
    /**
     * Installs the thread hooks.
     * @param communicator The communicator in which to install the thread hooks.
     * @param hook The thread notification callback object.
     */
    ThreadHookPlugin(const CommunicatorPtr& communicator, const ThreadNotificationPtr& hook);
#endif

    /** Not used. */
    virtual void initialize();

    /** Not used. */
    virtual void destroy();
};

/**
 * Encapsulates data to initialize a communicator.
 * \headerfile Ice/Ice.h
 */
struct InitializationData
{
    /**
     * The properties for the communicator.
     */
    PropertiesPtr properties;

    /**
     * The logger for the communicator.
     */
    LoggerPtr logger;

    /**
     * The communicator observer used by the Ice run-time.
     */
    Instrumentation::CommunicatorObserverPtr observer;

#ifdef ICE_CPP11_MAPPING
    /**
     * Called whenever the communicator starts a new thread.
     */
    std::function<void()> threadStart;

    /**
     * Called whenever a thread created by the communicator is about to be destroyed.
     */
    std::function<void()> threadStop;

    /**
      * You can control which thread receives operation invocations and AMI
      * callbacks by supplying a dispatcher.
      *
      * For example, you can use this dispatching facility to ensure that
      * all invocations and callbacks are dispatched in a GUI event loop
      * thread so that it is safe to invoke directly on GUI objects.
      *
      * The dispatcher is responsible for running (dispatching) the
      * invocation or AMI callback on its favorite thread.
      * @param call Represents the invocation. The dispatcher must eventually invoke this function.
      * @param con The connection associated with this dispatch, or nil if no connection is
      * associated with it.
      */
    std::function<void(std::function<void()> call, const std::shared_ptr<Ice::Connection>& con)> dispatcher;

    /**
     * Applications that make use of compact type IDs to conserve space
     * when marshaling class instances, and also use the streaming API to
     * extract such classes, can intercept the translation between compact
     * type IDs and their corresponding string type IDs by installing a
     * compact ID resolver.
     * @param id The compact ID.
     * @return The fully-scoped type ID such as "::Module::Class", or an empty string if
     * the compact ID is unknown.
     */
    std::function<std::string(int id)> compactIdResolver;

    /**
     * The batch request interceptor, which is called by the Ice run time to enqueue a batch request.
     * @param req An object representing the batch request.
     * @param count The number of requests currently in the queue.
     * @param size The number of bytes consumed by the requests currently in the queue.
     */
    std::function<void(const Ice::BatchRequest& req, int count, int size)> batchRequestInterceptor;
#else
    /**
     * The thread hook for the communicator.
     */
    ThreadNotificationPtr threadHook;

    /**
      * You can control which thread receives operation invocations and AMI
      * callbacks by supplying a dispatcher.
      *
      * For example, you can use this dispatching facility to ensure that
      * all invocations and callbacks are dispatched in a GUI event loop
      * thread so that it is safe to invoke directly on GUI objects.
      *
      * The dispatcher is responsible for running (dispatching) the
      * invocation or AMI callback on its favorite thread. It must eventually
      * execute the provided call.
      */
    DispatcherPtr dispatcher;

    /**
     * Applications that make use of compact type IDs to conserve space
     * when marshaling class instances, and also use the streaming API to
     * extract such classes, can intercept the translation between compact
     * type IDs and their corresponding string type IDs by installing a
     * compact ID resolver.
     */
    CompactIdResolverPtr compactIdResolver;

    /**
     * The batch request interceptor.
     */
    BatchRequestInterceptorPtr batchRequestInterceptor;
#endif

    /**
     * The value factory manager.
     */
    ValueFactoryManagerPtr valueFactoryManager;
};

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param initData Configuration data for the new Communicator.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(int& argc, const char* argv[],
                                   const InitializationData& initData = InitializationData(),
                                   int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param initData Configuration data for the new Communicator.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
inline CommunicatorPtr initialize(int& argc, char* argv[], const InitializationData& initData = InitializationData(),
                                   int version = ICE_INT_VERSION)
{
    return initialize(argc, const_cast<const char**>(argv), initData, version);
}

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param configFile The name of an Ice configuration file.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(int& argc, const char* argv[], ICE_CONFIG_FILE_STRING configFile,
                                   int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param configFile The name of an Ice configuration file.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
inline CommunicatorPtr initialize(int& argc, char* argv[], ICE_CONFIG_FILE_STRING configFile,
                                  int version = ICE_INT_VERSION)
{
    return initialize(argc, const_cast<const char**>(argv), configFile, version);
}

#ifdef _WIN32
/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param initData Configuration data for the new Communicator.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[],
                                   const InitializationData& initData = InitializationData(),
                                   int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param initData Configuration data for the new Communicator.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], const InitializationData& initData = InitializationData(),
                                   int version = ICE_INT_VERSION)
{
    return initialize(argc, const_cast<const wchar_t**>(argv), initData, version);
}

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param configFile The name of an Ice configuration file.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[], ICE_CONFIG_FILE_STRING configFile,
                                   int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param argc The number of arguments in argv. Upon return, this argument
 * is updated to reflect the arguments still remaining in argv.
 * @param argv Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this vector upon return.
 * @param configFile The name of an Ice configuration file.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], ICE_CONFIG_FILE_STRING configFile,
                                  int version = ICE_INT_VERSION)
{
    return initialize(argc, const_cast<const wchar_t**>(argv), configFile, version);
}
#endif

/**
 * Initializes a new communicator.
 * @param seq Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this container upon return.
 * @param initData Configuration data for the new Communicator.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(StringSeq& seq, const InitializationData& initData = InitializationData(),
                                   int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param seq Command-line arguments, possibly containing
 * options to set properties. If the arguments include
 * a <code>--Ice.Config</code> option, the corresponding configuration
 * files are parsed. If the same property is set in a configuration
 * file and in the arguments, the arguments take precedence.
 * Recognized options are removed from this container upon return.
 * @param configFile The name of an Ice configuration file.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(StringSeq& seq, ICE_CONFIG_FILE_STRING configFile, int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param initData Configuration data for the new Communicator.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(const InitializationData& initData = InitializationData(),
                                   int version = ICE_INT_VERSION);

/**
 * Initializes a new communicator.
 * @param configFile The name of an Ice configuration file.
 * @param version Indicates the Ice version with which the application is compatible. If not
 * specified, the version of the Ice installation is used.
 * @return The new communicator.
 */
ICE_API CommunicatorPtr initialize(ICE_CONFIG_FILE_STRING configFile, int version = ICE_INT_VERSION);

/**
 * Obtains the per-process logger. This logger is used by all communicators that do not have their
 * own specific logger established at the time a communicator is created.
 * @return The current per-process logger instance.
 */
ICE_API LoggerPtr getProcessLogger();

/**
 * Sets the per-process logger. This logger is used by all communicators that do not have their
 * own specific logger established at the time a communicator is created.
 * @param logger The new per-process logger instance.
 */
ICE_API void setProcessLogger(const LoggerPtr& logger);

/**
 * A plug-in factory function is responsible for creating an Ice plug-in.
 * @param communicator The communicator in which the plug-in will be installed.
 * @param name The name assigned to the plug-in.
 * @param args Additional arguments included in the plug-in's configuration.
 * @return The new plug-in object. Returning nil will cause the run time to raise PluginInitializationException.
 */
typedef Ice::Plugin* (*PluginFactory)(const ::Ice::CommunicatorPtr& communicator, const std::string& name,
                                      const ::Ice::StringSeq& args);

/**
 * Manually registers a plug-in factory function.
 * @param name The name assigned to the plug-in.
 * @param factory The factory function.
 * @param loadOnInit If true, the plug-in is always loaded (created) during communicator initialization,
 * even if Ice.Plugin.name is not set. When false, the plug-in is loaded (created) during communication
 * initialization only if Ice.Plugin.name  is set to a non-empty value (e.g.: Ice.Plugin.IceSSL=1).
 */
ICE_API void registerPluginFactory(const std::string& name, PluginFactory factory, bool loadOnInit);

/**
 * A helper class that uses Resource Acquisition Is Initialization (RAII) to initialize and hold a
 * communicator instance, and automatically destroy the communicator when the holder goes out of scope.
 * \headerfile Ice/Ice.h
 */
class ICE_API CommunicatorHolder
{
public:

    /**
     * The holder's initial state is empty.
     */
    CommunicatorHolder();

#ifdef ICE_CPP11_MAPPING

    /**
     * Calls initialize to create a communicator with the provided arguments.
     * This constructor accepts all of the same overloaded argument styles as
     * initialize.
     */
    template<class... T>
    explicit CommunicatorHolder(T&&... args) :
        _communicator(std::move(initialize(std::forward<T>(args)...)))
    {
    }

    /**
     * Adopts the given communicator.
     * @param communicator The new communicator instance to hold.
     */
    CommunicatorHolder(std::shared_ptr<Communicator> communicator);

    /**
     * Adopts the given communicator. If this holder currently holds a communicator,
     * it will be destroyed.
     * @param communicator The new communicator instance to hold.
     */
    CommunicatorHolder& operator=(std::shared_ptr<Communicator> communicator);

    CommunicatorHolder(const CommunicatorHolder&) = delete;
    CommunicatorHolder(CommunicatorHolder&&) = default;

    /**
     * Adopts the communicator in the given holder. If this holder currently holds a communicator,
     * it will be destroyed.
     * @param holder The holder from which to adopt a communicator.
     */
    CommunicatorHolder& operator=(CommunicatorHolder&& holder);

    /**
     * Determines whether the holder contains an instance.
     * @return True if the holder currently holds an instance, false otherwise.
     */
    explicit operator bool() const;

#else // C++98 mapping

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param initData Configuration data for the new Communicator.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, const char* argv[], const InitializationData& initData = InitializationData(),
                       int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param initData Configuration data for the new Communicator.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, char* argv[], const InitializationData& initData = InitializationData(),
                       int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param configFile The name of an Ice configuration file.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, const char* argv[], const char* configFile, int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param configFile The name of an Ice configuration file.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, char* argv[], const char* configFile, int version = ICE_INT_VERSION);

#   ifdef _WIN32
    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param initData Configuration data for the new Communicator.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, const wchar_t* argv[], const InitializationData& initData = InitializationData(),
                       int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param initData Configuration data for the new Communicator.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, wchar_t* argv[], const InitializationData& initData = InitializationData(),
                       int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param configFile The name of an Ice configuration file.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, const wchar_t* argv[], const char* configFile, int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param argc The number of arguments in argv. Upon return, this argument
     * is updated to reflect the arguments still remaining in argv.
     * @param argv Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this vector upon return.
     * @param configFile The name of an Ice configuration file.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(int& argc, wchar_t* argv[], const char* configFile, int version = ICE_INT_VERSION);
#   endif

    /**
     * Initializes a new communicator.
     * @param seq Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this container upon return.
     * @param initData Configuration data for the new Communicator.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    explicit CommunicatorHolder(StringSeq& seq, const InitializationData& initData = InitializationData(),
                                int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param seq Command-line arguments, possibly containing
     * options to set properties. If the arguments include
     * a <code>--Ice.Config</code> option, the corresponding configuration
     * files are parsed. If the same property is set in a configuration
     * file and in the arguments, the arguments take precedence.
     * Recognized options are removed from this container upon return.
     * @param configFile The name of an Ice configuration file.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    CommunicatorHolder(StringSeq& seq, const char* configFile, int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param initData Configuration data for the new Communicator.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    explicit CommunicatorHolder(const InitializationData& initData, int version = ICE_INT_VERSION);

    /**
     * Initializes a new communicator.
     * @param configFile The name of an Ice configuration file.
     * @param version Indicates the Ice version with which the application is compatible. If not
     * specified, the version of the Ice installation is used.
     */
    explicit CommunicatorHolder(const char* configFile, int version = ICE_INT_VERSION);

    /**
     * Adopts the given communicator.
     * @param communicator The new communicator instance to hold.
     */
    CommunicatorHolder(const CommunicatorPtr& communicator);

    /**
     * Adopts the given communicator. If this holder currently holds a communicator,
     * it will be destroyed.
     * @param communicator The new communicator instance to hold.
     */
    CommunicatorHolder& operator=(const CommunicatorPtr& communicator);

    /**
     * Determines whether the holder contains an instance.
     * @return True if the holder currently holds an instance, false otherwise.
     */
    operator bool() const;

    /// \cond INTERNAL
    //
    // Required for successful copy-initialization, but not
    // defined as it should always be elided by the compiler.
    CommunicatorHolder(const CommunicatorHolder&);
    /// \endcond

#endif

    ~CommunicatorHolder();

    /**
     * Obtains the communicator instance.
     * @return The communicator held by this holder, or nil if the holder is empty.
     */
    const CommunicatorPtr& communicator() const;

    /**
     * Obtains the communicator instance.
     * @return The communicator held by this holder, or nil if the holder is empty.
     */
    const CommunicatorPtr& operator->() const;

    /**
     * Obtains the communicator instance and clears the reference held by the holder.
     * @return The communicator held by this holder, or nil if the holder is empty.
     */
    CommunicatorPtr release();

private:

    CommunicatorPtr  _communicator;
};

/**
 * Converts a stringified identity into an Identity.
 * @param str The stringified identity.
 * @return An Identity structure containing the name and category components.
 */
ICE_API Identity stringToIdentity(const std::string& str);

/**
 * Converts an Identity structure into a string using the specified mode.
 * @param id The identity structure.
 * @param mode Affects the handling of non-ASCII characters and non-printable ASCII characters.
 * @return The stringified identity.
 */
ICE_API std::string identityToString(const Identity& id, ToStringMode mode = ICE_ENUM(ToStringMode, Unicode));

}

namespace IceInternal
{

//
// Some Ice extensions need access to the Ice internal instance. Do
// not use this operation for regular application code! It is intended
// to be used by modules such as Freeze.
//
ICE_API InstancePtr getInstance(const ::Ice::CommunicatorPtr&);
ICE_API IceUtil::TimerPtr getInstanceTimer(const ::Ice::CommunicatorPtr&);

}

#endif