PTLib
Version 2.14.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
pprocess.h
Go to the documentation of this file.
1
/*
2
* pprocess.h
3
*
4
* Operating System Process (running program executable) class.
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23
*
24
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25
* All Rights Reserved.
26
*
27
* Contributor(s): ______________________________________.
28
*
29
* $Revision: 31907 $
30
* $Author: rjongbloed $
31
* $Date: 2014-05-16 16:54:39 +1000 (Fri, 16 May 2014) $
32
*/
33
34
#ifndef PTLIB_PROCESS_H
35
#define PTLIB_PROCESS_H
36
37
#ifdef P_USE_PRAGMA
38
#pragma interface
39
#endif
40
41
#include <
ptlib/mutex.h
>
42
#include <
ptlib/syncpoint.h
>
43
#include <
ptlib/thread.h
>
44
#include <
ptlib/pfactory.h
>
45
46
53
#ifdef P_VXWORKS
54
#define PCREATE_PROCESS(cls) \
55
cls instance; \
56
instance.InternalMain();
57
#elif defined(P_RTEMS)
58
#define PCREATE_PROCESS(cls) \
59
extern "C" {\
60
void* POSIX_Init( void* argument) \
61
{ \
62
static cls instance; \
63
exit( instance.InternalMain() ); \
64
} \
65
}
66
#elif defined(_WIN32_WCE)
67
#define PCREATE_PROCESS(cls) \
68
PDEFINE_WINMAIN(hInstance, , lpCmdLine, ) \
69
{ \
70
cls *pInstance = new cls(); \
71
pInstance->GetArguments().SetArgs(lpCmdLine); \
72
int terminationValue = pInstance->InternalMain(hInstance); \
73
delete pInstance; \
74
return terminationValue; \
75
}
76
#else
77
#define PCREATE_PROCESS(cls) \
78
int main(int argc, char * argv[]) \
79
{ \
80
cls *pInstance = new cls(); \
81
pInstance->PreInitialise(argc, argv); \
82
int terminationValue = pInstance->InternalMain(); \
83
delete pInstance; \
84
return terminationValue; \
85
}
86
#endif // P_VXWORKS
87
88
/*$MACRO PDECLARE_PROCESS(cls,ancestor,manuf,name,major,minor,status,build)
89
This macro is used to declare the components necessary for a user PWLib
90
process. This will declare the PProcess descendent class, eg PApplication,
91
and create an instance of the class. See the <code>PCREATE_PROCESS</code> macro
92
for more details.
93
*/
94
#define PDECLARE_PROCESS(cls,ancestor,manuf,name,major,minor,status,build) \
95
class cls : public ancestor { \
96
PCLASSINFO(cls, ancestor); \
97
public: \
98
cls() : ancestor(manuf, name, major, minor, status, build) { } \
99
private: \
100
virtual void Main(); \
101
};
102
104
// PProcess
105
118
class
PProcess
:
public
PThread
119
{
120
PCLASSINFO(
PProcess
,
PThread
);
121
122
public
:
125
126
enum
CodeStatus
{
128
AlphaCode
,
130
BetaCode
,
132
ReleaseCode
,
133
NumCodeStatuses
134
};
135
138
PProcess
(
139
const
char
* manuf =
""
,
140
const
char
* name =
""
,
141
unsigned
majorVersion
= 1,
142
unsigned
minorVersion
= 0,
143
CodeStatus
status
=
ReleaseCode
,
144
unsigned
buildNumber
= 1,
145
bool
library =
false
,
146
bool
suppressStartup =
false
147
);
149
158
Comparison
Compare
(
159
const
PObject
& obj
160
)
const
;
162
167
virtual
void
Terminate
();
169
178
static
PProcess
&
Current
();
179
182
void
Startup
();
183
187
virtual
void
OnThreadStart
(
188
PThread
& thread
189
);
190
194
virtual
void
OnThreadEnded
(
195
PThread
& thread
196
);
197
210
virtual
bool
OnInterrupt
(
211
bool
terminating
212
);
213
220
static
PBoolean
IsInitialised
();
221
228
void
SetTerminationValue
(
229
int
value
230
);
231
241
int
GetTerminationValue
()
const
;
242
249
PArgList
&
GetArguments
();
250
260
virtual
const
PString
&
GetManufacturer
()
const
;
261
271
virtual
const
PString
&
GetName
()
const
;
272
287
virtual
PString
GetVersion
(
288
PBoolean
full =
true
289
)
const
;
290
296
const
PFilePath
&
GetFile
()
const
;
297
305
PProcessIdentifier
GetProcessID
()
const
{
return
m_processID
; }
306
314
static
PProcessIdentifier
GetCurrentProcessID
();
315
318
PTime
GetStartTime
()
const
;
319
328
PString
GetUserName
()
const
;
329
352
PBoolean
SetUserName
(
353
const
PString
& username,
354
PBoolean
permanent =
false
355
);
356
361
PDirectory
GetHomeDirectory
()
const
;
362
371
PString
GetGroupName
()
const
;
372
397
PBoolean
SetGroupName
(
398
const
PString
& groupname,
399
PBoolean
permanent =
false
400
);
401
408
int
GetMaxHandles
()
const
;
409
419
PBoolean
SetMaxHandles
(
420
int
newLimit
421
);
422
423
#if P_CONFIG_FILE
424
426
virtual
PString
GetConfigurationFile
();
427
442
void
SetConfigurationPath
(
443
const
PString
& path
444
);
445
#endif // P_CONFIG_FILE
446
447
456
static
PString
GetOSClass
();
457
464
static
PString
GetOSName
();
465
471
static
PString
GetOSHardware
();
472
479
static
PString
GetOSVersion
();
480
486
static
bool
IsOSVersion
(
487
unsigned
major,
488
unsigned
minor = 0,
489
unsigned
build = 0
490
);
491
499
static
PDirectory
GetOSConfigDir
();
500
507
static
PString
GetLibVersion
();
509
513
void
PreInitialise
(
514
int
argc,
// Number of program arguments.
515
char
** argv
// Array of strings for program arguments.
516
);
517
521
void
PreShutdown
();
522
static
void
PostShutdown
();
523
525
virtual
int
InternalMain
(
void
* arg = NULL);
526
548
class
HostSystemURLHandlerInfo
549
{
550
public
:
551
HostSystemURLHandlerInfo
()
552
{ }
553
554
HostSystemURLHandlerInfo
(
const
PString
& t)
555
:
type
(t)
556
{ }
557
558
static
bool
RegisterTypes
(
const
PString
& types,
bool
force =
true
);
559
560
void
SetIcon
(
const
PString
& icon);
561
PString
GetIcon
()
const
;
562
563
void
SetCommand
(
const
PString
& key,
const
PString
& command);
564
PString
GetCommand
(
const
PString
& key)
const
;
565
566
bool
GetFromSystem
();
567
bool
CheckIfRegistered
();
568
569
bool
Register
();
570
571
PString
type
;
572
573
#if _WIN32
574
PString
iconFileName;
575
PStringToString
cmds;
576
#endif
577
};
579
580
PThread
*
GetThread
(PThreadIdentifier threadId)
const
;
581
bool
SignalTimerChange
();
582
583
protected
:
584
void
Construct
();
585
586
// Member variables
587
bool
m_library
;
// Indication PTLib is being used as a library for an external process.
588
int
terminationValue
;
// Application return value
589
590
PString
manufacturer
;
// Application manufacturer name.
591
PString
productName
;
// Application executable base name from argv[0]
592
593
unsigned
majorVersion
;
// Major version number of the product
594
unsigned
minorVersion
;
// Minor version number of the product
595
CodeStatus
status
;
// Development status of the product
596
unsigned
buildNumber
;
// Build number of the product
597
598
PFilePath
executableFile
;
// Application executable file from argv[0] (not open)
599
PStringArray
configurationPaths
;
// Explicit file or set of directories to find default PConfig
600
PArgList
arguments
;
// The list of arguments
601
int
maxHandles
;
// Maximum number of file handles process can open.
602
603
PTime
programStartTime
;
// time at which process was intantiated, i.e. started
604
605
bool
m_shuttingDown
;
606
PMutex
m_threadMutex
;
607
608
typedef
std::map<PThreadIdentifier, PThread *>
ThreadMap
;
609
ThreadMap
m_activeThreads
;
610
void
InternalThreadStarted
(
PThread
* thread);
611
void
InternalThreadEnded
(
PThread
* thread);
612
613
typedef
PList<PThread>
ThreadList
;
614
ThreadList
m_autoDeleteThreads
;
615
void
InternalSetAutoDeleteThread
(
PThread
* thread);
616
void
InternalCleanAutoDeleteThreads
();
617
618
PAtomicBoolean
m_keepingHouse
;
619
PThread
*
m_houseKeeper
;
// Thread for doing timers, thread clean up etc.
620
PSyncPoint
m_signalHouseKeeper
;
621
void
HouseKeeping
();
622
623
PTimer::List
*
m_timerList
;
624
friend
PTimer::List
*
PTimer::TimerList
();
625
626
PProcessIdentifier
m_processID
;
627
628
friend
class
PThread
;
629
630
631
// Include platform dependent part of class
632
#ifdef _WIN32
633
#include "msos/ptlib/pprocess.h"
634
#else
635
#include "unix/ptlib/pprocess.h"
636
#endif
637
};
638
639
642
class
PLibraryProcess
:
public
PProcess
643
{
644
PCLASSINFO(
PLibraryProcess
,
PProcess
);
645
646
public
:
651
PLibraryProcess
(
652
const
char
* manuf =
""
,
653
const
char
* name =
""
,
654
unsigned
majorVersionNum = 1,
655
unsigned
minorVersionNum = 0,
656
CodeStatus
statusCode =
ReleaseCode
,
657
unsigned
buildNum = 1,
658
bool
suppressStartup =
false
659
) :
PProcess
(manuf, name, majorVersionNum, minorVersionNum, statusCode, buildNum, true, suppressStartup) { }
661
663
virtual
void
Main
() { }
664
};
665
666
667
/*
668
* one instance of this class (or any descendants) will be instantiated
669
* via PGenericFactory<PProessStartup> one "main" has been started, and then
670
* the OnStartup() function will be called. The OnShutdown function will
671
* be called after main exits, and the instances will be destroyed if they
672
* are not singletons
673
*/
674
class
PProcessStartup
:
public
PObject
675
{
676
PCLASSINFO
(
PProcessStartup
,
PObject
)
677
public
:
678
virtual
void
OnStartup
() { }
679
virtual
void
OnShutdown
() { }
680
};
681
682
typedef
PFactory<PProcessStartup>
PProcessStartupFactory
;
683
684
#if PTRACING
685
686
// using an inline definition rather than a #define crashes gcc 2.95. Go figure
687
#define P_DEFAULT_TRACE_OPTIONS ( PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine )
688
689
template
<
unsigned
level,
unsigned
options = P_DEFAULT_TRACE_OPTIONS >
690
class
PTraceLevelSetStartup :
public
PProcessStartup
691
{
692
public
:
693
void
OnStartup
()
694
{
PTrace::Initialise
(level, NULL, options); }
695
};
696
697
#endif // PTRACING
698
699
700
#endif // PTLIB_PROCESS_H
701
702
703
// End Of File ///////////////////////////////////////////////////////////////
include
ptlib
pprocess.h
Generated on Fri Oct 10 2014 21:15:13 for PTLib by
1.8.3.1