JD2022-TU1/main/extern/UbiServices/custom/client-sdk/private/ubiservices/applicationStateManager.h

112 lines
4.5 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "ubiservices/core/configs/config.h"
#if defined(US_SDK_SERVER)
#error This file shall not be part of the solution
#endif
#include "ubiservices/core/helpers/platformHelper/platformHelperCommon.h"
#include "ubiservices/core/locks/criticalSection.h"
#include "ubiservices/core/tasks/asyncResultInternal.h"
#include "ubiservices/core/tasks/asyncResultBatch.h"
#include "ubiservices/ubiServicesSdkStateInternal.h"
namespace US_NS {;
class FacadeInternal;
class InstancesManager;
class JobManager;
#if defined(US_TARGET_XONE) || defined(US_TARGET_MANJARO)
#if defined(US_TARGET_WITH_GDK)
class ApplicationEventsManager;
#else
ref class ApplicationEventsManager;
#endif
class HighResolutionChrono;
#endif
// The behavior of the SDK state machine is describe in the following page
// https://mdc-web-tomcat17.ubisoft.org/confluence/display/ubiservices/Transitions+in+application+states
class ApplicationStateManager : public RootObject
{
public:
ApplicationStateManager();
~ApplicationStateManager();
AsyncResultBatch<Facade*, Empty> transitionTo(InstancesManager& im, PlatformState toState);
PlatformState getApplicationState();
void switchToNextState();
UbiServicesSdkStateInternal::Enum getUbiServicesSdkStateInternal();
#if defined(US_TARGET_XONE) || defined(US_TARGET_MANJARO)
const uint64 getElapseMsecSinceLastTransitionFromSuspended();
#endif
#if defined(US_TARGET_STADIA)
void processFirstPartyEvents();
#endif
private:
US_CLASS_COPY_NOT_ALLOWED(ApplicationStateManager);
// All following functions must be called inside the m_stateLock critical section
void updateSdkState();
AsyncResultBatch<Facade*, Empty> transitionFromForegroundTo(InstancesManager& im,
PlatformState toState,
AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
AsyncResultBatch<Facade*, Empty> transitionFromBackgroundTo(InstancesManager& im,
PlatformState toState,
AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
AsyncResultBatch<Facade*, Empty> transitionFromSuspendedTo(InstancesManager& im,
PlatformState toState,
AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
AsyncResultBatch<Facade*, Empty> transitionFromBackgroundToForegroundTo(InstancesManager& im,
PlatformState toState,
AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
AsyncResultBatch<Facade*, Empty> transitionFromSuspendedToForegroundTo(InstancesManager& im,
PlatformState toState,
AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
AsyncResultBatch<Facade*, Empty> transitionFromSuspendedToForegroundToBackgroundTo(InstancesManager& im,
PlatformState toState,
AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
void goToBackground(InstancesManager& im, AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
void resumeFromBackground(InstancesManager& im, AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
void goToSuspended(InstancesManager& im, AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
void resumeFromSuspended(InstancesManager& im, AsyncResultInternal<Map<Facade*, AsyncResult<Empty> > >& result);
void storeEventPeriodicJobRunning(InstancesManager& im);
// There may be several jobs running in parallel, e.g. in the following case :
// fg -> bg -> fg -> bg -> fg -> bg
// Each transition 'bg->fg' starts a job, which may still run during the following transitions
enum { MaxConcurrentCalls = 6 };
::std::unique_ptr<JobManager> m_jobManager;
UbiServicesSdkStateInternal::Enum m_currentSdkState;
bool m_mustSwitchSdkToNextState; // This bool is here to avoid deadlocks
AsyncResultBatch<Facade*, Empty> m_backgroundToForeground;
AsyncResultBatch<Facade*, Empty> m_suspendedToForeground;
Map<FacadeInternal*, bool> m_eventPeriodicJobsRunning;
CriticalSection m_stateLock;
CriticalSection m_switchLock;
#if defined(US_TARGET_XONE) || defined(US_TARGET_MANJARO)
#if defined(US_TARGET_WITH_GDK)
ApplicationEventsManager* m_applicationEventsManager;
#else
ApplicationEventsManager^ m_applicationEventsManager;
#endif
HighResolutionChrono* m_timeSinceLastTransitionFromSuspended;
#endif
};
};