Skip to content

Commit

Permalink
PackageInfo: delay the fetching of package names until PackageData is…
Browse files Browse the repository at this point in the history
… up to date
  • Loading branch information
Christian-Stieber committed Jun 8, 2024
1 parent 9d44729 commit c0c14b9
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions Sources/Modules/PackageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/************************************************************************/

typedef SteamBot::Modules::LicenseList::Messageboard::NewLicenses NewLicenses;
typedef SteamBot::Modules::PackageData::Whiteboard::PackageData PackageData;
typedef SteamBot::Modules::PackageInfo::Info Info;

/************************************************************************/
Expand Down Expand Up @@ -213,9 +214,14 @@ namespace

private:
SteamBot::Messageboard::WaiterType<NewLicenses> newLicensesWaiter;
SteamBot::Whiteboard::WaiterType<PackageData> packageDataWaiter;

// we collect them here, until PackageData is current
std::vector<std::shared_ptr<const NewLicenses>> newLicensesMessages;

private:
void updateLicenseInfo(const SteamBot::AppID);
void updateNewLicenses();

public:
void handle(std::shared_ptr<const NewLicenses>);
Expand Down Expand Up @@ -1130,39 +1136,56 @@ void PackageInfoModule::updateLicenseInfo(const SteamBot::AppID appId)

/************************************************************************/

void PackageInfoModule::handle(std::shared_ptr<const NewLicenses> newLicenses)
void PackageInfoModule::updateNewLicenses()
{
for (const auto packageId : newLicenses->licenses)
if (PackageData::isCurrent())
{
auto cancellation=SteamBot::Client::getClient().cancel.registerObject(mutex);

std::lock_guard<decltype(mutex)> lock(mutex);
if (auto info=PackageInfo::get().get(packageId))
{
BOOST_LOG_TRIVIAL(info) << "package-id " << SteamBot::toInteger(packageId) << " already has known name \"" << info->packageName << "\"";
}
else
while (!newLicensesMessages.empty())
{
typedef SteamBot::Modules::LicenseList::Whiteboard::LicenseIdentifier LicenseIdentifier;
auto packageInfo=SteamBot::Modules::PackageData::getPackageInfo(LicenseIdentifier(packageId));
if (packageInfo!=nullptr)
const auto message=std::move(newLicensesMessages.back());
newLicensesMessages.pop_back();

for (const auto packageId : message->licenses)
{
for (const auto appId: packageInfo->appIds)
auto cancellation=SteamBot::Client::getClient().cancel.registerObject(mutex);

std::lock_guard<decltype(mutex)> lock(mutex);
if (auto info=PackageInfo::get().get(packageId))
{
BOOST_LOG_TRIVIAL(info) << "package-id " << SteamBot::toInteger(packageId) << " already has known name \"" << info->packageName << "\"";
}
else
{
updateLicenseInfo(appId);
typedef SteamBot::Modules::LicenseList::Whiteboard::LicenseIdentifier LicenseIdentifier;
auto packageInfo=SteamBot::Modules::PackageData::getPackageInfo(LicenseIdentifier(packageId));
if (packageInfo!=nullptr)
{
for (const auto appId: packageInfo->appIds)
{
updateLicenseInfo(appId);
}
}
PackageInfo::get().save(false);
}
}
PackageInfo::get().save(false);
}
PackageInfo::get().save(true);
}
PackageInfo::get().save(true);
}

/************************************************************************/

void PackageInfoModule::handle(std::shared_ptr<const NewLicenses> message)
{
newLicensesMessages.push_back(std::move(message));
}

/************************************************************************/

void PackageInfoModule::init(SteamBot::Client& client)
{
newLicensesWaiter=client.messageboard.createWaiter<NewLicenses>(*waiter);
packageDataWaiter=client.whiteboard.createWaiter<PackageData>(*waiter);
}

/************************************************************************/
Expand All @@ -1173,6 +1196,8 @@ void PackageInfoModule::run(SteamBot::Client&)
{
waiter->wait();
newLicensesWaiter->handle(this);
packageDataWaiter->has();
updateNewLicenses();
}
}

Expand Down

0 comments on commit c0c14b9

Please sign in to comment.