Skip to content

Commit

Permalink
smarter id assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Apr 2, 2020
1 parent 0d372fb commit 79feb10
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 26 deletions.
3 changes: 0 additions & 3 deletions src/cascadia/TerminalControl/TermControlAutomationPeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ Author(s):

namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
typedef unsigned long long IdType;
constexpr IdType InvalidId = 0;

struct TermControlAutomationPeer :
public TermControlAutomationPeerT<TermControlAutomationPeer>,
::Microsoft::Console::Types::IUiaEventDispatcher,
Expand Down
15 changes: 14 additions & 1 deletion src/types/IUiaTraceable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ namespace Microsoft::Console::Types
return _id;
}

protected:
bool AssignId(IdType id) noexcept
{
if (_id == InvalidId)
{
_id = id;
return true;
}
else
{
return false;
}
}

private:
// used to debug objects passed back and forth
// between the provider and the client
IdType _id{};
Expand Down
5 changes: 0 additions & 5 deletions src/types/ScreenInfoUiaProviderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using namespace Microsoft::Console::Types;

IdType ScreenInfoUiaProviderBase::id = 1;

// A helper function to create a SafeArray Version of an int array of a specified length
SAFEARRAY* BuildIntSafeArray(std::basic_string_view<int> data)
{
Expand Down Expand Up @@ -41,9 +39,6 @@ try
_pData = pData;
_wordDelimiters = wordDelimiters;

_id = id;
++id;

UiaTracing::TextProvider::Constructor(*this);
return S_OK;
}
Expand Down
2 changes: 0 additions & 2 deletions src/types/ScreenInfoUiaProviderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,5 @@ namespace Microsoft::Console::Types
const Viewport _getViewport() const noexcept;
void _LockConsole() noexcept;
void _UnlockConsole() noexcept;

static IdType id;
};
}
8 changes: 0 additions & 8 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using namespace Microsoft::Console::Types;

IdType UiaTextRangeBase::id = 1;

// degenerate range constructor.
#pragma warning(suppress : 26434) // WRL RuntimeClassInitialize base is a no-op and we need this for MakeAndInitialize
HRESULT UiaTextRangeBase::RuntimeClassInitialize(_In_ IUiaData* pData, _In_ IRawElementProviderSimple* const pProvider, _In_ std::wstring_view wordDelimiters) noexcept
Expand All @@ -26,9 +24,6 @@ try
_blockRange = false;
_wordDelimiters = wordDelimiters;

_id = id;
++id;

UiaTracing::TextRange::Constructor(*this);
return S_OK;
}
Expand Down Expand Up @@ -123,9 +118,6 @@ try
_pData = a._pData;
_wordDelimiters = a._wordDelimiters;

_id = id;
++id;

UiaTracing::TextRange::Constructor(*this);
return S_OK;
}
Expand Down
3 changes: 0 additions & 3 deletions src/types/UiaTextRangeBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ namespace Microsoft::Console::Types
class UiaTextRangeBase : public WRL::RuntimeClass<WRL::RuntimeClassFlags<WRL::ClassicCom | WRL::InhibitFtmBase>, ITextRangeProvider>,
public IUiaTraceable
{
private:
static IdType id;

protected:
// indicates which direction a movement operation
// is going
Expand Down
28 changes: 26 additions & 2 deletions src/types/UiaTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ TRACELOGGING_DEFINE_PROVIDER(g_UiaProviderTraceProvider,

using namespace Microsoft::Console::Types;

// The first valid ID is 1 for each of our traced UIA object types
IdType UiaTracing::_utrId = 1;
IdType UiaTracing::_siupId = 1;

void UiaTracing::_assignId(UiaTextRangeBase& utr)
{
auto temp = utr.AssignId(_utrId);
if (temp)
{
++_utrId;
}
}

void UiaTracing::_assignId(ScreenInfoUiaProviderBase& siup)
{
auto temp = siup.AssignId(_siupId);
if (temp)
{
++_siupId;
}
}

UiaTracing::UiaTracing() noexcept
{
TraceLoggingRegister(g_UiaProviderTraceProvider);
Expand Down Expand Up @@ -88,11 +110,12 @@ inline std::wstring UiaTracing::_getValue(const TextUnit unit) noexcept
}
}

void UiaTracing::TextRange::Constructor(const UiaTextRangeBase& result) noexcept
void UiaTracing::TextRange::Constructor(UiaTextRangeBase& result) noexcept
{
EnsureRegistration();
if (TraceLoggingProviderEnabled(g_UiaProviderTraceProvider, WINEVENT_LEVEL_VERBOSE, 0))
{
_assignId(result);
TraceLoggingWrite(
g_UiaProviderTraceProvider,
"UiaTextRange::Constructor",
Expand Down Expand Up @@ -362,11 +385,12 @@ void UiaTracing::TextRange::GetChildren(const UiaTextRangeBase& result) noexcept
}
}

void UiaTracing::TextProvider::Constructor(const ScreenInfoUiaProviderBase& result) noexcept
void UiaTracing::TextProvider::Constructor(ScreenInfoUiaProviderBase& result) noexcept
{
EnsureRegistration();
if (TraceLoggingProviderEnabled(g_UiaProviderTraceProvider, WINEVENT_LEVEL_VERBOSE, 0))
{
_assignId(result);
TraceLoggingWrite(
g_UiaProviderTraceProvider,
"ScreenInfoUiaProvider::Constructor",
Expand Down
11 changes: 9 additions & 2 deletions src/types/UiaTracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Microsoft::Console::Types
class TextRange final
{
public:
static void Constructor(const UiaTextRangeBase& result) noexcept;
static void Constructor(UiaTextRangeBase& result) noexcept;
static void Clone(const UiaTextRangeBase& base, const UiaTextRangeBase& result) noexcept;
static void Compare(const UiaTextRangeBase& base, const UiaTextRangeBase& other, bool result) noexcept;
static void CompareEndpoints(const UiaTextRangeBase& base, const TextPatternRangeEndpoint endpoint, const UiaTextRangeBase& other, TextPatternRangeEndpoint otherEndpoint, int result) noexcept;
Expand All @@ -56,7 +56,7 @@ namespace Microsoft::Console::Types
class TextProvider final
{
public:
static void Constructor(const ScreenInfoUiaProviderBase& result) noexcept;
static void Constructor(ScreenInfoUiaProviderBase& result) noexcept;
static void get_ProviderOptions(const ScreenInfoUiaProviderBase& base, ProviderOptions options) noexcept;
static void GetPatternProvider(const ScreenInfoUiaProviderBase& base, PATTERNID patternId) noexcept;
static void GetPropertyValue(const ScreenInfoUiaProviderBase& base, PROPERTYID propertyId) noexcept;
Expand Down Expand Up @@ -100,5 +100,12 @@ namespace Microsoft::Console::Types
static inline std::wstring _getValue(const UiaTextRangeBase& utr) noexcept;
static inline std::wstring _getValue(const TextPatternRangeEndpoint endpoint) noexcept;
static inline std::wstring _getValue(const TextUnit unit) noexcept;

// these are used to assign IDs to new UiaTextRanges and ScreenInfoUiaProviders respectively
static IdType _utrId;
static IdType _siupId;

static void _assignId(UiaTextRangeBase& utr);
static void _assignId(ScreenInfoUiaProviderBase& siup);
};
}

1 comment on commit 79feb10

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • VTE
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw(
Impl
XY
);
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/alphabet.txt .github/actions/spell-check/whitelist/web.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
impl
VTE
xy
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/79feb102e392042e346de95cb63bbb603656f820.txt'

Please sign in to comment.