1*2123d757SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2123d757SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2123d757SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2123d757SAndrew Rist  * distributed with this work for additional information
6*2123d757SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2123d757SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2123d757SAndrew Rist  * "License"); you may not use this file except in compliance
9*2123d757SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2123d757SAndrew Rist  *
11*2123d757SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2123d757SAndrew Rist  *
13*2123d757SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2123d757SAndrew Rist  * software distributed under the License is distributed on an
15*2123d757SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2123d757SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2123d757SAndrew Rist  * specific language governing permissions and limitations
18*2123d757SAndrew Rist  * under the License.
19*2123d757SAndrew Rist  *
20*2123d757SAndrew Rist  *************************************************************/
21*2123d757SAndrew Rist 
22*2123d757SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #if ! defined INCLUDED_CLI_ENVIRONMENT_H
25cdf0e10cSrcweir #define INCLUDED_CLI_ENVIRONMENT_H
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "cli_base.h"
28cdf0e10cSrcweir #using <mscorlib.dll>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace System;
31cdf0e10cSrcweir using namespace System::Collections;
32cdf0e10cSrcweir using namespace System::Runtime::Serialization;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace cli_uno
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir public __gc class Cli_environment
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     static System::String* sOidPart;
40cdf0e10cSrcweir     static  Hashtable* m_objects;
41cdf0e10cSrcweir     static System::Runtime::Serialization::ObjectIDGenerator* m_IDGen;
42cdf0e10cSrcweir     inline static System::String* createKey(System::String* oid, System::Type* t);
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 1
45cdf0e10cSrcweir     int _numRegisteredObjects;
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir 
48cdf0e10cSrcweir public:
49cdf0e10cSrcweir 
Cli_environment()50cdf0e10cSrcweir     static Cli_environment()
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir         m_objects = Hashtable::Synchronized(new Hashtable());
53cdf0e10cSrcweir         m_IDGen = new System::Runtime::Serialization::ObjectIDGenerator();
54cdf0e10cSrcweir         System::Text::StringBuilder* buffer = new System::Text::StringBuilder(256);
55cdf0e10cSrcweir         Guid gd = Guid::NewGuid();
56cdf0e10cSrcweir         buffer->Append(S";cli[0];");
57cdf0e10cSrcweir 		buffer->Append(gd.ToString());
58cdf0e10cSrcweir         sOidPart = buffer->ToString();
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     inline Cli_environment();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     ~Cli_environment();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir        Registers an UNO object as being mapped by this bridge. The resulting
67cdf0e10cSrcweir        cli object is represents all interfaces of the UNO object. Therefore the
68cdf0e10cSrcweir        object can be registered only with its OID; a type is not necessary.
69cdf0e10cSrcweir     */
70cdf0e10cSrcweir     Object* registerInterface(Object* obj, System::String* oid);
71cdf0e10cSrcweir     /**
72cdf0e10cSrcweir        Registers a CLI object as being mapped by this bridge. The resulting
73cdf0e10cSrcweir        object represents exactly one UNO interface.
74cdf0e10cSrcweir      */
75cdf0e10cSrcweir     Object* registerInterface(Object* obj, System::String* oid, System::Type* type);
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /**
78cdf0e10cSrcweir        By revoking an interface it is declared that the respective interface has
79cdf0e10cSrcweir        not been mapped. The proxy implementations call revoke interface in their
80cdf0e10cSrcweir        destructors.
81cdf0e10cSrcweir      */
82cdf0e10cSrcweir     inline void revokeInterface(System::String* oid);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     void revokeInterface(System::String* oid, System::Type* type);
85cdf0e10cSrcweir     /**
86cdf0e10cSrcweir      * Retrieves an interface identified by its object id and type from this
87cdf0e10cSrcweir      * environment.
88cdf0e10cSrcweir      *
89cdf0e10cSrcweir      * @param oid object id of interface to be retrieved
90cdf0e10cSrcweir      * @param type the type description of the interface to be retrieved
91cdf0e10cSrcweir      * @see com.sun.star.uno.IEnvironment#getRegisteredInterface
92cdf0e10cSrcweir      */
93cdf0e10cSrcweir     Object* getRegisteredInterface(System::String* oid, System::Type* type);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	/**
96cdf0e10cSrcweir 	 * Generates a worldwide unique object identifier (oid) for the given object. It is
97cdf0e10cSrcweir      * guaranteed, that subsequent calls to the method with the same object
98cdf0e10cSrcweir      * will give the same id.
99cdf0e10cSrcweir 	 * <p>
100cdf0e10cSrcweir 	 * @return     the generated oid.
101cdf0e10cSrcweir 	 * @param      object     the object for which a Oid should be generated.
102cdf0e10cSrcweir 	 */
103cdf0e10cSrcweir     static System::String* getObjectIdentifier(Object* obj);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir };
106cdf0e10cSrcweir 
107cdf0e10cSrcweir } //namespace cli_uno
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir #endif
111