summaryrefslogtreecommitdiff
path: root/CIAO/DAnCE/DAnCE/DAnCE_Utility.h
blob: 93ad4e8fe375f94b476fbdc9a0ff639bb3608674 (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
// $Id$

/**
 * @file DAnCE_Utility.h
 * @author William R. Otte <wotte@dre.vanderbilt.edu>
 *
 * Utility methods used throughought DAnCE.

 */

#ifndef DAnCE_Utility_H
#define DAnCE_Utility_H

#include /**/ "ace/pre.h"

#include "DAnCE_stub_export.h"

#include "ace/config-all.h"
#include "ace/Hash_Map_Manager_T.h"
#include "ace/Refcounted_Auto_Ptr.h"
#include "tao/AnyTypeCode/Any.h"
#include "Deployment/Deployment_DeploymentPlanC.h"
#include "DAnCE/Logger/Log_Macros.h"

namespace DAnCE
{
  namespace Utility
  {
    typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
                                    CORBA::Any,
                                    ACE_Hash<ACE_CString>,
                                    ACE_Equal_To<ACE_CString>,
                                    ACE_Null_Mutex> PROPERTY_MAP;

    typedef ACE_Refcounted_Auto_Ptr <PROPERTY_MAP,
                                     TAO_SYNCH_MUTEX> PMAP_PTR;

    DANCE_STUB_Export void build_property_map (PROPERTY_MAP &map,
                                               const ::Deployment::Properties &prop);

    DANCE_STUB_Export void build_property_sequence (::Deployment::Properties &prop,
                                                    const PROPERTY_MAP &map);

    template<class T>
    bool
    get_property_value (const char *name,
                        const PROPERTY_MAP &properties,
                        T &val);

    template<class T>
    bool
    get_property_value (const char *name,
                        const ::Deployment::Properties &properties,
                        T &val);

    template<class T>
    void
    update_property_value (const char *name,
                           ::Deployment::Properties &properties,
                           const T &val);

    template <typename EXCEPTION>
    void test_and_set_exception (bool &flag, EXCEPTION &exception,
                                 const char *name, const char *reason);


    DANCE_STUB_Export const char *
    get_instance_type (const ::Deployment::Properties& prop);

    DANCE_STUB_Export void append_properties (::Deployment::Properties &dest,
                            const ::Deployment::Properties &src);

    /// Write a string (usually a stringified IOR) to a file
    /// designated by the @c pathname.  The file named will always get
    /// overwritten.
    DANCE_STUB_Export int write_IOR (const ACE_TCHAR *pathname,
                                     const char *IOR);
    
    /// Attempt to extract the any into EXCEPTION type and
    /// throw.  Returns 'false' if extraction fails.
    template <typename EXCEPTION>
    bool extract_and_throw_exception (const CORBA::Any &excep);
  }
}

// Template specializations.
namespace DAnCE
{
  namespace Utility
  {
    template<>
    DANCE_STUB_Export bool
    get_property_value (const char *name,
                        const PROPERTY_MAP &properties, bool &val);

    template<>
    DANCE_STUB_Export bool
    get_property_value (const char *name,
                        const PROPERTY_MAP &properties, const char *&val);

    template<>
    DANCE_STUB_Export bool
    get_property_value (const char *name,
                        const ::Deployment::Properties &properties,
                        const char * &val);

    template<char*>
    DANCE_STUB_Export void
    update_property_value (const char *name,
                           ::Deployment::Properties &properties,
                           const char * &val);
  }
}


#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "DAnCE_Utility.tpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("DAnCE_Utility.tpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */


#include /**/ "ace/post.h"
#endif