OLD | NEW |
| (Empty) |
1 // Copyright 2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #ifndef OMAHA_PLUGINS_UPDATE_NPAPI_TESTING_DISPATCH_HOST_TEST_INTERFACE_H_ | |
17 #define OMAHA_PLUGINS_UPDATE_NPAPI_TESTING_DISPATCH_HOST_TEST_INTERFACE_H_ | |
18 | |
19 #include <atlbase.h> | |
20 #include <atlcom.h> | |
21 #include <atlstr.h> | |
22 | |
23 #include "base/basictypes.h" | |
24 #include "omaha/base/app_util.h" | |
25 #include "omaha/plugins/update/npapi/testing/resource.h" | |
26 #include "plugins/update/npapi/testing/dispatch_host_test_idl.h" | |
27 | |
28 namespace omaha { | |
29 | |
30 // This class allows for using IDispatchImpl with a specific TypeLib, in a | |
31 // module that has multiple TYPELIB resources. Ordinarily, IDispatchImpl will | |
32 // only load the first TYPELIB resource in the module, which does not work for | |
33 // omaha_unittest.exe. Hence the need for this class. This class loads the TLB | |
34 // with the specified resource id, and uses that for subsequent IDispatch | |
35 // requests. | |
36 // TODO(omaha3): Perhaps move this class into a generic utility header. | |
37 | |
38 template <class T, const IID* piid = &__uuidof(T), const int tlb_res_id = 1> | |
39 class ATL_NO_VTABLE IDispatchImplResId : public IDispatchImpl<T, piid> { | |
40 public: | |
41 IDispatchImplResId() { | |
42 CComPtr<ITypeLib> type_lib; | |
43 CString tlb_path; | |
44 | |
45 // Format the path as "ModulePath\\ResourceId". Specifying a ResourceId | |
46 // allows overriding the default behavior of LoadTypeLib to load the first | |
47 // TYPELIB resource from the module. | |
48 tlb_path.Format(_T("%s\\%d"), app_util::GetCurrentModuleName(), tlb_res_id); | |
49 | |
50 HRESULT hr = LoadTypeLib(tlb_path, &type_lib); | |
51 if (FAILED(hr)) { | |
52 return; | |
53 } | |
54 | |
55 CComPtr<ITypeInfo> type_info; | |
56 hr = type_lib->GetTypeInfoOfGuid(*piid, &type_info); | |
57 if (FAILED(hr)) { | |
58 return; | |
59 } | |
60 | |
61 CComPtr<ITypeInfo2> type_info2; | |
62 if (SUCCEEDED(type_info->QueryInterface(&type_info2))) { | |
63 type_info = type_info2; | |
64 } | |
65 | |
66 // Override the ITypeInfo in the CComTypeInfoHolder, which will be used in | |
67 // subsequent calls to the IDispatch methods. | |
68 _tih.m_pInfo = type_info.Detach(); | |
69 } | |
70 | |
71 virtual ~IDispatchImplResId() {} | |
72 }; | |
73 | |
74 class ATL_NO_VTABLE DispatchHostTestInterface | |
75 : public CComObjectRootEx<CComObjectThreadModel>, | |
76 public IDispatchImplResId<IDispatchHostTestInterface, | |
77 &__uuidof(IDispatchHostTestInterface), | |
78 IDR_DISPATCH_HOST_TEST_TLB> { | |
79 public: | |
80 DispatchHostTestInterface() {} | |
81 virtual ~DispatchHostTestInterface() {} | |
82 | |
83 DECLARE_NOT_AGGREGATABLE(DispatchHostTestInterface); | |
84 | |
85 BEGIN_COM_MAP(DispatchHostTestInterface) | |
86 COM_INTERFACE_ENTRY(IDispatch) | |
87 END_COM_MAP() | |
88 | |
89 // IDispatchHostTestInterface methods. | |
90 STDMETHOD(Random)(INT* x); | |
91 | |
92 STDMETHOD(get_Property)(INT* x); | |
93 STDMETHOD(put_Property)(INT x); | |
94 | |
95 STDMETHOD(get_ReadOnlyProperty)(INT* x); | |
96 STDMETHOD(put_WriteOnlyProperty)(INT x); | |
97 | |
98 STDMETHOD(AddAsMethod)(INT a, INT b, INT* c); | |
99 STDMETHOD(get_AddAsProperty)(INT a, INT b, INT* c); | |
100 | |
101 STDMETHOD(DidYouMeanRecursion)(IDispatch** me); | |
102 | |
103 private: | |
104 DISALLOW_COPY_AND_ASSIGN(DispatchHostTestInterface); | |
105 }; | |
106 | |
107 class ATL_NO_VTABLE DispatchHostTestInterface2 | |
108 : public CComObjectRootEx<CComObjectThreadModel>, | |
109 public IDispatchImplResId<IDispatchHostTestInterface2, | |
110 &__uuidof(IDispatchHostTestInterface2), | |
111 IDR_DISPATCH_HOST_TEST_TLB> { | |
112 public: | |
113 DispatchHostTestInterface2() {} | |
114 virtual ~DispatchHostTestInterface2() {} | |
115 | |
116 DECLARE_NOT_AGGREGATABLE(DispatchHostTestInterface2); | |
117 | |
118 BEGIN_COM_MAP(DispatchHostTestInterface) | |
119 COM_INTERFACE_ENTRY(IDispatch) | |
120 END_COM_MAP() | |
121 | |
122 // IDispatchHostTestInterface2 methods. | |
123 STDMETHOD(get_Get)(INT index, INT* x); | |
124 | |
125 private: | |
126 DISALLOW_COPY_AND_ASSIGN(DispatchHostTestInterface2); | |
127 }; | |
128 | |
129 } // namespace omaha | |
130 | |
131 #endif // OMAHA_PLUGINS_UPDATE_NPAPI_TESTING_DISPATCH_HOST_TEST_INTERFACE_H_ | |
OLD | NEW |