Reverted r39451. Instead introduced new class ActiveProcessInfo and added

method GetActiveProcessInfo() to Shell and TermView to get such an info for
the current foreground process group leader. Currently the info only contains
the ID, name, and current directory of the process.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39455 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2010-11-16 19:47:46 +00:00
parent 698fcd85da
commit b27862d236
7 changed files with 148 additions and 17 deletions

View File

@ -0,0 +1,38 @@
/*
* Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "ActiveProcessInfo.h"
ActiveProcessInfo::ActiveProcessInfo()
:
fID(-1),
fShellID(-1),
fName(),
fCurrentDirectory()
{
}
void
ActiveProcessInfo::SetTo(pid_t id, pid_t shellID, const BString& name,
const BString& currentDirectory)
{
fID = id;
fShellID = shellID;
fName = name;
fCurrentDirectory = currentDirectory;
}
void
ActiveProcessInfo::Unset()
{
fID = -1;
fShellID = -1;
fName = BString();
fCurrentDirectory = BString();
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef ACTIVE_PROCESS_INFO_H
#define ACTIVE_PROCESS_INFO_H
#include <OS.h>
#include <String.h>
class ActiveProcessInfo {
public:
ActiveProcessInfo();
void SetTo(pid_t id, pid_t shellID,
const BString& name,
const BString& currentDirectory);
void Unset();
bool IsValid() const { return fID >= 0; }
pid_t ID() const { return fID; }
pid_t ShellProcessID() const { return fShellID; }
const BString& Name() const { return fName; }
const BString& CurrentDirectory() const
{ return fCurrentDirectory; }
private:
pid_t fID;
pid_t fShellID;
BString fName;
BString fCurrentDirectory;
};
#endif // ACTIVE_PROCESS_INFO_H

View File

@ -4,7 +4,10 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UseHeaders [ FDirName $(HAIKU_TOP) src kits tracker ] ; UseHeaders [ FDirName $(HAIKU_TOP) src kits tracker ] ;
UsePrivateHeaders libroot kernel system ;
Application Terminal : Application Terminal :
ActiveProcessInfo.cpp
AppearPrefView.cpp AppearPrefView.cpp
Arguments.cpp Arguments.cpp
BasicTerminalBuffer.cpp BasicTerminalBuffer.cpp

View File

@ -29,9 +29,17 @@
#include <unistd.h> #include <unistd.h>
#include <Catalog.h> #include <Catalog.h>
#include <OS.h> #include <Entry.h>
#include <Locale.h> #include <Locale.h>
#include <OS.h>
#include <Path.h>
#include <util/KMessage.h>
#include <extended_system_info.h>
#include <extended_system_info_defs.h>
#include "ActiveProcessInfo.h"
#include "TermConst.h" #include "TermConst.h"
#include "TermParse.h" #include "TermParse.h"
#include "TerminalBuffer.h" #include "TerminalBuffer.h"
@ -231,13 +239,6 @@ Shell::FD() const
} }
pid_t
Shell::ActiveProcessGroup() const
{
return tcgetpgrp(fFd);
}
bool bool
Shell::HasActiveProcesses() const Shell::HasActiveProcesses() const
{ {
@ -249,6 +250,45 @@ Shell::HasActiveProcesses() const
} }
bool
Shell::GetActiveProcessInfo(ActiveProcessInfo& _info) const
{
_info.Unset();
// get the foreground process group
pid_t process = tcgetpgrp(fFd);
if (process < 0)
return false;
// get more info on the process group leader
KMessage info;
status_t error = get_extended_team_info(process, B_TEAM_INFO_BASIC, info);
if (error != B_OK)
return false;
// fetch the name and the current directory from the info
const char* name;
int32 cwdDevice;
int64 cwdDirectory;
if (info.FindString("name", &name) != B_OK
|| info.FindInt32("cwd device", &cwdDevice) != B_OK
|| info.FindInt64("cwd directory", &cwdDirectory) != B_OK) {
return false;
}
// convert the node ref into a path
entry_ref cwdRef(cwdDevice, cwdDirectory, ".");
BPath cwdPath;
if (cwdPath.SetTo(&cwdRef) != B_OK)
return false;
// set the result
_info.SetTo(process, fProcessID, name, cwdPath.Path());
return true;
}
status_t status_t
Shell::AttachBuffer(TerminalBuffer *buffer) Shell::AttachBuffer(TerminalBuffer *buffer)
{ {

View File

@ -17,6 +17,7 @@
#include <SupportDefs.h> #include <SupportDefs.h>
class ActiveProcessInfo;
// TODO: Maybe merge TermParse and Shell classes ? // TODO: Maybe merge TermParse and Shell classes ?
class TerminalBuffer; class TerminalBuffer;
class TermParse; class TermParse;
@ -44,8 +45,9 @@ public:
int FD() const; int FD() const;
pid_t ProcessID() const { return fProcessID; } pid_t ProcessID() const { return fProcessID; }
pid_t ActiveProcessGroup() const;
bool HasActiveProcesses() const; bool HasActiveProcesses() const;
bool GetActiveProcessInfo(
ActiveProcessInfo& _info) const;
virtual status_t AttachBuffer(TerminalBuffer* buffer); virtual status_t AttachBuffer(TerminalBuffer* buffer);
virtual void DetachBuffer(); virtual void DetachBuffer();

View File

@ -24,6 +24,7 @@
#include <algorithm> #include <algorithm>
#include <new> #include <new>
#include "ActiveProcessInfo.h"
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Beep.h> #include <Beep.h>
@ -628,13 +629,6 @@ TermView::~TermView()
} }
pid_t
TermView::ActiveProcessGroup() const
{
return fShell != NULL ? fShell->ActiveProcessGroup() : -1;
}
bool bool
TermView::IsShellBusy() const TermView::IsShellBusy() const
{ {
@ -642,6 +636,18 @@ TermView::IsShellBusy() const
} }
bool
TermView::GetActiveProcessInfo(ActiveProcessInfo& _info) const
{
if (fShell == NULL) {
_info.Unset();
return false;
}
return fShell->GetActiveProcessInfo(_info);
}
/* static */ /* static */
BArchivable * BArchivable *
TermView::Instantiate(BMessage* data) TermView::Instantiate(BMessage* data)

View File

@ -19,6 +19,7 @@
#include "TermPos.h" #include "TermPos.h"
class ActiveProcessInfo;
class BClipboard; class BClipboard;
class BMessageRunner; class BMessageRunner;
class BScrollBar; class BScrollBar;
@ -46,8 +47,9 @@ public:
virtual void GetPreferredSize(float* _width, float* _height); virtual void GetPreferredSize(float* _width, float* _height);
pid_t ActiveProcessGroup() const;
bool IsShellBusy() const; bool IsShellBusy() const;
bool GetActiveProcessInfo(
ActiveProcessInfo& _info) const;
const char* TerminalName() const; const char* TerminalName() const;