winecfg: Fix signedness of variable in enumerate_valuesW().
[wine] / programs / services / services.h
1 /*
2  * Services.exe - include file
3  *
4  * Copyright 2007 Google (Mikolaj Zalewski)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #ifndef WINE_PROGRAMS_UTILS_H_
22 #define WINE_PROGRAMS_UTILS_H_
23
24 #include "wine/list.h"
25
26 struct scmdatabase
27 {
28     HKEY root_key;
29     LONG service_start_lock;
30     struct list services;
31     CRITICAL_SECTION cs;
32 };
33
34 struct service_entry
35 {
36     struct list entry;
37     struct scmdatabase *db;
38     LONG ref_count;                    /* number of references - if goes to zero and the service is deleted the structure will be freed */
39     LPWSTR name;
40     SERVICE_STATUS_PROCESS status;
41     QUERY_SERVICE_CONFIGW config;
42     LPWSTR description;
43     LPWSTR dependOnServices;
44     LPWSTR dependOnGroups;
45     HANDLE control_mutex;
46     HANDLE control_pipe;
47     HANDLE status_changed_event;
48 };
49
50 extern struct scmdatabase *active_database;
51
52 /* SCM database functions */
53
54 struct service_entry *scmdatabase_find_service(struct scmdatabase *db, LPCWSTR name);
55 struct service_entry *scmdatabase_find_service_by_displayname(struct scmdatabase *db, LPCWSTR name);
56 DWORD scmdatabase_add_service(struct scmdatabase *db, struct service_entry *entry);
57 DWORD scmdatabase_remove_service(struct scmdatabase *db, struct service_entry *entry);
58
59 DWORD scmdatabase_lock_startup(struct scmdatabase *db);
60 void scmdatabase_unlock_startup(struct scmdatabase *db);
61
62 void scmdatabase_lock_shared(struct scmdatabase *db);
63 void scmdatabase_lock_exclusive(struct scmdatabase *db);
64 void scmdatabase_unlock(struct scmdatabase *db);
65
66 /* Service functions */
67
68 DWORD service_create(LPCWSTR name, struct service_entry **entry);
69 BOOL validate_service_name(LPCWSTR name);
70 BOOL validate_service_config(struct service_entry *entry);
71 DWORD save_service_config(struct service_entry *entry);
72 void free_service_entry(struct service_entry *entry);
73 void release_service(struct service_entry *service);
74 void service_lock_shared(struct service_entry *service);
75 void service_lock_exclusive(struct service_entry *service);
76 void service_unlock(struct service_entry *service);
77 DWORD service_start(struct service_entry *service, DWORD service_argc, LPCWSTR *service_argv);
78
79 extern HANDLE g_hStartedEvent;
80
81 DWORD RPC_Init(void);
82 DWORD RPC_MainLoop(void);
83
84 /* from utils.c */
85 LPWSTR strdupW(LPCWSTR str);
86
87 BOOL check_multisz(LPCWSTR lpMultiSz, DWORD cbSize);
88
89 DWORD load_reg_string(HKEY hKey, LPCWSTR szValue, BOOL bExpand, LPWSTR *output);
90 DWORD load_reg_multisz(HKEY hKey, LPCWSTR szValue, LPWSTR *output);
91 DWORD load_reg_dword(HKEY hKey, LPCWSTR szValue, DWORD *output);
92
93 static inline LPCWSTR get_display_name(struct service_entry *service)
94 {
95     return service->config.lpDisplayName ? service->config.lpDisplayName : service->name;
96 }
97
98 static inline BOOL is_marked_for_delete(struct service_entry *service)
99 {
100     return service->entry.next == NULL;
101 }
102
103 #endif /*WINE_PROGRAMS_UTILS_H_*/