]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/DLLX/TXTRecord.h
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / DLLX / TXTRecord.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2009 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: TXTRecord.h,v $
20 Revision 1.1 2009/05/26 04:43:54 herscher
21 <rdar://problem/3948252> COM component that can be used with any .NET language and VB.
22
23
24 */
25
26 #pragma once
27 #include "resource.h" // main symbols
28 #include "DLLX.h"
29 #include <vector>
30 #include <dns_sd.h>
31
32
33 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
34 #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
35 #endif
36
37
38
39 // CTXTRecord
40
41 class ATL_NO_VTABLE CTXTRecord :
42 public CComObjectRootEx<CComSingleThreadModel>,
43 public CComCoClass<CTXTRecord, &CLSID_TXTRecord>,
44 public IDispatchImpl<ITXTRecord, &IID_ITXTRecord, &LIBID_Bonjour, /*wMajor =*/ 1, /*wMinor =*/ 0>
45 {
46 public:
47 CTXTRecord()
48 :
49 m_allocated( FALSE )
50 {
51 }
52
53 DECLARE_REGISTRY_RESOURCEID(IDR_TXTRECORD)
54
55
56 BEGIN_COM_MAP(CTXTRecord)
57 COM_INTERFACE_ENTRY(ITXTRecord)
58 COM_INTERFACE_ENTRY(IDispatch)
59 END_COM_MAP()
60
61
62
63 DECLARE_PROTECT_FINAL_CONSTRUCT()
64
65 HRESULT FinalConstruct()
66 {
67 return S_OK;
68 }
69
70 void FinalRelease()
71 {
72 if ( m_allocated )
73 {
74 TXTRecordDeallocate( &m_tref );
75 }
76 }
77
78 public:
79
80 STDMETHOD(SetValue)(BSTR key, VARIANT value);
81 STDMETHOD(RemoveValue)(BSTR key);
82 STDMETHOD(ContainsKey)(BSTR key, VARIANT_BOOL* retval);
83 STDMETHOD(GetValueForKey)(BSTR key, VARIANT* value);
84 STDMETHOD(GetCount)(ULONG* count);
85 STDMETHOD(GetKeyAtIndex)(ULONG index, BSTR* retval);
86 STDMETHOD(GetValueAtIndex)(ULONG index, VARIANT* retval);
87
88 private:
89
90 typedef std::vector< BYTE > ByteArray;
91 ByteArray m_byteArray;
92 BOOL m_allocated;
93 TXTRecordRef m_tref;
94
95 public:
96
97 uint16_t
98 GetLen()
99 {
100 return TXTRecordGetLength( &m_tref );
101 }
102
103 const void*
104 GetBytes()
105 {
106 return TXTRecordGetBytesPtr( &m_tref );
107 }
108
109 void
110 SetBytes
111 (
112 const unsigned char * bytes,
113 uint16_t len
114 );
115 };
116
117 OBJECT_ENTRY_AUTO(__uuidof(TXTRecord), CTXTRecord)