summaryrefslogtreecommitdiff
path: root/DAnCE/dance/DAnCE_Utility.h
blob: e4d34ee2e18bda69a409bdd438de51938a006784 (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
// $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/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 "dance/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>
    bool
    get_satisfierproperty_value (const char *name,
                         const ::Deployment::SatisfierProperties &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 @a 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);

    DANCE_STUB_Export bool
    throw_exception_from_any (const CORBA::Any &excep);

    template <typename EXCEPTION>
    CORBA::Any* create_any_from_exception (const EXCEPTION& ex);

    DANCE_STUB_Export CORBA::Any*
    create_any_from_user_exception (const CORBA::UserException& ex);

    template <typename EXCEPTION>
    bool stringify_exception (const CORBA::Any &excep,
                              std::string &result);

    DANCE_STUB_Export bool
    stringify_exception_from_any (const CORBA::Any &excep, std::string &result);
  }
}

// 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<>
    DANCE_STUB_Export bool
    get_satisfierproperty_value (const char *name,
                        const ::Deployment::SatisfierProperties &properties,
                        const char * &val);

    template<>
    DANCE_STUB_Export bool
    get_property_value (const char *name,
                        const ::Deployment::Properties &properties,
                        bool &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/DAnCE_Utility.tpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

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


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