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#ifndef _CDNSSDSERVICE_H
20#define _CDNSSDSERVICE_H
21
22#include "IDNSSDService.h"
23#include "nsCOMPtr.h"
24#include "nsComponentManagerUtils.h"
25#include "nsIThread.h"
26#include "nsIRunnable.h"
27#include "prtpool.h"
28#include <dns_sd.h>
29#include <stdio.h>
30#include <string>
31
32
33#define CDNSSDSERVICE_CONTRACTID "@apple.com/DNSSDService;1"
34#define CDNSSDSERVICE_CLASSNAME "CDNSSDService"
35#define CDNSSDSERVICE_CID { 0x944ED267, 0x465A, 0x4989, { 0x82, 0x72, 0x7E, 0xE9, 0x28, 0x6C, 0x99, 0xA5 } }
36
37
38/* Header file */
39class CDNSSDService : public IDNSSDService, nsIRunnable
40{
41public:
42NS_DECL_ISUPPORTS
43NS_DECL_IDNSSDSERVICE
44NS_DECL_NSIRUNNABLE
45
46CDNSSDService();
47CDNSSDService( DNSServiceRef mainRef, nsISupports * listener );
48
49virtual ~CDNSSDService();
50
51private:
52
53static void DNSSD_API
54BrowseReply
55(
56    DNSServiceRef sdRef,
57    DNSServiceFlags flags,
58    uint32_t interfaceIndex,
59    DNSServiceErrorType errorCode,
60    const char      *   serviceName,
61    const char      *   regtype,
62    const char      *   replyDomain,
63    void            *   context
64);
65
66static void DNSSD_API
67ResolveReply
68(
69    DNSServiceRef sdRef,
70    DNSServiceFlags flags,
71    uint32_t interfaceIndex,
72    DNSServiceErrorType errorCode,
73    const char          *   fullname,
74    const char          *   hosttarget,
75    uint16_t port,
76    uint16_t txtLen,
77    const unsigned char *   txtRecord,
78    void                *   context
79);
80
81static void
82Read
83(
84    void * arg
85);
86
87nsresult
88SetupNotifications();
89
90void
91Cleanup();
92
93char m_master;
94PRThreadPool    *   m_threadPool;
95DNSServiceRef m_mainRef;
96DNSServiceRef m_subRef;
97nsISupports     *   m_listener;
98PRFileDesc      *   m_fileDesc;
99PRJobIoDesc m_iod;
100PRJob           *   m_job;
101};
102
103
104#endif
105