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.
22 #include "resource.h" // main symbols
28 #include "DNSSDEventManager.h"
30 #include <CommonServices.h>
32 #include <DebugServices.h>
42 #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
44 #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."
58 class ATL_NO_VTABLE CDNSSDService
:
60 public CComObjectRootEx
<CComSingleThreadModel
>,
62 public CComCoClass
<CDNSSDService
, &CLSID_DNSSDService
>,
64 public IDispatchImpl
<IDNSSDService
, &IID_IDNSSDService
, &LIBID_Bonjour
, /*wMajor =*/ 1, /*wMinor =*/ 0>
72 typedef CComObjectRootEx
<CComSingleThreadModel
> Super
;
82 m_eventManager( NULL
),
96 DECLARE_REGISTRY_RESOURCEID(IDR_DNSSDSERVICE
)
102 BEGIN_COM_MAP(CDNSSDService
)
104 COM_INTERFACE_ENTRY(IDNSSDService
)
106 COM_INTERFACE_ENTRY(IDispatch
)
112 DECLARE_PROTECT_FINAL_CONSTRUCT()
146 SetPrimaryRef( DNSServiceRef primary
)
170 SetSubordRef( DNSServiceRef subord
)
180 inline CDNSSDEventManager
*
186 return m_eventManager
;
194 SetEventManager( IDNSSDEventManager
* eventManager
)
198 if ( m_eventManager
)
202 m_eventManager
->Release();
204 m_eventManager
= NULL
;
214 m_eventManager
= dynamic_cast< CDNSSDEventManager
* >( eventManager
);
216 check( m_eventManager
);
218 m_eventManager
->AddRef();
242 static void DNSSD_API
246 DNSServiceFlags flags
,
248 DNSServiceErrorType errorCode
,
249 const char *replyDomain
,
255 static void DNSSD_API
259 DNSServiceFlags flags
,
260 uint32_t interfaceIndex
,
261 DNSServiceErrorType errorCode
,
262 const char *serviceName
,
264 const char *replyDomain
,
270 static void DNSSD_API
276 DNSServiceFlags flags
,
277 uint32_t interfaceIndex
,
278 DNSServiceErrorType errorCode
,
279 const char *fullname
,
280 const char *hosttarget
,
283 const unsigned char *txtRecord
,
290 static void DNSSD_API
294 DNSServiceFlags flags
,
295 DNSServiceErrorType errorCode
,
304 static void DNSSD_API
308 DNSServiceFlags flags
,
309 uint32_t interfaceIndex
,
310 DNSServiceErrorType errorCode
,
311 const char *fullname
,
322 static void DNSSD_API
326 DNSServiceFlags flags
,
327 uint32_t interfaceIndex
,
328 DNSServiceErrorType errorCode
,
329 const char *hostname
,
330 const struct sockaddr
*address
,
337 static void DNSSD_API
341 DNSServiceFlags flags
,
342 uint32_t interfaceIndex
,
343 DNSServiceErrorType errorCode
,
344 uint32_t externalAddress
, /* four byte IPv4 address in network byte order */
345 DNSServiceProtocol protocol
,
346 uint16_t internalPort
,
347 uint16_t externalPort
, /* may be different than the requested port */
348 uint32_t ttl
, /* may be different than the requested ttl */
354 static void DNSSD_API
358 DNSRecordRef RecordRef
,
359 DNSServiceFlags flags
,
360 DNSServiceErrorType errorCode
,
368 ShouldHandleReply( DNSServiceErrorType errorCode
, CDNSSDEventManager
*& eventManager
);
372 static LRESULT CALLBACK
374 WndProc( HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
378 typedef std::map
< SOCKET
, CDNSSDService
* > SocketMap
;
382 static BOOL m_registeredWindowClass
;
384 static HWND m_hiddenWindow
;
386 static SocketMap m_socketMap
;
388 CDNSSDEventManager
* m_eventManager
;
394 DNSServiceRef m_primary
;
396 DNSServiceRef m_subord
;
400 STDMETHOD(EnumerateDomains
)(DNSSDFlags flags
, ULONG ifIndex
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
402 STDMETHOD(Browse
)(DNSSDFlags flags
, ULONG interfaceIndex
, BSTR regtype
, BSTR domain
, IDNSSDEventManager
* eventManager
, IDNSSDService
** sdref
);
404 STDMETHOD(Resolve
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR serviceName
, BSTR regType
, BSTR domain
, IDNSSDEventManager
* eventManager
, IDNSSDService
** service
);
406 STDMETHOD(Register
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR name
, BSTR regType
, BSTR domain
, BSTR host
, USHORT port
, ITXTRecord
*record
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
408 STDMETHOD(QueryRecord
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR fullname
, DNSSDRRType rrtype
, DNSSDRRClass rrclass
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
410 STDMETHOD(RegisterRecord
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR fullname
, DNSSDRRType rrtype
, DNSSDRRClass rrclass
, VARIANT rdata
, ULONG ttl
, IDNSSDEventManager
* eventManager
, IDNSSDRecord
** record
);
412 STDMETHOD(AddRecord
)(DNSSDFlags flags
, DNSSDRRType rrtype
, VARIANT rdata
, ULONG ttl
, IDNSSDRecord
** record
);
414 STDMETHOD(ReconfirmRecord
)(DNSSDFlags flags
, ULONG ifIndex
, BSTR fullname
, DNSSDRRType rrtype
, DNSSDRRClass rrclass
, VARIANT rdata
);
416 STDMETHOD(GetProperty
)(BSTR prop
, VARIANT
* value
);
418 STDMETHOD(GetAddrInfo
)(DNSSDFlags flags
, ULONG ifIndex
, DNSSDAddressFamily addressFamily
, BSTR hostname
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
420 STDMETHOD(NATPortMappingCreate
)(DNSSDFlags flags
, ULONG ifIndex
, DNSSDAddressFamily addressFamily
, DNSSDProtocol protocol
, USHORT internalPort
, USHORT externalPort
, ULONG ttl
, IDNSSDEventManager
*eventManager
, IDNSSDService
**service
);
422 STDMETHOD(Stop
)(void);
428 OBJECT_ENTRY_AUTO(__uuidof(DNSSDService
), CDNSSDService
)