summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2009-02-24 22:14:51 +0000
committerStephen D. Huston <shuston@apache.org>2009-02-24 22:14:51 +0000
commita000997e57e349a2ce6f68e32753ae64c9de5704 (patch)
treec85360652b0b4684902114ec4818a0faba9805ce /qpid/cpp
parentdb61f38f13280eb69edda44448c85255275014f8 (diff)
downloadqpid-python-a000997e57e349a2ce6f68e32753ae64c9de5704.tar.gz
Implement process id and name methods for Windows
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@747577 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rwxr-xr-xqpid/cpp/src/qpid/sys/windows/SystemInfo.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp b/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp
index dc5c56b6fb..3e2fcb1517 100755
--- a/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp
+++ b/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp
@@ -29,6 +29,7 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
+#include <tlhelp32.h>
#ifndef HOST_NAME_MAX
# define HOST_NAME_MAX 256
@@ -155,25 +156,43 @@ void SystemInfo::getSystemId (std::string &osName,
machine = "unknown";
break;
}
+}
uint32_t SystemInfo::getProcessId()
{
- // TODO: Provide Windows implementation
- return 0;
+ return static_cast<uint32_t>(::GetCurrentProcessId());
}
uint32_t SystemInfo::getParentProcessId()
{
- // TODO: Provide Windows implementation
- return 0;
+ // Only want info for the current process, so ask for something specific.
+ // The module info won't be used here but it keeps the snapshot limited to
+ // the current process so a search through all processes is not needed.
+ HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
+ if (snap == INVALID_HANDLE_VALUE)
+ return 0;
+ PROCESSENTRY32 entry;
+ entry.dwSize = sizeof(entry);
+ if (!Process32First(snap, &entry))
+ entry.th32ParentProcessID = 0;
+ CloseHandle(snap);
+ return static_cast<uint32_t>(entry.th32ParentProcessID);
}
std::string SystemInfo::getProcessName()
{
- // TODO: Provide Windows implementation
- return std::string();
-}
-
+ // Only want info for the current process, so ask for something specific.
+ // The module info won't be used here but it keeps the snapshot limited to
+ // the current process so a search through all processes is not needed.
+ HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
+ if (snap == INVALID_HANDLE_VALUE)
+ return 0;
+ PROCESSENTRY32 entry;
+ entry.dwSize = sizeof(entry);
+ if (!Process32First(snap, &entry))
+ entry.szExeFile[0] = '\0';
+ CloseHandle(snap);
+ return std::string(entry.szExeFile);
}
}} // namespace qpid::sys