ExplorerBarWindow.h [plain text]
#ifndef __EXPLORER_BAR_WINDOW__
#define __EXPLORER_BAR_WINDOW__
#pragma once
#include "afxtempl.h"
#include "dns_sd.h"
#include <list>
struct ServiceHandlerEntry;
class ExplorerBarWindow;
struct ServiceInfo
{
CString displayName;
char * name;
char * type;
char * domain;
uint32_t ifi;
HTREEITEM item;
ServiceHandlerEntry * handler;
DWORD refs;
ServiceInfo( void )
{
item = NULL;
type = NULL;
domain = NULL;
handler = NULL;
}
~ServiceInfo( void )
{
if( name )
{
free( name );
}
if( type )
{
free( type );
}
if( domain )
{
free( domain );
}
}
};
typedef CArray < ServiceInfo *, ServiceInfo * > ServiceInfoArray;
struct TextRecord
{
uint8_t * mData;
uint16_t mSize;
TextRecord( void )
{
mData = NULL;
mSize = 0;
}
~TextRecord( void )
{
if( mData )
{
free( mData );
}
}
void GetData( void *outData, uint16_t *outSize )
{
if( outData )
{
*( (void **) outData ) = mData;
}
if( outSize )
{
*outSize = mSize;
}
}
OSStatus SetData( const void *inData, uint16_t inSize )
{
OSStatus err;
uint8_t * newData;
newData = (uint8_t *) malloc( inSize );
require_action( newData, exit, err = kNoMemoryErr );
memcpy( newData, inData, inSize );
if( mData )
{
free( mData );
}
mData = newData;
mSize = inSize;
err = kNoErr;
exit:
return( err );
}
};
struct ResolveInfo
{
CString host;
uint16_t port;
uint32_t ifi;
TextRecord txt;
ServiceHandlerEntry * handler;
};
struct ServiceHandlerEntry
{
const char * type;
const char * urlScheme;
DNSServiceRef ref;
ServiceInfoArray array;
ExplorerBarWindow * obj;
bool needsLogin;
ServiceHandlerEntry( void )
{
type = NULL;
urlScheme = NULL;
ref = NULL;
obj = NULL;
needsLogin = false;
}
~ServiceHandlerEntry( void )
{
int i;
int n;
n = (int) array.GetSize();
for( i = 0; i < n; ++i )
{
delete array[ i ];
}
}
};
typedef CArray < ServiceHandlerEntry *, ServiceHandlerEntry * > ServiceHandlerArray;
class ExplorerBar;
class ExplorerBarWindow : public CWnd
{
protected:
ExplorerBar * mOwner;
CTreeCtrl mTree;
ServiceHandlerArray mServiceHandlers;
DNSServiceRef mResolveServiceRef;
public:
ExplorerBarWindow( void );
virtual ~ExplorerBarWindow( void );
protected:
afx_msg int OnCreate( LPCREATESTRUCT inCreateStruct );
afx_msg void OnDestroy( void );
afx_msg void OnSize( UINT inType, int inX, int inY );
afx_msg void OnDoubleClick( NMHDR *inNMHDR, LRESULT *outResult );
afx_msg LRESULT OnServiceEvent( WPARAM inWParam, LPARAM inLParam );
static void DNSSD_API
BrowseCallBack(
DNSServiceRef inRef,
DNSServiceFlags inFlags,
uint32_t inInterfaceIndex,
DNSServiceErrorType inErrorCode,
const char * inName,
const char * inType,
const char * inDomain,
void * inContext );
LONG OnServiceAdd( ServiceInfo * service );
LONG OnServiceRemove( ServiceInfo * service );
OSStatus StartResolve( ServiceInfo *inService );
void StopResolve( void );
void Stop( DNSServiceRef ref );
static void DNSSD_API
ResolveCallBack(
DNSServiceRef inRef,
DNSServiceFlags inFlags,
uint32_t inInterfaceIndex,
DNSServiceErrorType inErrorCode,
const char * inFullName,
const char * inHostName,
uint16_t inPort,
uint16_t inTXTSize,
const char * inTXT,
void * inContext );
LONG OnResolve( ResolveInfo * resolve );
public:
ExplorerBar * GetOwner( void ) const { return( mOwner ); }
void SetOwner( ExplorerBar *inOwner ) { mOwner = inOwner; }
DECLARE_MESSAGE_MAP()
private:
typedef std::list< DNSServiceRef > ServiceRefList;
HTREEITEM m_about;
ServiceRefList m_serviceRefs;
CImageList m_imageList;
};
#endif // __EXPLORER_BAR_WINDOW__