libs-gsweb/GSWeb.framework/GSWProcFS.m
Dave Wetzel 0c43a77fd2 * GSWExtensionsGSW.framework/GSWFileUploadComponent.m
* GSWExtensionsGSW.framework/GSWLogin.m
	removed logs
	* GSWExtensionsGSW.framework/GNUmakefile
	added ADDITIONAL_OBJCFLAGS = -Werror-implicit-function-declaration
	* GSWExtensionsGSW.framework/GSWCacheElement.m
	removed logs, use object_getClassName
	* GSWExtensionsGSW.framework/GSWValidationFailureComponent.m
	* GSWExtensionsGSW.framework/GSWTabComponent.m
	* GSWExtensionsGSW.framework/GSWFileUploadFormComponent.m
	* GSWExtensionsGSW.framework/GSWSimpleFormComponent.m
	* GSWeb.framework/GSWApplication.m
	removed logs, _validateAPI
	ClassIsKindOfClass -> GSObjCIsKindOf
	* GSWeb.framework/GSWAction.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	removed logs and unused (commented) code
	* GSWeb.framework/GSWResourceManager.h
	removed _validateAPI
	* GSWeb.framework/GSWImageButton.m
	added #include <GNUstepBase/NSObject+GNUstepBase.h>
	removed logs and unused (commented) code
	* GSWeb.framework/NSString+HTML.h
	changed int to NSUInteger / NSInteger
	* GSWeb.framework/GSWResourceManager.m
	removed logs, _validateAPI
	* GSWeb.framework/GSWContext.m 
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWRequestHandler.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/NSString+HTML.m
	include <GNUstepBase/NSString+GNUstepBase.h>
	changed int to NSUInteger
	use memmove in GSWMemMove macro
	disabled testStringByConvertingHTML
	removed logs
	fixed warnings
	* GSWeb.framework/GSWMultiKeyDictionary.m
	removed logs
	* GSWeb.framework/GSWVBScript.m
	removed logs
	* GSWeb.framework/NSNonBlockingFileHandle.m
	removed logs
	* GSWeb.framework/GSWStatisticsStore.h
	removed useless @interface / @end for the same class
	* GSWeb.framework/GSWLifebeatThread.m
	removed include <GNUstepBase/GSCategories.h>
	removed logs
	* GSWeb.framework/GSWStatisticsStore.m
	removed logs
	include <GNUstepBase/NSObject+GNUstepBase.h>
	include <GNUstepBase/NSString+GNUstepBase.h>
	implement _purgePathsStatistics, _updatePathsStatisticsWithPaths
	removed useless @implementation / @end for the same class
	* GSWeb.framework/GSWCookie.m
	removed logs
	* GSWeb.framework/GNUmakefile
	added ADDITIONAL_OBJCFLAGS = -Werror-implicit-function-declaration
	* GSWeb.framework/GSWRecording.m
	removed logs
	* GSWeb.framework/GSWToggle.m
	removed logs
	* GSWeb.framework/GSWMessage.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	globalDefaultEncoding = [NSString defaultCStringEncoding];
	(see http://wiki.gnustep.org/index.php/GSWebFAQ )
	use NSUInteger for index
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWDefaultAdaptor.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWJavaScript.m
	* GSWeb.framework/GSWClientSideScript.m
	removed logs
	* GSWeb.framework/GSWNestedList.m
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWEmbeddedObject.m	
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWRequest.h
	removed _validateAPI
	* GSWeb.framework/GSWRequest.m
	add includes
	removed _validateAPI
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWUtils.h
	unsigned int -> NSUInteger
	* GSWeb.framework/Resources/languages.plist
	added languages
	* GSWeb.framework/GSWUtils.m
	add includes
	unsigned int -> NSUInteger
	removed logs
	* GSWeb.framework/GSWComponentReference.m	
	removed logs
	* GSWeb.framework/GSWGeometricRegion.m
	add includes
	removed logs
	* GSWeb.framework/GSWKeyValueAssociation.m
	add includes
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWHiddenField.m
	removed logs
	* GSWeb.framework/GSWParam.m
	add includes
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/NSString+Trimming.h
	* GSWeb.framework/NSString+Trimming.m
	removed longValue, ulongValue, longLongValue;
	removed logs
	* GSWeb.framework/GSWStaticResourceRequestHandler.m
	removed logs
	* GSWeb.framework/GSWURLValuedElementData.m
	removed logs
	* GSWeb.framework/GSWDirectAction.m
	takeValue -> setValue
	removed logs
	int -> NSUInteger
	* GSWeb.framework/GSWComponentDefinition.m
	add includes
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWAssociation.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWSession.h
	* GSWeb.framework/GSWSession.m
	unsigned int-> NSUInteger
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	David Ayers: pls check sleepInContext!
	removed _validateAPI, __setContextCounterIncrementingEnabled, __counterIncrementingEnabledFlag
	* GSWeb.framework/GSWFileUpload.m
	removed logs
	* GSWeb.framework/GSWApplet.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWGenericElement.m
	removed logs
	GSWeb.framework/GSWTemplateParser.m
	add includes
	* GSWeb.framework/GSWTemporaryElement.m		
	removed logs
	* GSWeb.framework/GSWResponse.m
	add include
	removed docStructure checks
	removed logs
	* GSWeb.framework/GSWProjectBundle.m
	add include
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWWorkerThread.m
	added - drain
	removed NSLog
	* GSWeb.framework/GSWApplication+Defaults.m
	add include			
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWActiveImage.m
	* GSWeb.framework/GSWDirectActionRequestHandler.m
	* GSWeb.framework/GSWConstantValueAssociation.m
	* GSWeb.framework/NSData+Compress.m
	removed logs
	* GSWeb.framework/GSWHTMLStaticElement.m	
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWServerSessionStore.m
	removed logs
	* GSWeb.framework/GSWAdaptor.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWDeployedBundle.m
	removed logs
	add includes
	* GSWeb.framework/GSWSubmitButton.m
	removed logs
	* GSWeb.framework/GSWDeclarationParser.m
	add includes
	removed logs
	* GSWeb.framework/GSWBundle.m
	add includes
	removed logs
	clearCache
	* GSWeb.framework/GSWWOCompatibility.h
	fixed typo in WOMessage
	* GSWeb.framework/GSWSessionTimeOut.m
	removed logs
	* GSWeb.framework/GSWPopUpButton.m	
	add includes
	* GSWeb.framework/GSWComponent.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWHTTPIO.m
	add include
	* GSWeb.framework/GSWBindingNameAssociation.m
	takeValue -> setValue
	* GSWeb.framework/GSWHTMLTemplateParser.m
	removed logs
	* GSWeb.framework/GSWResetButton.m
	removed logs
	* GSWeb.framework/GSWDebug.h/m
	disabled log funtions
	* GSWeb.framework/GSWActionRequestHandler.m
	add includes
	removed logs
	* GSWeb.framework/GSWSwitchComponent.m
	* GSWeb.framework/GSWSessionTimeOutManager.m
	removed logs
	* GSWeb.framework/GSWMailDelivery.m
	add includes
	removed logs
	* GSWeb.framework/GSWDynamicURLString.h
	* GSWeb.framework/GSWDynamicURLString.m
	unsigned int -> NSUInteger
	removed checkURL
	add includes
	* GSWeb.framework/GSWProcFS.m		
	removed logs
	* GSWeb.framework/GSWApplication.h
	removed _validateAPI
	* GSWeb.framework/GSWResourceRequestHandler.m
	add include
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWSessionStore.h
	removed _validateAPI
	* GSWeb.framework/GSWSessionStore.m
	add include
	removed _validateAPI
	removed logs
	* GSWExtensions.framework/GSWLongResponsePage.m
	* GSWExtensions.framework/GSWExceptionPage.m
	* GSWExtensions.framework/GSWMetaRefresh.m
	* GSWExtensions.framework/GSWCollapsibleComponentContent.m
	removed logs
	* GSWExtensions.framework/GNUmakefile
	added ADDITIONAL_OBJCFLAGS = -Werror-implicit-function-declaration
	* GSWExtensions.framework/GSWStatsPage.m
	removed logs
	unsigned int -> NSUInteger
	* Examples/hello/HelloPage.wo/HelloPage.html
	* Examples/hello/Main.wo/Main.html
	* Examples/hello/Hello.m
	convert to UTF8
	
	The change of
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	will show where we need to implement functionality.
	Please send bug reports! -- dw



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30584 72102866-910b-0410-8b05-ffd578937521
2010-06-05 21:08:12 +00:00

406 lines
12 KiB
Objective-C

/** GSWProcFS.m - <title>GSWeb: Class GSWApplication</title>
Copyright (C) 1999-2003 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Oct 1999
$Revision$
$Date$
$Id$
This file is part of the GNUstep Web Library.
<abstract>
/proc management
</abstract>
<license>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
</license>
**/
#include "config.h"
RCS_ID("$Id$")
#include "GSWeb.h"
NSString* formattedByteSizeValue(unsigned int value)
{
if (value<1024)
return [NSString stringWithFormat:@"%lu b",value];
else if (value<1024L*1024L)
return [NSString stringWithFormat:@"%.3f Kb",
(((double)value)/1024)];
else if (value<1024L*1024L*1024L)
return [NSString stringWithFormat:@"%.3f Mb",
(((double)value)/(1024L*1024L))];
else
return [NSString stringWithFormat:@"%.3f Gb",
(((double)value)/(1024L*1024L*1024L))];
};
@implementation GSWProcFSProcInfo
+ (GSWProcFSProcInfo *)filledProcInfo
{
int processID = [[NSProcessInfo processInfo] processIdentifier];
return [self filledProcInfoWithPID: processID];
}
+ (GSWProcFSProcInfo *)filledProcInfoWithPID: (int)processID
{
GSWProcFSProcInfo *obj
= AUTORELEASE([[self alloc] initFilledWithPID: processID]);
return obj;
}
- (id)initFilledWithPID: (int)processID
{
if ((self = [super init]))
{
_pid = processID;
[self fill];
};
return self;
}
-(void)dealloc
{
DESTROY(_user);
DESTROY(_command);
DESTROY(_ttyc);
DESTROY(_environ);
DESTROY(_commandLine);
[super dealloc];
};
-(NSString*)description
{
NSString* dscr=nil;
unsigned int pageSize=NSPageSize();
char* stateCString=NULL;
switch(_state)
{
case GSWProcState__Sleeping:
stateCString="Sleeping";
break;
case GSWProcState__Running:
stateCString="Running";
break;
case GSWProcState__Zombie:
stateCString="Zombie";
break;
case GSWProcState__Stopped:
stateCString="Stopped";
break;
case GSWProcState__SleepWait:
stateCString="Waiting-Sleeping";
break;
case GSWProcState__Unknown:
default:
stateCString="Unknown";
break;
};
dscr=[NSString stringWithFormat:@"user: %@\ncmd: %@\nState: %s\nttyc: %@\nenviron: %@\ncommand line:%@\n",
_user,
_command,
stateCString,
_ttyc,
_environ,
_commandLine];
dscr=[dscr stringByAppendingFormat:@"uid: %d\npid: %d\nppid: %d\npgrp: %d\nsession: %d\ntty: %d\ntpgid: %d\npriority: %d\nnice: %d\nsignal: %LX\nblocked: %LX\nsigIgnore: %LX\nsigCache: %LX\n",
_uid,
_pid,
_ppid,
_pgrp,
_session,
_tty,
_tpgid,
_priority,
_nice,
_signal,
_blocked,
_sigIgnore,
_sigCatch];
dscr=[dscr stringByAppendingFormat:@"startTime: %@\nuserTime: %f\nsystemTime: %f\ncumulativeUserTime: %f\ncumulativeSystemTime: %f\n",
[NSDate dateWithTimeIntervalSinceReferenceDate:_startTime],
_userTime,
_systemTime,
_cumulativeUserTime,
_cumulativeSystemTime];
dscr=[dscr stringByAppendingFormat:@"pagesNb=%ld (size: %@)\nresidentPagesNb: %ld (size: %@)\nsharedPagesNb: %ld (size: %@)\ntextResidentSize: %@\nsharedLibResidentSize: %@\ndataResidentSize: %@\ndirtyPagesNb: %ld\n",
_pagesNb,
formattedByteSizeValue(_pagesNb*pageSize),
_residentPagesNb,
formattedByteSizeValue(_residentPagesNb*pageSize),
_sharedPagesNb,
formattedByteSizeValue(_sharedPagesNb*pageSize),
formattedByteSizeValue(_textResidentSize),
formattedByteSizeValue(_sharedLibResidentSize),
formattedByteSizeValue(_dataResidentSize),
_dirtyPagesNb];
dscr=[dscr stringByAppendingFormat:@"cpuUsage: %u%%\nvirtualMemorySize: %@\nresidentMemorySize: %@\nresidentMemorySizeLimit: %@\ntimeout: %lu\nit_real_value: %lu\n",
_cpuUsagePC,
formattedByteSizeValue(_virtualMemorySize),
formattedByteSizeValue(_residentMemorySize),
formattedByteSizeValue(_residentMemorySizeLimit),
_timeout,
_it_real_value];
/* unsigned long flags,
unsigned long minorPageFaultNb,
unsigned long majorPageFaultNb,
unsigned long cumulativeMinorPageFaultNb,
unsigned long cumulativeMajorPageFaultNb,
unsigned long startCodeAddress,
unsigned long endCodeAddress,
unsigned long startStackAddress,
unsigned long kernelStackPointerESP,
unsigned long kernelStackPointerEIP,
unsigned long kernelWaitChannelProc,
*/
return dscr;
};
-(BOOL)fill
{
//TODO
[self fillStat];
[self fillStatm];
return YES;
};
+ (NSString *)contentOfProcFile: (NSString *)procFile
{
NSString *path;
NSString *content;
path = [NSString stringWithFormat: @"/proc/%@", procFile];
content = [NSString stringWithContentsOfFile: path];
if ([content length] == 0)
{
//LOGSeriousError(@"Read (%@) attempt failed", path);
}
return content;
}
-(NSString*)contentOfPIDFile:(NSString*)pidFile
{
NSString* content=nil;
NSString* path
= [NSString stringWithFormat:@"%d/%@",
(_pid ? _pid
: [[NSProcessInfo processInfo] processIdentifier]),
pidFile];
content=[[self class] contentOfProcFile: path];
return content;
};
-(BOOL)fillStatm
{
BOOL ok=NO;
NSString* pidstat=[self contentOfPIDFile:@"statm"];
if (pidstat)
{
const char* statsChars=[pidstat cString];
if (sscanf(statsChars, "%ld %ld %ld %ld %ld %ld %ld",
&_pagesNb,//size
&_residentPagesNb,//resident
&_sharedPagesNb,//share
&_textResidentSize, //trs
&_sharedLibResidentSize,//lrs
&_dataResidentSize,//drs
&_dirtyPagesNb//dt
)==7)
ok=YES;
};
return ok;
};
-(BOOL)fillStat
{
BOOL ok=NO;
NSString* pidstat = [self contentOfPIDFile: @"stat"];
if (pidstat)
{
NSRange cmdEnd=[pidstat rangeOfString:@") "];
if (cmdEnd.length>0)
{
NSString* pid_cmd=[pidstat substringToIndex:cmdEnd.location];
if (cmdEnd.location+cmdEnd.length<[pidstat length])
{
NSString* stats=[pidstat substringFromIndex:cmdEnd.location+cmdEnd.length];
/*
char* tmp = strrchr(S, ')'); // split into "PID (cmd" and "<rest>"
*tmp = '\0'; // replace trailing ')' with NUL
// parse these two strings separately, skipping the leading "(".
memset(P->cmd, 0, sizeof P->cmd); // clear even though *P xcalloc'd ?!
sscanf(S, "%d (%39c", &P->pid, P->cmd);
*/
const char* statsChars=[stats cString];
char cState;
long utime;
long stime;
long cutime;
long cstime;
long startTime;
if (sscanf(statsChars,
"%c %d %d %d %d %d %lu %lu %lu %lu %lu %ld %ld %ld %ld %d "
"%d %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %LX %LX %LX %LX %lu",
&cState, //state
&_ppid,//ppid
&_pgrp,//pgrp
&_session,//session
&_tty,//tty
&_tpgid,//tpgid,
&_flags,//flags
&_minorPageFaultNb,//min_flt
&_cumulativeMinorPageFaultNb,//cmin_flt
&_majorPageFaultNb,//maj_flt
&_cumulativeMajorPageFaultNb,//cmaj_flt,
&utime,//utime
&stime,//stime
&cutime,//cutime
&cstime,//cstime
&_priority,//priority
&_nice,//nice,
&_timeout,//timeout
&_it_real_value,//it_real_value
&startTime,//start_time
&_virtualMemorySize,//vsize
&_residentMemorySize,//rss,
&_residentMemorySizeLimit,//rss_rlim
&_startCodeAddress,//start_code
&_endCodeAddress,//end_code
&_startStackAddress,//start_stack,
&_kernelStackPointerESP,//kstk_esp
&_kernelStackPointerEIP,//kstk_eip
&_signal,//signal
&_blocked,//blocked
&_sigIgnore,//sigignore,
&_sigCatch,//sigcatch
&_kernelWaitChannelProc//wchan
)==33)
{
ok=YES;
switch(cState)
{
case 'S':
_state=GSWProcState__Sleeping;
break;
case 'R':
_state=GSWProcState__Running;
break;
case 'Z':
_state=GSWProcState__Zombie;
break;
case 'T':
_state=GSWProcState__Stopped;
break;
case 'D':
_state=GSWProcState__SleepWait;
break;
default:
_state=GSWProcState__Unknown;
break;
};
_userTime=utime;
_systemTime=stime;
_cumulativeUserTime=cutime;
_cumulativeSystemTime=cstime;
startTime=[[NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)_startTime]timeIntervalSinceReferenceDate];
if (_tty == 0)
_tty = -1; // the old notty val, update elsewhere bef. moving to 0
/* if (linux_version_code < LINUX_VERSION(1,3,39))
{
P->priority = 2*15 - P->priority; // map old meanings to new
P->nice = 15 - P->nice;
}
if (linux_version_code < LINUX_VERSION(1,1,30) && P->tty != -1)
P->tty = 4*0x100 + P->tty; // when tty wasn't full devno
*/
};
};
};
};
return ok;
};
-(unsigned int)residentMemory
{
unsigned int pageSize=NSPageSize();
return (unsigned int)(_residentPagesNb*pageSize);
};
-(unsigned int)sharedMemory
{
unsigned int pageSize=NSPageSize();
return (unsigned int)(_sharedPagesNb*pageSize);
};
-(unsigned int)virtualMemory
{
return (unsigned int)_virtualMemorySize;
};
-(unsigned int)swapMemory
{
//TODO
return 0;
};
-(unsigned int)usedMemory
{
unsigned int residentMemory=[self residentMemory];
unsigned int sharedMemory=[self sharedMemory];
unsigned int virtualMemory=[self virtualMemory];
return max(residentMemory+sharedMemory,virtualMemory);
};
-(NSString*)formattedResidentMemory
{
return formattedByteSizeValue([self residentMemory]);
};
-(NSString*)formattedSharedMemory
{
return formattedByteSizeValue([self sharedMemory]);
}
-(NSString*)formattedVirtualMemory
{
return formattedByteSizeValue([self virtualMemory]);
}
-(NSString*)formattedSwapMemory
{
return formattedByteSizeValue([self swapMemory]);
}
-(NSString*)formattedUsedMemory
{
return formattedByteSizeValue([self usedMemory]);
}
@end