Skip to content

Commit

Permalink
Objc2Winmd binary update: (#1913)
Browse files Browse the repository at this point in the history
* Objc2Winmd binary update: Fixed memory leak issues with IAsyncOperation implementation

* ObjC2Winmd binary update: Removed unnecessary comments
  • Loading branch information
mukhole authored Feb 3, 2017
1 parent 5a10c6b commit c740efc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bin/objc2winmd.exe
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ inline std::wstring getWString(const char* str) {
return std::wstring(&str[0], &str[len - 1]);
}

//ABI::FacebookSDK::FBSDKLoginKit::FBSDKLoginManagerLoginResult
//ABI::FacebookSDK::FBSDKLoginKit::IFBSDKLoginManagerLoginResult
template<typename resultType, typename resultInterfaceType>
template<typename resultType, typename resultInterfaceType, bool = _is_COM_Object(resultInterfaceType)>
class AsyncOperationImpl :
public RuntimeClass<
RuntimeClassFlags<WinRtClassicComMix>,
Expand Down Expand Up @@ -77,4 +75,57 @@ class AsyncOperationImpl :
void OnClose() override {}
void OnCancel() override {}
};

template<typename resultType, typename resultInterfaceType>
class AsyncOperationImpl<resultType, resultInterfaceType, true> :
public RuntimeClass<
RuntimeClassFlags<WinRtClassicComMix>,
IAsyncOperation<resultType>,
AsyncBase<IAsyncOperationCompletedHandler<resultType>>> {

typedef RuntimeClass<RuntimeClassFlags<WinRtClassicComMix>,
IAsyncOperation<resultType>,
AsyncBase<IAsyncOperationCompletedHandler<resultType>>> RuntimeClassT;

// This will fail for double pointer (and higher level pointers), but we do not care so much about them.
InspectableClass((std::wstring(L"Windows.Foundation.IAsyncOperation") + getWString(typeid(std::remove_pointer<resultType>).name())).c_str(), BaseTrust);

ComPtr<typename std::remove_pointer<resultInterfaceType>::type> _result;
public:
AsyncOperationImpl()
{
Start();
}
IFACEMETHODIMP put_Completed(IAsyncOperationCompletedHandler<resultType> *pCompleteHandler) override
{
return AsyncBase::PutOnComplete(pCompleteHandler);
}
IFACEMETHODIMP get_Completed(IAsyncOperationCompletedHandler<resultType> **ppCompleteHandler) override
{
return AsyncBase::GetOnComplete(ppCompleteHandler);
}
void setResult(resultInterfaceType result)
{
_result.Attach(result);
FireCompletion();
}
IFACEMETHODIMP GetResults(resultInterfaceType* results) override
{
*results = 0;
HRESULT hr = AsyncBase::CheckValidStateForResultsCall();
if (SUCCEEDED(hr))
{
// Implicit AddRef
ComPtr<typename std::remove_pointer<resultInterfaceType>::type> ptr = _result;
*results = ptr.Detach();
}
return hr;
}
HRESULT OnStart() override
{
return S_OK;
}
void OnClose() override {}
void OnCancel() override {}
};
}

0 comments on commit c740efc

Please sign in to comment.