Skip to content

Commit 2500f28

Browse files
refs #2 (#3)
* refs #2
1 parent 989ea1f commit 2500f28

13 files changed

+445
-56
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
}
2525
},
2626
"require": {
27-
"php": "^7.1.0 <7.4.0",
28-
"ext-win32service": "*"
27+
"php": "^7.1.0 <7.4.0"
2928
},
3029
"require-dev": {
3130
"atoum/atoum": "^3.3"

examples/service.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ class MyTestService extends AbstractServiceRunner
1919
{
2020
/**
2121
* This function is runnning in loop. The running duration is limited to 30 seconds
22+
* @param int $control contains the last control.
2223
* @return void
2324
*/
24-
protected function run(): void
25+
protected function run(int $control): void
2526
{
26-
usleep(500);
27-
trigger_error('Main run', E_USER_NOTICE);
27+
usleep(1000);
28+
//trigger_error('Main run', E_USER_NOTICE);
2829
}
2930

3031
/**
@@ -79,4 +80,4 @@ protected function lastRunIsTooSlow(float $duration): void
7980
$serviceId = ServiceIdentifier::identify('my_test_service', 'localhost');
8081

8182
// init and run the service
82-
(new MyTestService($serviceId))->doRun();
83+
(new MyTestService($serviceId))->doRun(100);

idelib/php_win32service.constants.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
*
3333
* Type of services
3434
*/
35-
define("WIN32_SERVICE_KERNEL_DRIVER", 0x00000001, true); /* 0x00000001 Driver service. */
36-
define("WIN32_SERVICE_FILE_SYSTEM_DRIVER", 0x00000002, true); /* 0x00000002 File system driver service. */
37-
define("WIN32_SERVICE_ADAPTER", 0x00000004, true); /* 0x00000004 Reserved. */
38-
define("WIN32_SERVICE_RECOGNIZER_DRIVER", 0x00000008, true); /* 0x00000008 Reserved. */
35+
//define("WIN32_SERVICE_KERNEL_DRIVER", 0x00000001, true); /* 0x00000001 Driver service. */
36+
//define("WIN32_SERVICE_FILE_SYSTEM_DRIVER", 0x00000002, true); /* 0x00000002 File system driver service. */
37+
//define("WIN32_SERVICE_ADAPTER", 0x00000004, true); /* 0x00000004 Reserved. */
38+
//define("WIN32_SERVICE_RECOGNIZER_DRIVER", 0x00000008, true); /* 0x00000008 Reserved. */
3939
define("WIN32_SERVICE_WIN32_OWN_PROCESS", 0x00000010, true); /* 0x00000010 Service that runs in its own process. */
40-
define("WIN32_SERVICE_WIN32_SHARE_PROCESS", 0x00000020, true); /* 0x00000020 Service that shares a process with one or more other services. */
40+
//define("WIN32_SERVICE_WIN32_SHARE_PROCESS", 0x00000020, true); /* 0x00000020 Service that shares a process with one or more other services. */
4141
define("WIN32_SERVICE_INTERACTIVE_PROCESS", 0x00000100, true); /* 0x00000100 The service can interact with the desktop. */
4242
define("WIN32_SERVICE_WIN32_OWN_PROCESS_INTERACTIVE", 0x00000110, true); /* 0x00000110 Service that runs in its own process and interacts with the desktop. */
4343

@@ -135,15 +135,10 @@
135135
define("WIN32_SERVICE_ERROR_CRITICAL", 0x00000003, true); /* 0x00000003 The startup program logs the error in the event log, if possible.
136136
If the last-known-good configuration is being started, the startup operation fails. Otherwise, the system is restarted with the last-known good configuration. */
137137

138-
139-
140-
141138
/* dwServiceFlags */
142139
define("WIN32_SERVICE_RUNS_IN_SYSTEM_PROCESS", 0x00000001, true); /* 0x00000001 The service runs in a system process that must always be running. */
143140

144141

145-
146-
147142
/* Error constants generated in communication with the SCM */
148143
define("WIN32_ERROR_ACCESS_DENIED", 0x00000005, true); /* 0x00000005 The handle to the SCM database does not have the appropriate access rights. */
149144
define("WIN32_ERROR_CALL_NOT_IMPLEMENTED", 0x00000078, true); /* 0x00000028 This function is not supported. */
@@ -175,6 +170,7 @@
175170
define("WIN32_ERROR_SERVICE_NOT_ACTIVE", 0x00000426, true); /* 0x00000426 The service has not been started. */
176171
define("WIN32_ERROR_SERVICE_REQUEST_TIMEOUT", 0x0000041D, true); /* 0x0000041D The process for the service was started, but it did not call StartServiceCtrlDispatcher, or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function. */
177172
define("WIN32_ERROR_SHUTDOWN_IN_PROGRESS", 0x0000045B, true); /* 0x0000045B The system is shutting down; this function cannot be called. */
173+
define("ERROR_SERVICE_SPECIFIC_ERROR", 0x0000042A, true); /* 0x0000042A The service has returned a service-specific error code. */
178174
define("WIN32_NO_ERROR", 0x00000000, true); /* 0x00000000 No error. */
179175

180176

@@ -187,3 +183,33 @@
187183
define("WIN32_IDLE_PRIORITY_CLASS", 0x00000040, true); /* 0x00000040 Process whose threads run only when the system is idle. The threads of the process are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle-priority class is inherited by child processes. */
188184
define("WIN32_NORMAL_PRIORITY_CLASS", 0x00000020, true); /* 0x00000020 Process with no special scheduling needs. */
189185
define("WIN32_REALTIME_PRIORITY_CLASS", 0x00000100, true); /* 0x00000100 Process that has the highest possible priority. The threads of the process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive. */
186+
187+
/* Win32 Recovery Constants */
188+
define("WIN32_SC_ACTION_NONE", 0x00000000, true); /* 0x00000000 No Action */
189+
define("WIN32_SC_ACTION_REBOOT", 0x00000001, true); /* 0x00000001 Reboot the computer */
190+
define("WIN32_SC_ACTION_RESTART", 0x00000002, true); /* 0x00000002 Restart the service */
191+
define("WIN32_SC_ACTION_RUN_COMMAND", 0x00000003, true); /* 0x00000003 Run the command */
192+
193+
/* Win32 Informations Keys */
194+
define("INFO_SERVICE", "service", true);
195+
define("INFO_DISPLAY", "display", true);
196+
define("INFO_USER", "user", true);
197+
define("INFO_PASSWORD", "password", true);
198+
define("INFO_PATH", "path", true);
199+
define("INFO_PARAMS", "params", true);
200+
define("INFO_DESCRIPTION", "description", true);
201+
define("INFO_START_TYPE", "start_type", true);
202+
define("WIN32_INFO_LOAD_ORDER", "load_order", true);
203+
define("WIN32_INFO_SVC_TYPE", "svc_type", true);
204+
define("WIN32_INFO_ERROR_CONTROL", "error_control", true);
205+
define("WIN32_INFO_DELAYED_START", "delayed_start", true);
206+
define("WIN32_INFO_BASE_PRIORITY", "base_priority", true);
207+
define("WIN32_INFO_DEPENDENCIES", "dependencies", true);
208+
define("WIN32_INFO_RECOVERY_DELAY", "recovery_delay", true);
209+
define("WIN32_INFO_RECOVERY_ACTION_1", "recovery_action_1", true);
210+
define("WIN32_INFO_RECOVERY_ACTION_2", "recovery_action_2", true);
211+
define("WIN32_INFO_RECOVERY_ACTION_3", "recovery_action_3", true);
212+
define("WIN32_INFO_RECOVERY_RESET_PERIOD", "recovery_reset_period", true);
213+
define("WIN32_INFO_RECOVERY_ENABLED", "recovery_enabled", true);
214+
define("WIN32_INFO_RECOVERY_REBOOT_MSG", "recovery_reboot_msg", true);
215+
define("WIN32_INFO_RECOVERY_COMMAND", "recovery_command", true);

idelib/php_win32service.functions.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
/**
2626
* Registers the script with the SCM, so that it can act as the service with the given name.
2727
* @param string $ServiceName Name of the service to represent.
28+
* @param boolean $GracefulExit [optional] Set the exit mode.
2829
* @Return boolean|integer FALSE on success or Error code on failure.
2930
*/
30-
function win32_start_service_ctrl_dispatcher( $ServiceName ) {}
31+
function win32_start_service_ctrl_dispatcher( $ServiceName , $GracefulExit) {}
3132

3233
/**
3334
* Tells SCM the current status of the service.
@@ -98,3 +99,28 @@ function win32_pause_service( $ServiceName , $Machine ) {}
9899
* @Return boolean|integer WIN32_NO_ERROR on success. FALSE or Error code on failure.
99100
*/
100101
function win32_continue_service( $ServiceName , $Machine ) {}
102+
103+
/**
104+
* Sen custom control value to the service.
105+
* @param string $ServiceName Name of the service to query.
106+
* @param integer $Control The control value between 128 and 255
107+
* @param string $Machine [optional] Remote machine to unpause the service on. Probably only works in a Windows Domain.
108+
* @Return boolean|integer WIN32_NO_ERROR on success. FALSE or Error code on failure.
109+
*/
110+
function win32_send_custom_control( $ServiceName , $Control , $Machine ) {}
111+
112+
113+
/**
114+
* Set (or get) the exit code.
115+
* @param integer $ExitCode [optional] The exit code returned on exit
116+
* @return integer Current exit code, or old exit code if $ExitCode is defined
117+
*/
118+
function win32_set_service_exit_code( $ExitCode ) {}
119+
120+
121+
/**
122+
* Get (or set) the exit mode.
123+
* @param boolean $GracefulExit [optional] Set the exit mode.
124+
* @return boolean Current exit mode, or old exit mode if $GrafeFulExit is defined
125+
*/
126+
function win32_set_service_exit_mode( $GracefulExit ) {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* @copy In Extenso (c) 2019
4+
* Added by : cameleon at 14/02/19 08:57
5+
*/
6+
7+
namespace Win32Service\Exception;
8+
9+
10+
class ServiceAlreadyRegistredException extends ServiceRegistrationException
11+
{
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* @copy In Extenso (c) 2019
4+
* Added by : cameleon at 19/02/19 17:18
5+
*/
6+
7+
namespace Win32Service\Exception;
8+
9+
10+
class ServiceMarkedForDeleteException extends ServiceUnregistrationException
11+
{
12+
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* This file is part of Win32Service Library package
4+
* @copy Win32Service (c) 2018
5+
* @author "Jean-Baptiste Nahan" <jean-baptiste@nahan.fr>
6+
*/
7+
8+
namespace Win32Service\Exception;
9+
10+
11+
class StopLoopException extends Win32ServiceException
12+
{
13+
14+
}

0 commit comments

Comments
 (0)