-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move FreeThreadedHen to separate files
The AtlHen files became a bit big.
- Loading branch information
100029962
committed
Apr 11, 2023
1 parent
03713fe
commit 71ceef9
Showing
6 changed files
with
70 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "pch.h" | ||
#include "FreeThreadedHen.h" | ||
#include <cassert> | ||
#include <future> | ||
#include <ComUtility/Utility.h> | ||
#include <winrt/base.h> | ||
|
||
HRESULT FreeThreadedHen::FinalConstruct() | ||
{ | ||
return CoCreateFreeThreadedMarshaler(GetControllingUnknown(), &m_marshaler); | ||
} | ||
|
||
HRESULT FreeThreadedHen::Cluck() | ||
{ | ||
assert(m_myThreadId == GetCurrentThreadId()); | ||
return S_OK; | ||
} | ||
|
||
HRESULT FreeThreadedHen::CluckAsync(IAsyncCluckObserver* cluckObserver) | ||
{ | ||
winrt::com_ptr<IAsyncCluckObserver> observer; | ||
observer.copy_from(cluckObserver); | ||
|
||
auto result = std::async(std::launch::async, [observer] { | ||
ComRuntime comRuntime{ Apartment::MultiThreaded }; | ||
return observer->OnCluck(); | ||
}); | ||
|
||
return result.get(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
#include "resource.h" // main symbols | ||
#include <AtlServer/AtlServer.h> | ||
|
||
using namespace ATL; | ||
|
||
/** A hen that can be called from any thread by aggregating | ||
* the free threaded marshaler | ||
*/ | ||
class ATL_NO_VTABLE FreeThreadedHen : | ||
public CComObjectRootEx<CComMultiThreadModel>, | ||
public CComCoClass<FreeThreadedHen, &CLSID_FreeThreadedHen>, | ||
public IHen | ||
{ | ||
public: | ||
DECLARE_REGISTRY_RESOURCEID(IDR_HEN) | ||
DECLARE_PROTECT_FINAL_CONSTRUCT() | ||
DECLARE_GET_CONTROLLING_UNKNOWN() | ||
|
||
BEGIN_COM_MAP(FreeThreadedHen) | ||
COM_INTERFACE_ENTRY(IHen) | ||
COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_marshaler) | ||
END_COM_MAP() | ||
|
||
HRESULT FinalConstruct(); | ||
|
||
HRESULT Cluck() override; | ||
HRESULT CluckAsync(IAsyncCluckObserver* cluckObserver) override; | ||
|
||
private: | ||
CComPtr<IUnknown> m_marshaler; | ||
unsigned long m_myThreadId = GetCurrentThreadId(); | ||
}; | ||
|
||
OBJECT_ENTRY_AUTO(CLSID_FreeThreadedHen, FreeThreadedHen) | ||
|