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 18 19 20#pragma once 21 22#include "resource.h" // main symbols 23 24#include "DLLX.h" 25 26#include <vector> 27 28#include <dns_sd.h> 29 30 31 32 33 34#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA) 35 36#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." 37 38#endif 39 40 41 42 43 44 45 46// CTXTRecord 47 48 49 50class ATL_NO_VTABLE CTXTRecord : 51 52 public CComObjectRootEx<CComSingleThreadModel>, 53 54 public CComCoClass<CTXTRecord, &CLSID_TXTRecord>, 55 56 public IDispatchImpl<ITXTRecord, &IID_ITXTRecord, &LIBID_Bonjour, /*wMajor =*/ 1, /*wMinor =*/ 0> 57 58{ 59 60public: 61 62 CTXTRecord() 63 64 : 65 66 m_allocated( FALSE ) 67 68 { 69 70 } 71 72 73 74DECLARE_REGISTRY_RESOURCEID(IDR_TXTRECORD) 75 76 77 78 79 80BEGIN_COM_MAP(CTXTRecord) 81 82 COM_INTERFACE_ENTRY(ITXTRecord) 83 84 COM_INTERFACE_ENTRY(IDispatch) 85 86END_COM_MAP() 87 88 89 90 91 92 93 94 DECLARE_PROTECT_FINAL_CONSTRUCT() 95 96 97 98 HRESULT FinalConstruct() 99 100 { 101 102 return S_OK; 103 104 } 105 106 107 108 void FinalRelease() 109 110 { 111 112 if ( m_allocated ) 113 114 { 115 116 TXTRecordDeallocate( &m_tref ); 117 118 } 119 120 } 121 122 123 124public: 125 126 127 128 STDMETHOD(SetValue)(BSTR key, VARIANT value); 129 130 STDMETHOD(RemoveValue)(BSTR key); 131 132 STDMETHOD(ContainsKey)(BSTR key, VARIANT_BOOL* retval); 133 134 STDMETHOD(GetValueForKey)(BSTR key, VARIANT* value); 135 136 STDMETHOD(GetCount)(ULONG* count); 137 138 STDMETHOD(GetKeyAtIndex)(ULONG index, BSTR* retval); 139 140 STDMETHOD(GetValueAtIndex)(ULONG index, VARIANT* retval); 141 142 143 144private: 145 146 147 148 typedef std::vector< BYTE > ByteArray; 149 150 ByteArray m_byteArray; 151 152 BOOL m_allocated; 153 154 TXTRecordRef m_tref; 155 156 157 158public: 159 160 161 162 uint16_t 163 164 GetLen() 165 166 { 167 168 return TXTRecordGetLength( &m_tref ); 169 170 } 171 172 173 174 const void* 175 176 GetBytes() 177 178 { 179 180 return TXTRecordGetBytesPtr( &m_tref ); 181 182 } 183 184 185 186 void 187 188 SetBytes 189 190 ( 191 192 const unsigned char * bytes, 193 194 uint16_t len 195 196 ); 197 198}; 199 200 201 202OBJECT_ENTRY_AUTO(__uuidof(TXTRecord), CTXTRecord) 203 204