1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2009 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 Change History (most recent first):
19 $Log: DNSSDService.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.
27 #include "resource.h" // main symbols
30 #include "DNSSDEventManager.h"
31 #include <CommonServices.h>
32 #include <DebugServices.h>
37 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
38 #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."
45 class ATL_NO_VTABLE CDNSSDService
:
46 public CComObjectRootEx
<CComSingleThreadModel
>,
47 public CComCoClass
<CDNSSDService
, &CLSID_DNSSDService
>,
48 public IDispatchImpl
<IDNSSDService
, &IID_IDNSSDService
, &LIBID_Bonjour
, /*wMajor =*/ 1, /*wMinor =*/ 0>
52 typedef CComObjectRootEx
<CComSingleThreadModel
> Super
;
57 m_eventManager( NULL
),
64 DECLARE_REGISTRY_RESOURCEID(IDR_DNSSDSERVICE
)
67 BEGIN_COM_MAP(CDNSSDService
)
68 COM_INTERFACE_ENTRY(IDNSSDService
)
69 COM_INTERFACE_ENTRY(IDispatch
)
72 DECLARE_PROTECT_FINAL_CONSTRUCT()
89 SetPrimaryRef( DNSServiceRef primary
)
101 SetSubordRef( DNSServiceRef subord
)
106 inline CDNSSDEventManager
*
109 return m_eventManager
;
113 SetEventManager( IDNSSDEventManager
* eventManager
)
115 if ( m_eventManager
)
117 m_eventManager
->Release();
118 m_eventManager
= NULL
;
123 m_eventManager
= dynamic_cast< CDNSSDEventManager
* >( eventManager
);
124 check( m_eventManager
);
125 m_eventManager
->AddRef();
137 static void DNSSD_API
141 DNSServiceFlags flags
,
143 DNSServiceErrorType errorCode
,
144 const char *replyDomain
,
148 static void DNSSD_API
152 DNSServiceFlags flags
,
153 uint32_t interfaceIndex
,
154 DNSServiceErrorType errorCode
,
155 const char *serviceName
,
157 const char *replyDomain
,
161 static void DNSSD_API
165 DNSServiceFlags flags
,
166 uint32_t interfaceIndex
,
167 DNSServiceErrorType errorCode
,
168 const char *fullname
,
169 const char *hosttarget
,
172 const unsigned char *txtRecord
,
176 static void DNSSD_API
180 DNSServiceFlags flags
,
181 DNSServiceErrorType errorCode
,
188 static void DNSSD_API
192 DNSServiceFlags flags
,
193 uint32_t interfaceIndex
,
194 DNSServiceErrorType errorCode
,
195 const char *fullname
,
204 static void DNSSD_API
208 DNSServiceFlags flags
,
209 uint32_t interfaceIndex
,
210 DNSServiceErrorType errorCode
,
211 const char *hostname
,
212 const struct sockaddr
*address
,
217 static void DNSSD_API
221 DNSServiceFlags flags
,
222 uint32_t interfaceIndex
,
223 DNSServiceErrorType errorCode
,
224 uint32_t externalAddress
, /* four byte IPv4 address in network byte order */
225 DNSServiceProtocol protocol
,
226 uint16_t internalPort
,
227 uint16_t externalPort
, /* may be different than the requested port */
228 uint32_t ttl
, /* may be different than the requested ttl */
232 static void DNSSD_API
236 DNSRecordRef RecordRef
,
237 DNSServiceFlags flags
,
238 DNSServiceErrorType errorCode
,
243 ShouldHandleReply( DNSServiceErrorType errorCode
, CDNSSDEventManager
*& eventManager
);
245 static LRESULT CALLBACK
246 WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
248 typedef std::map
< SOCKET
, CDNSSDService
* > SocketMap
;
250 static BOOL m_registeredWindowClass
;
251 static HWND m_hiddenWindow
;
252 static SocketMap m_socketMap
;
253 CDNSSDEventManager
* m_eventManager
;
256 DNSServiceRef m_primary
;
257 DNSServiceRef m_subord
;
259 STDMETHOD(EnumerateDomains
)(DNSSDFlags flags
, ULONG ifIndex
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
260 STDMETHOD(Browse
)(DNSSDFlags flags
, ULONG interfaceIndex
, BSTR regtype
, BSTR domain
, IDNSSDEventManager
* eventManager
, IDNSSDService
** sdref
);
261 STDMETHOD(Resolve
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR serviceName
, BSTR regType
, BSTR domain
, IDNSSDEventManager
* eventManager
, IDNSSDService
** service
);
262 STDMETHOD(Register
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR name
, BSTR regType
, BSTR domain
, BSTR host
, USHORT port
, ITXTRecord
*record
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
263 STDMETHOD(QueryRecord
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR fullname
, DNSSDRRType rrtype
, DNSSDRRClass rrclass
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
264 STDMETHOD(RegisterRecord
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR fullname
, DNSSDRRType rrtype
, DNSSDRRClass rrclass
, VARIANT rdata
, ULONG ttl
, IDNSSDEventManager
* eventManager
, IDNSSDRecord
** record
);
265 STDMETHOD(AddRecord
)(DNSSDFlags flags
, DNSSDRRType rrtype
, VARIANT rdata
, ULONG ttl
, IDNSSDRecord
** record
);
266 STDMETHOD(ReconfirmRecord
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR fullname
, DNSSDRRType rrtype
, DNSSDRRClass rrclass
, VARIANT rdata
);
267 STDMETHOD(GetProperty
)(BSTR prop
, VARIANT
* value
);
268 STDMETHOD(GetAddrInfo
)(DNSSDFlags flags
, ULONG ifIndex
, DNSSDAddressFamily addressFamily
, BSTR hostname
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
269 STDMETHOD(NATPortMappingCreate
)(DNSSDFlags flags
, ULONG ifIndex
, DNSSDAddressFamily addressFamily
, DNSSDProtocol protocol
, USHORT internalPort
, USHORT externalPort
, ULONG ttl
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
270 STDMETHOD(Stop
)(void);
273 OBJECT_ENTRY_AUTO(__uuidof(DNSSDService
), CDNSSDService
)