2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "DeviceManagerPrivatePCH.h"
# define LOCTEXT_NAMESPACE "SDeviceProcesses"
/* SMessagingEndpoints structors
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SDeviceProcesses : : ~ SDeviceProcesses ( )
{
if ( Model . IsValid ( ) )
{
Model - > OnSelectedDeviceServiceChanged ( ) . RemoveAll ( this ) ;
}
}
/* SDeviceDetails interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SDeviceProcesses : : Construct ( const FArguments & InArgs , const FDeviceManagerModelRef & InModel )
{
Model = InModel ;
ShowProcessTree = true ;
ChildSlot
[
SNew ( SOverlay )
+ SOverlay : : Slot ( )
[
SNew ( SVerticalBox )
. IsEnabled ( this , & SDeviceProcesses : : HandleProcessesBoxIsEnabled )
+ SVerticalBox : : Slot ( )
. FillHeight ( 1.0f )
. Padding ( 0.0f , 4.0f , 0.0f , 0.0f )
[
// process list
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " ToolPanel.GroupBorder " ) )
. Padding ( 0.0f )
[
SAssignNew ( ProcessTreeView , STreeView < FDeviceProcessesProcessTreeNodePtr > )
. ItemHeight ( 20.0f )
. OnGenerateRow ( this , & SDeviceProcesses : : HandleProcessTreeViewGenerateRow )
. OnGetChildren ( this , & SDeviceProcesses : : HandleProcessTreeViewGetChildren )
. SelectionMode ( ESelectionMode : : Multi )
. TreeItemsSource ( & ProcessList )
. HeaderRow
(
SNew ( SHeaderRow )
+ SHeaderRow : : Column ( " Name " )
2014-04-23 18:06:41 -04:00
. DefaultLabel ( LOCTEXT ( " ProcessListNameColumnHeader " , " Process Name " ) )
2014-03-14 14:13:41 -04:00
. FillWidth ( 0.275f )
+ SHeaderRow : : Column ( " PID " )
2014-04-23 18:06:41 -04:00
. DefaultLabel ( LOCTEXT ( " ProcessListPidColumnHeader " , " PID " ) )
2014-03-14 14:13:41 -04:00
. FillWidth ( 0.15f )
+ SHeaderRow : : Column ( " User " )
2014-04-23 18:06:41 -04:00
. DefaultLabel ( LOCTEXT ( " ProcessListUserColumnHeader " , " User " ) )
2014-03-14 14:13:41 -04:00
. FillWidth ( 0.275f )
+ SHeaderRow : : Column ( " Threads " )
2014-04-23 18:06:41 -04:00
. DefaultLabel ( LOCTEXT ( " ProcessListThreadsColumnHeader " , " Threads " ) )
2014-03-14 14:13:41 -04:00
. FillWidth ( 0.15f )
+ SHeaderRow : : Column ( " Parent " )
2014-04-23 18:06:41 -04:00
. DefaultLabel ( LOCTEXT ( " ProcessListParentColumnHeader " , " Parent PID " ) )
2014-03-14 14:13:41 -04:00
. FillWidth ( 0.15f )
)
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 4.0f , 0.0f , 0.0f )
[
SNew ( SBorder )
. Padding ( FMargin ( 8.0f , 6.0f , 8.0f , 4.0f ) )
. BorderImage ( FEditorStyle : : GetBrush ( " ToolPanel.GroupBorder " ) )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
[
SNew ( SCheckBox )
. IsChecked ( this , & SDeviceProcesses : : HandleProcessTreeCheckBoxIsChecked )
. OnCheckStateChanged ( this , & SDeviceProcesses : : HandleProcessTreeCheckBoxCheckStateChanged )
. Padding ( FMargin ( 4.0f , 0.0f ) )
2014-04-23 18:06:41 -04:00
. ToolTipText ( LOCTEXT ( " ProcessTreeCheckBoxToolTip " , " Check this box to display the list of processes as a tree instead of a flat list " ) )
2014-03-14 14:13:41 -04:00
[
SNew ( STextBlock )
2014-04-23 18:06:41 -04:00
. Text ( LOCTEXT ( " ProcessTreeCheckBoxText " , " Show process tree " ) )
2014-03-14 14:13:41 -04:00
]
]
+ SHorizontalBox : : Slot ( )
. HAlign ( HAlign_Right )
[
SNew ( SButton )
. IsEnabled ( this , & SDeviceProcesses : : HandleTerminateProcessButtonIsEnabled )
. OnClicked ( this , & SDeviceProcesses : : HandleTerminateProcessButtonClicked )
2014-04-23 18:06:41 -04:00
. Text ( LOCTEXT ( " TerminateProcessButtonText " , " Terminate Process " ) )
2014-03-14 14:13:41 -04:00
]
]
]
]
+ SOverlay : : Slot ( )
. HAlign ( HAlign_Center )
. VAlign ( VAlign_Center )
[
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " NotificationList.ItemBackground " ) )
. Padding ( 8.0f )
2014-04-02 18:09:23 -04:00
. Visibility ( this , & SDeviceProcesses : : HandleMessageOverlayVisibility )
2014-03-14 14:13:41 -04:00
[
SNew ( STextBlock )
2014-04-02 18:09:23 -04:00
. Text ( this , & SDeviceProcesses : : HandleMessageOverlayText )
2014-03-14 14:13:41 -04:00
]
]
] ;
Model - > OnSelectedDeviceServiceChanged ( ) . AddRaw ( this , & SDeviceProcesses : : HandleModelSelectedDeviceServiceChanged ) ;
ReloadProcessList ( true ) ;
---- Merging with SlateDev branch ----
Introduces the concept of "Active Ticking" to allow Slate to go to sleep when there is no need to update the UI.
While asleep, Slate will skip the Tick & Paint pass for that frame entirely.
- There are TWO ways to "wake" Slate and cause a Tick/Paint pass:
1. Provide some sort of input (mouse movement, clicks, and key presses). Slate will always tick when the user is active.
- Therefore, if the logic in a given widget's Tick is only relevant in response to user action, there is no need to register an active tick.
2. Register an Active Tick. Currently this is an all-or-nothing situation, so if a single active tick needs to execute, all of Slate will be ticked.
- The purpose of an Active Tick is to allow a widget to "drive" Slate and guarantee a Tick/Paint pass in the absence of any user action.
- Examples include animation, async operations that update periodically, progress updates, loading bars, etc.
- An empty active tick is registered for viewports when they are real-time, so game project widgets are unaffected by this change and should continue to work as before.
- An Active Tick is registered by creating an FWidgetActiveTickDelegate and passing it to SWidget::RegisterActiveTick()
- There are THREE ways to unregister an active tick:
1. Return EActiveTickReturnType::StopTicking from the active tick function
2. Pass the FActiveTickHandle returned by RegisterActiveTick() to SWidget::UnregisterActiveTick()
3. Destroy the widget responsible for the active tick
- Sleeping is currently disabled, can be enabled with Slate.AllowSlateToSleep cvar
- There is currently a little buffer time during which Slate continues to tick following any input. Long-term, this is planned to be removed.
- The duration of the buffer can be adjusted using Slate.SleepBufferPostInput cvar (defaults to 1.0f)
- The FCurveSequence API has been updated to work with the active tick system
- Playing a curve sequence now requires that you pass the widget being animated by the sequence
- The active tick will automatically be registered on behalf of the widget and unregister when the sequence is complete
- GetLerpLooping() has been removed. Instead, pass true as the second param to Play() to indicate that the animation will loop. This causes the active tick to be registered indefinitely until paused or jumped to the start/end.
[CL 2391669 by Dan Hertzka in Main branch]
2014-12-17 16:07:57 -05:00
// Register for an active update every 2.5 seconds
2014-12-19 17:44:49 -05:00
RegisterActiveTimer ( 2.5f , FWidgetActiveTimerDelegate : : CreateSP ( this , & SDeviceProcesses : : UpdateProcessList ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-12-19 17:44:49 -05:00
EActiveTimerReturnType SDeviceProcesses : : UpdateProcessList ( double InCurrentTime , float InDeltaTime )
2014-03-14 14:13:41 -04:00
{
---- Merging with SlateDev branch ----
Introduces the concept of "Active Ticking" to allow Slate to go to sleep when there is no need to update the UI.
While asleep, Slate will skip the Tick & Paint pass for that frame entirely.
- There are TWO ways to "wake" Slate and cause a Tick/Paint pass:
1. Provide some sort of input (mouse movement, clicks, and key presses). Slate will always tick when the user is active.
- Therefore, if the logic in a given widget's Tick is only relevant in response to user action, there is no need to register an active tick.
2. Register an Active Tick. Currently this is an all-or-nothing situation, so if a single active tick needs to execute, all of Slate will be ticked.
- The purpose of an Active Tick is to allow a widget to "drive" Slate and guarantee a Tick/Paint pass in the absence of any user action.
- Examples include animation, async operations that update periodically, progress updates, loading bars, etc.
- An empty active tick is registered for viewports when they are real-time, so game project widgets are unaffected by this change and should continue to work as before.
- An Active Tick is registered by creating an FWidgetActiveTickDelegate and passing it to SWidget::RegisterActiveTick()
- There are THREE ways to unregister an active tick:
1. Return EActiveTickReturnType::StopTicking from the active tick function
2. Pass the FActiveTickHandle returned by RegisterActiveTick() to SWidget::UnregisterActiveTick()
3. Destroy the widget responsible for the active tick
- Sleeping is currently disabled, can be enabled with Slate.AllowSlateToSleep cvar
- There is currently a little buffer time during which Slate continues to tick following any input. Long-term, this is planned to be removed.
- The duration of the buffer can be adjusted using Slate.SleepBufferPostInput cvar (defaults to 1.0f)
- The FCurveSequence API has been updated to work with the active tick system
- Playing a curve sequence now requires that you pass the widget being animated by the sequence
- The active tick will automatically be registered on behalf of the widget and unregister when the sequence is complete
- GetLerpLooping() has been removed. Instead, pass true as the second param to Play() to indicate that the animation will loop. This causes the active tick to be registered indefinitely until paused or jumped to the start/end.
[CL 2391669 by Dan Hertzka in Main branch]
2014-12-17 16:07:57 -05:00
ReloadProcessList ( true ) ;
2014-03-14 14:13:41 -04:00
2014-12-19 17:44:49 -05:00
return EActiveTimerReturnType : : Continue ;
2014-03-14 14:13:41 -04:00
}
/* SDeviceDetails implementation
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SDeviceProcesses : : ReloadProcessList ( bool FullyReload )
{
// reload running processes
if ( FullyReload )
{
RunningProcesses . Reset ( ) ;
ITargetDeviceServicePtr DeviceService = Model - > GetSelectedDeviceService ( ) ;
if ( DeviceService . IsValid ( ) )
{
ITargetDevicePtr TargetDevice = DeviceService - > GetDevice ( ) ;
if ( TargetDevice . IsValid ( ) )
{
TargetDevice - > GetProcessSnapshot ( RunningProcesses ) ;
}
}
}
// update process tree
TMap < uint32 , FDeviceProcessesProcessTreeNodePtr > NewProcessMap ;
for ( int32 ProcessIndex = 0 ; ProcessIndex < RunningProcesses . Num ( ) ; + + ProcessIndex )
{
const FTargetDeviceProcessInfo & ProcessInfo = RunningProcesses [ ProcessIndex ] ;
FDeviceProcessesProcessTreeNodePtr Node = ProcessMap . FindRef ( ProcessInfo . Id ) ;
if ( Node . IsValid ( ) )
{
Node - > ClearChildren ( ) ;
Node - > SetParent ( NULL ) ;
NewProcessMap . Add ( ProcessInfo . Id , Node ) ;
}
else
{
NewProcessMap . Add ( ProcessInfo . Id , MakeShareable ( new FDeviceProcessesProcessTreeNode ( ProcessInfo ) ) ) ;
}
}
ProcessMap = NewProcessMap ;
// build process tree
if ( ShowProcessTree )
{
for ( TMap < uint32 , FDeviceProcessesProcessTreeNodePtr > : : TConstIterator It ( ProcessMap ) ; It ; + + It )
{
FDeviceProcessesProcessTreeNodePtr Node = It . Value ( ) ;
FDeviceProcessesProcessTreeNodePtr Parent = ProcessMap . FindRef ( Node - > GetProcessInfo ( ) . ParentId ) ;
if ( Parent . IsValid ( ) )
{
Node - > SetParent ( Parent ) ;
Parent - > AddChild ( Node ) ;
}
}
}
// filter process list
ProcessList . Reset ( ) ;
for ( TMap < uint32 , FDeviceProcessesProcessTreeNodePtr > : : TConstIterator It ( ProcessMap ) ; It ; + + It )
{
FDeviceProcessesProcessTreeNodePtr Node = It . Value ( ) ;
if ( ! Node - > GetParent ( ) . IsValid ( ) )
{
ProcessList . Add ( Node ) ;
}
}
// refresh list view
ProcessTreeView - > RequestTreeRefresh ( ) ;
2014-09-29 15:56:45 -04:00
LastProcessListRefreshTime = FDateTime : : UtcNow ( ) ;
2014-03-14 14:13:41 -04:00
}
/* SDeviceDetails callbacks
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-04-02 18:09:23 -04:00
FText SDeviceProcesses : : HandleMessageOverlayText ( ) const
{
ITargetDeviceServicePtr DeviceService = Model - > GetSelectedDeviceService ( ) ;
if ( DeviceService . IsValid ( ) )
{
ITargetDevicePtr Device = DeviceService - > GetDevice ( ) ;
if ( Device . IsValid ( ) & & Device - > IsConnected ( ) )
{
if ( Device - > SupportsFeature ( ETargetDeviceFeatures : : ProcessSnapshot ) )
{
return FText : : GetEmpty ( ) ;
}
return LOCTEXT ( " ProcessSnapshotsUnsupportedOverlayText " , " The selected device does not support process snapshots " ) ;
}
return LOCTEXT ( " DeviceUnavailableOverlayText " , " The selected device is currently unavailable " ) ;
}
return LOCTEXT ( " SelectDeviceOverlayText " , " Please select a device from the Device Browser " ) ;
}
EVisibility SDeviceProcesses : : HandleMessageOverlayVisibility ( ) const
{
ITargetDeviceServicePtr DeviceService = Model - > GetSelectedDeviceService ( ) ;
if ( DeviceService . IsValid ( ) )
{
ITargetDevicePtr Device = DeviceService - > GetDevice ( ) ;
if ( Device . IsValid ( ) & & Device - > IsConnected ( ) & & Device - > SupportsFeature ( ETargetDeviceFeatures : : ProcessSnapshot ) )
{
return EVisibility : : Hidden ;
}
}
return EVisibility : : Visible ;
}
2014-03-14 14:13:41 -04:00
void SDeviceProcesses : : HandleModelSelectedDeviceServiceChanged ( )
{
ReloadProcessList ( true ) ;
}
2014-12-10 14:24:09 -05:00
void SDeviceProcesses : : HandleProcessTreeCheckBoxCheckStateChanged ( ECheckBoxState NewState )
2014-03-14 14:13:41 -04:00
{
2014-12-10 14:24:09 -05:00
ShowProcessTree = ( NewState = = ECheckBoxState : : Checked ) ;
2014-03-14 14:13:41 -04:00
ReloadProcessList ( false ) ;
}
2014-12-10 14:24:09 -05:00
ECheckBoxState SDeviceProcesses : : HandleProcessTreeCheckBoxIsChecked ( ) const
2014-03-14 14:13:41 -04:00
{
if ( ShowProcessTree )
{
2014-12-10 14:24:09 -05:00
return ECheckBoxState : : Checked ;
2014-03-14 14:13:41 -04:00
}
2014-12-10 14:24:09 -05:00
return ECheckBoxState : : Unchecked ;
2014-03-14 14:13:41 -04:00
}
TSharedRef < ITableRow > SDeviceProcesses : : HandleProcessTreeViewGenerateRow ( FDeviceProcessesProcessTreeNodePtr Item , const TSharedRef < STableViewBase > & OwnerTable )
{
return SNew ( SDeviceProcessesProcessListRow , OwnerTable )
. Node ( Item ) ;
}
void SDeviceProcesses : : HandleProcessTreeViewGetChildren ( FDeviceProcessesProcessTreeNodePtr Item , TArray < FDeviceProcessesProcessTreeNodePtr > & OutChildren )
{
if ( Item . IsValid ( ) )
{
OutChildren = Item - > GetChildren ( ) ;
}
}
bool SDeviceProcesses : : HandleProcessesBoxIsEnabled ( ) const
{
ITargetDeviceServicePtr DeviceService = Model - > GetSelectedDeviceService ( ) ;
2014-04-02 18:09:23 -04:00
if ( DeviceService . IsValid ( ) )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
ITargetDevicePtr Device = DeviceService - > GetDevice ( ) ;
return ( Device . IsValid ( ) & & Device - > IsConnected ( ) & & Device - > SupportsFeature ( ETargetDeviceFeatures : : ProcessSnapshot ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-04-02 18:09:23 -04:00
return false ;
2014-03-14 14:13:41 -04:00
}
bool SDeviceProcesses : : HandleTerminateProcessButtonIsEnabled ( ) const
{
return ( ProcessTreeView - > GetNumItemsSelected ( ) > 0 ) ;
}
FReply SDeviceProcesses : : HandleTerminateProcessButtonClicked ( )
{
ITargetDeviceServicePtr DeviceService = Model - > GetSelectedDeviceService ( ) ;
if ( DeviceService . IsValid ( ) )
{
if ( FMessageDialog : : Open ( EAppMsgType : : OkCancel , LOCTEXT ( " TerminateProcessWarning " , " Warning: If you terminate a process that is associated with a game or an application, you willl lose any unsaved data. If you end a system process, it might result in an unstable system. " ) ) = = EAppReturnType : : Ok )
{
TArray < FDeviceProcessesProcessTreeNodePtr > FailedProcesses ;
TArray < FDeviceProcessesProcessTreeNodePtr > SelectedProcesses = ProcessTreeView - > GetSelectedItems ( ) ;
for ( int32 ProcessIndex = 0 ; ProcessIndex < SelectedProcesses . Num ( ) ; + + ProcessIndex )
{
ITargetDevicePtr TargetDevice = DeviceService - > GetDevice ( ) ;
if ( TargetDevice . IsValid ( ) )
{
const FDeviceProcessesProcessTreeNodePtr & Process = SelectedProcesses [ ProcessIndex ] ;
if ( ! TargetDevice - > TerminateProcess ( Process - > GetProcessInfo ( ) . Id ) )
{
FailedProcesses . Add ( Process ) ;
}
}
}
if ( FailedProcesses . Num ( ) > 0 )
{
FString ProcessInfo ;
for ( int32 FailedProcessIndex = 0 ; FailedProcessIndex < FailedProcesses . Num ( ) ; + + FailedProcessIndex )
{
const FTargetDeviceProcessInfo & FailedProcessInfo = FailedProcesses [ FailedProcessIndex ] - > GetProcessInfo ( ) ;
ProcessInfo + = FString : : Printf ( TEXT ( " %s (PID: %d) \n " ) , * FailedProcessInfo . Name , FailedProcessInfo . Id ) ;
}
const FText ErrorMessage = FText : : Format ( LOCTEXT ( " FailedToTerminateProcessesMessage " , " The following processes could not be terminated. \n You may not have the required permissions: \n \n {0} " ) , FText : : FromString ( ProcessInfo ) ) ;
FMessageDialog : : Open ( EAppMsgType : : Ok , ErrorMessage ) ;
}
}
}
return FReply : : Handled ( ) ;
}
# undef LOCTEXT_NAMESPACE