Skip to content

Commit 444e17a

Browse files
committed
Temporary added verbose function logging for sa_plugin_process.cpp plugin.
1 parent 497a46c commit 444e17a

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

src/plugins/sa_plugin_process/sa_plugin_process.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,63 @@
4242

4343
#define EXPORT_API __declspec(dllexport)
4444

45+
class ScopeLogger2
46+
{
47+
public:
48+
/// <summary>
49+
/// Argument struct for a ScopeManager
50+
/// </summary>
51+
struct ARGS
52+
{
53+
///<summary>The souce code filename generating the log entries.</summary>
54+
const char* filename;
55+
///<summary>The souce code line number generating the log entries.</summary>
56+
int line;
57+
///<summary>The level to use while producing log entries.</summary>
58+
sa_log_level_t level;
59+
///<summary>The name to use while generating logs. Usually the function name.</summary>
60+
const char* name;
61+
};
62+
63+
public:
64+
ScopeLogger2(const ScopeLogger2::ARGS* args_) :
65+
args(args_)
66+
{
67+
// Prepare output text
68+
std::string text;
69+
text += args->name;
70+
71+
sa_logging_print_format(args->level, "sa_plugin_process", "%s", text.c_str());
72+
}
73+
74+
~ScopeLogger2()
75+
{
76+
// Prepare output text
77+
std::string text;
78+
text += args->name;
79+
text += " - returns";
80+
81+
sa_logging_print_format(args->level, "sa_plugin_process", "%s", text.c_str());
82+
}
83+
84+
private:
85+
// Disable copy constructor and copy operator
86+
ScopeLogger2(const ScopeLogger2&);
87+
ScopeLogger2& operator=(const ScopeLogger2&);
88+
89+
public:
90+
const ARGS* args;
91+
};
92+
93+
#ifndef SA_DECLARE_SCOPE_LOGGER_ARGS
94+
#define SA_DECLARE_SCOPE_LOGGER_ARGS(info) \
95+
::ScopeLogger2::ARGS info = {0};\
96+
info.filename = __FILE__;\
97+
info.line = __LINE__;\
98+
info.name = __FUNCTION__ "()";\
99+
info.level = SA_LOG_LEVEL_INFO;
100+
#endif
101+
45102
#ifdef __cplusplus
46103
extern "C" {
47104
#if 0
@@ -86,6 +143,9 @@ void parse_string_dword(const char* str, DWORD& value)
86143
// https://stackoverflow.com/questions/13179410/check-whether-one-specific-process-is-running-on-windows-with-c
87144
DWORD find_process_id_from_name(const char* process_name)
88145
{
146+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
147+
ScopeLogger2 logger(&sli);
148+
89149
// strip path
90150
const char* p = strrchr(process_name, '\\');
91151
if (p)
@@ -120,6 +180,9 @@ DWORD find_process_id_from_name(const char* process_name)
120180

121181
bool process_id_exists(DWORD pid)
122182
{
183+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
184+
ScopeLogger2 logger(&sli);
185+
123186
PROCESSENTRY32 pi;
124187
pi.dwSize = sizeof(pi);
125188

@@ -149,6 +212,9 @@ bool process_id_exists(DWORD pid)
149212

150213
sa_error_t kill_process_by_pid(DWORD pid)
151214
{
215+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
216+
ScopeLogger2 logger(&sli);
217+
152218
bool success = false;
153219
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
154220
if (hProcess)
@@ -163,6 +229,9 @@ sa_error_t kill_process_by_pid(DWORD pid)
163229

164230
sa_error_t terminate_process_by_pid(DWORD pid)
165231
{
232+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
233+
ScopeLogger2 logger(&sli);
234+
166235
//ask the process to exit gracefully allowing a maximum of 60 seconds to close
167236
ULONGLONG time_start = GetTickCount64();
168237
bool terminated = ra::process::Terminate(pid);
@@ -185,6 +254,9 @@ sa_error_t terminate_process_by_pid(DWORD pid)
185254

186255
sa_error_t killprocess_event_create(sa_action_event_t evnt)
187256
{
257+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
258+
ScopeLogger2 logger(&sli);
259+
188260
const char* name = sa_plugin_action_get_name();
189261
const char* xml = sa_plugin_action_get_xml();
190262
sa_property_store_t* store = sa_plugin_action_get_property_store();
@@ -209,6 +281,9 @@ sa_error_t killprocess_event_create(sa_action_event_t evnt)
209281

210282
sa_error_t killprocess_event_execute(sa_action_event_t evnt)
211283
{
284+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
285+
ScopeLogger2 logger(&sli);
286+
212287
const char* action_name = sa_plugin_action_get_name();
213288
sa_property_store_t* store = sa_plugin_action_get_property_store();
214289

@@ -262,6 +337,9 @@ sa_error_t killprocess_event_execute(sa_action_event_t evnt)
262337

263338
sa_error_t killprocess_event(sa_action_event_t evnt)
264339
{
340+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
341+
ScopeLogger2 logger(&sli);
342+
265343
sa_error_t result;
266344
switch (evnt)
267345
{
@@ -284,6 +362,9 @@ sa_error_t killprocess_event(sa_action_event_t evnt)
284362

285363
sa_error_t terminateprocess_event_create(sa_action_event_t evnt)
286364
{
365+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
366+
ScopeLogger2 logger(&sli);
367+
287368
const char* name = sa_plugin_action_get_name();
288369
const char* xml = sa_plugin_action_get_xml();
289370
sa_property_store_t* store = sa_plugin_action_get_property_store();
@@ -308,6 +389,9 @@ sa_error_t terminateprocess_event_create(sa_action_event_t evnt)
308389

309390
sa_error_t terminateprocess_event_execute(sa_action_event_t evnt)
310391
{
392+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
393+
ScopeLogger2 logger(&sli);
394+
311395
const char* action_name = sa_plugin_action_get_name();
312396
sa_property_store_t* store = sa_plugin_action_get_property_store();
313397

@@ -361,6 +445,9 @@ sa_error_t terminateprocess_event_execute(sa_action_event_t evnt)
361445

362446
sa_error_t terminateprocess_event(sa_action_event_t evnt)
363447
{
448+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
449+
ScopeLogger2 logger(&sli);
450+
364451
sa_error_t result;
365452
switch (evnt)
366453
{
@@ -383,6 +470,9 @@ sa_error_t terminateprocess_event(sa_action_event_t evnt)
383470

384471
sa_boolean validate_process_filename()
385472
{
473+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
474+
ScopeLogger2 logger(&sli);
475+
386476
sa_selection_context_immutable_t* ctx = sa_plugin_validation_get_selection_context();
387477
sa_property_store_immutable_t* store = sa_plugin_validation_get_property_store();
388478

@@ -416,6 +506,9 @@ sa_boolean validate_process_filename()
416506

417507
sa_boolean validate_process_pid()
418508
{
509+
SA_DECLARE_SCOPE_LOGGER_ARGS(sli);
510+
ScopeLogger2 logger(&sli);
511+
419512
sa_selection_context_immutable_t* ctx = sa_plugin_validation_get_selection_context();
420513
sa_property_store_immutable_t* store = sa_plugin_validation_get_property_store();
421514

0 commit comments

Comments
 (0)