1/*
2 *  IOFireWireLibIOCFPlugIn.cpp
3 *  IOFireWireFamily
4 *
5 *  Created by Niels on Thu Feb 27 2003.
6 *  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 *
8 *	$ Log:IOFireWireLibIOCFPlugIn.cpp,v $
9 */
10
11#import "IOFireWireLibIOCFPlugIn.h"
12#import "IOFireWireLibDevice.h"
13
14namespace IOFireWireLib {
15
16	const IOCFPlugInInterface IOCFPlugIn::sInterface =
17	{
18		INTERFACEIMP_INTERFACE,
19		1, 0, // version/revision
20		& IOCFPlugIn::SProbe,
21		& IOCFPlugIn::SStart,
22		& IOCFPlugIn::SStop
23	};
24
25	IOCFPlugIn::IOCFPlugIn()
26	: IOFireWireIUnknown( reinterpret_cast<const IUnknownVTbl &>( sInterface ) ),
27	  mDevice(0)
28	{
29		// factory counting
30		::CFPlugInAddInstanceForFactory( kIOFireWireLibFactoryID );
31	}
32
33	IOCFPlugIn::~IOCFPlugIn()
34	{
35		if (mDevice)
36			(**mDevice).Release(mDevice) ;
37
38		// cleaning up COM bits
39		::CFPlugInRemoveInstanceForFactory( kIOFireWireLibFactoryID );
40	}
41
42	IOReturn
43	IOCFPlugIn::Probe( CFDictionaryRef propertyTable, io_service_t service, SInt32 *order )
44	{
45		// only load against firewire nubs
46		if( !service || !IOObjectConformsTo(service, "IOFireWireNub") )
47			return kIOReturnBadArgument;
48
49		return kIOReturnSuccess;
50	}
51
52	IOReturn
53	IOCFPlugIn::Start( CFDictionaryRef propertyTable, io_service_t service )
54	{
55		mDevice = DeviceCOM::Alloc( propertyTable, service ) ;
56		if (!mDevice)
57			return kIOReturnError ;
58
59		return kIOReturnSuccess ;
60	}
61
62	IOReturn
63	IOCFPlugIn::Stop()
64	{
65		return kIOReturnSuccess ;
66	}
67
68	HRESULT
69	IOCFPlugIn::QueryInterface( REFIID iid, LPVOID* ppv )
70	{
71		HRESULT		result = S_OK ;
72		*ppv = nil ;
73
74		CFUUIDRef	interfaceID	= CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, iid) ;
75
76		if ( CFEqual(interfaceID, IUnknownUUID) ||
77			CFEqual(interfaceID, kIOCFPlugInInterfaceID) )
78		{
79			*ppv = & GetInterface() ;
80			AddRef() ;
81			::CFRelease(interfaceID) ;
82		}
83		else
84			// we don't have one of these... let's ask the device interface...
85			result = (**mDevice).QueryInterface( mDevice, iid, ppv) ;
86
87
88		return result ;
89	}
90
91	IOCFPlugInInterface**
92	IOCFPlugIn::Alloc()
93	{
94		IOCFPlugIn*		me = new IOCFPlugIn ;
95		if( !me )
96			return nil ;
97
98		return reinterpret_cast<IOCFPlugInInterface **>( & me->GetInterface() );
99	}
100
101	IOReturn
102	IOCFPlugIn::SProbe(void* self, CFDictionaryRef propertyTable, io_service_t service, SInt32 *order )
103	{
104		return IOFireWireIUnknown::InterfaceMap<IOCFPlugIn>::GetThis(self)->Probe(propertyTable, service, order) ;
105	}
106
107	IOReturn
108	IOCFPlugIn::SStart(void* self, CFDictionaryRef propertyTable, io_service_t service)
109	{
110		return IOFireWireIUnknown::InterfaceMap<IOCFPlugIn>::GetThis(self)->Start(propertyTable, service) ;
111	}
112
113	IOReturn
114	IOCFPlugIn::SStop(void* self)
115	{
116		return IOFireWireIUnknown::InterfaceMap<IOCFPlugIn>::GetThis(self)->Stop() ;
117	}
118}
119