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