summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/windows
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2016-07-05 21:55:35 +0000
committerRobert Gemmell <robbie@apache.org>2016-07-05 21:55:35 +0000
commitf160cb6566c17945f7ebc4f3a752b2cc6a051685 (patch)
tree809f04fc1967c22e5abc52de07602555bed0e920 /qpid/cpp/src/windows
parentebb276cca41582b73223b55eff9f2d4386f4f746 (diff)
downloadqpid-python-f160cb6566c17945f7ebc4f3a752b2cc6a051685.tar.gz
QPID-7207: remove cpp and python subdirs from svn trunk, they have migrated to their own git repositories
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1751566 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/windows')
-rw-r--r--qpid/cpp/src/windows/QpiddBroker.cpp512
-rw-r--r--qpid/cpp/src/windows/SCM.cpp332
-rw-r--r--qpid/cpp/src/windows/SCM.h109
-rw-r--r--qpid/cpp/src/windows/resources/qpid-icon.icobin52972 -> 0 bytes
-rw-r--r--qpid/cpp/src/windows/resources/template-resource.rc122
-rw-r--r--qpid/cpp/src/windows/resources/version-resource.h35
6 files changed, 0 insertions, 1110 deletions
diff --git a/qpid/cpp/src/windows/QpiddBroker.cpp b/qpid/cpp/src/windows/QpiddBroker.cpp
deleted file mode 100644
index b383b7d6c7..0000000000
--- a/qpid/cpp/src/windows/QpiddBroker.cpp
+++ /dev/null
@@ -1,512 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "config.h"
-#include "qpidd.h"
-#include "SCM.h"
-#include "qpid/Exception.h"
-#include "qpid/Options.h"
-#include "qpid/Plugin.h"
-#include "qpid/sys/IntegerTypes.h"
-#include "qpid/sys/windows/check.h"
-#include "qpid/sys/Thread.h"
-#include "qpid/broker/Broker.h"
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include <windows.h>
-
-namespace {
- // This will accept args from the command line; augmented with service args.
- std::vector<std::string> cmdline_args;
-}
-
-namespace qpid {
-namespace broker {
-
-BootstrapOptions::BootstrapOptions(const char* argv0)
- : qpid::Options("Options"),
- common("", QPIDD_CONF_FILE, QPIDC_CONF_FILE),
- module(QPIDD_MODULE_DIR),
- log(argv0)
-{
- add(common);
- add(module);
- add(log);
-}
-
-void BootstrapOptions::usage() const {
- std::cout << "Usage: qpidd [OPTIONS]" << std::endl << std::endl << *this << std::endl;
-}
-
-// Local functions to set and get the pid via a LockFile.
-namespace {
-
-const std::string TCP = "tcp";
-
-// ShutdownEvent maintains an event that can be used to ask the broker
-// to stop. Analogous to sending SIGTERM/SIGINT to the posix broker.
-// The signal() method signals the event.
-class ShutdownEvent {
- public:
- ShutdownEvent(int port);
- ~ShutdownEvent();
-
- void create();
- void open();
- void signal();
-
- private:
- std::string eventName;
-
- protected:
- HANDLE event;
-};
-
-class ShutdownHandler : public ShutdownEvent, public qpid::sys::Runnable {
- public:
- ShutdownHandler(int port, const boost::intrusive_ptr<Broker>& b)
- : ShutdownEvent(port) { broker = b; }
-
- private:
- virtual void run(); // Inherited from Runnable
- boost::intrusive_ptr<Broker> broker;
-};
-
-ShutdownEvent::ShutdownEvent(int port) : event(NULL) {
- std::ostringstream name;
- name << "qpidd_" << port << std::ends;
- eventName = name.str();
-}
-
-void ShutdownEvent::create() {
- // Auto-reset event in case multiple processes try to signal a
- // broker that doesn't respond for some reason. Initially not signaled.
- event = ::CreateEvent(NULL, false, false, eventName.c_str());
- QPID_WINDOWS_CHECK_NULL(event);
-}
-
-void ShutdownEvent::open() {
- // TODO: Might need to search Global\\ name if unadorned name fails
- event = ::OpenEvent(EVENT_MODIFY_STATE, false, eventName.c_str());
- QPID_WINDOWS_CHECK_NULL(event);
-}
-
-ShutdownEvent::~ShutdownEvent() {
- ::CloseHandle(event);
- event = NULL;
-}
-
-void ShutdownEvent::signal() {
- QPID_WINDOWS_CHECK_NOT(::SetEvent(event), 0);
-}
-
-
-void ShutdownHandler::run() {
- if (event == NULL)
- return;
- ::WaitForSingleObject(event, INFINITE);
- if (broker.get()) {
- broker->shutdown();
- broker = 0; // Release the broker reference
- }
-}
-
-// Console control handler to properly handle ctl-c.
-int ourPort;
-BOOL CtrlHandler(DWORD ctl)
-{
- ShutdownEvent shutter(ourPort); // We have to have set up the port before interrupting
- shutter.open();
- shutter.signal();
- return ((ctl == CTRL_C_EVENT || ctl == CTRL_CLOSE_EVENT) ? TRUE : FALSE);
-}
-
-template <typename T>
-class NamedSharedMemory {
- std::string name;
- HANDLE memory;
- T* data;
-
-public:
- NamedSharedMemory(const std::string&);
- ~NamedSharedMemory();
-
- T& create();
- T& get();
-};
-
-template <typename T>
-NamedSharedMemory<T>::NamedSharedMemory(const std::string& n) :
- name(n),
- memory(NULL),
- data(0)
-{}
-
-template <typename T>
-NamedSharedMemory<T>::~NamedSharedMemory() {
- if (data)
- ::UnmapViewOfFile(data);
- if (memory != NULL)
- ::CloseHandle(memory);
-}
-
-template <typename T>
-T& NamedSharedMemory<T>::create() {
- assert(memory == NULL);
-
- // Create named shared memory file
- memory = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(T), name.c_str());
- QPID_WINDOWS_CHECK_NULL(memory);
-
- // Map file into memory
- data = static_cast<T*>(::MapViewOfFile(memory, FILE_MAP_WRITE, 0, 0, 0));
- QPID_WINDOWS_CHECK_NULL(data);
-
- return *data;
-}
-
-template <typename T>
-T& NamedSharedMemory<T>::get() {
- if (memory == NULL) {
- // TODO: Might need to search Global\\ name if unadorned name fails
- memory = ::OpenFileMapping(FILE_MAP_WRITE, FALSE, name.c_str());
- QPID_WINDOWS_CHECK_NULL(memory);
-
- data = static_cast<T*>(::MapViewOfFile(memory, FILE_MAP_WRITE, 0, 0, 0));
- QPID_WINDOWS_CHECK_NULL(data);
- }
-
- return *data;
-}
-
-std::string brokerInfoName(uint16_t port)
-{
- std::ostringstream path;
- path << "qpidd_info_" << port;
- return path.str();
-}
-
-struct BrokerInfo {
- DWORD pid;
-};
-
-// Service-related items. Only involved when running the broker as a Windows
-// service.
-
-const std::string svcName = "qpidd";
-SERVICE_STATUS svcStatus;
-SERVICE_STATUS_HANDLE svcStatusHandle = 0;
-
-// This function is only called when the broker is run as a Windows
-// service. It receives control requests from Windows.
-VOID WINAPI SvcCtrlHandler(DWORD control)
-{
- switch(control) {
- case SERVICE_CONTROL_STOP:
- svcStatus.dwCurrentState = SERVICE_STOP_PENDING;
- svcStatus.dwControlsAccepted = 0;
- svcStatus.dwCheckPoint = 1;
- svcStatus.dwWaitHint = 5000; // 5 secs.
- ::SetServiceStatus(svcStatusHandle, &svcStatus);
- CtrlHandler(CTRL_C_EVENT);
- break;
-
- case SERVICE_CONTROL_INTERROGATE:
- break;
-
- default:
- break;
- }
-}
-
-VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
-{
- // The arguments can come from 2 places. Args set with the executable
- // name when the service is installed come through main() and are now
- // in cmdline_args. Arguments set in StartService come into argc/argv
- // above; if they are set, argv[0] is the service name. Make command
- // line args first; StartService args come later and can override
- // command line args.
- int all_argc = argc + cmdline_args.size();
- if (argc == 0 && !cmdline_args.empty())
- ++all_argc; // No StartService args, so need to add prog name argv[0]
- const char **all_argv = new const char *[all_argc];
- if (all_argc > 0) {
- int i = 0;
- all_argv[i++] = argc > 0 ? argv[0] : svcName.c_str();
- for (size_t j = 0; j < cmdline_args.size(); ++j)
- all_argv[i++] = cmdline_args[j].c_str();
- for (DWORD k = 1; k < argc; ++k)
- all_argv[i++] = argv[k];
- }
-
- ::memset(&svcStatus, 0, sizeof(svcStatus));
- svcStatusHandle = ::RegisterServiceCtrlHandler(svcName.c_str(),
- SvcCtrlHandler);
- svcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
- svcStatus.dwCheckPoint = 1;
- svcStatus.dwWaitHint = 10000; // 10 secs.
- svcStatus.dwCurrentState = SERVICE_START_PENDING;
- ::SetServiceStatus(svcStatusHandle, &svcStatus);
- // QpiddBroker class resets state to running.
- svcStatus.dwWin32ExitCode = run_broker(all_argc,
- const_cast<char**>(all_argv),
- true);
- svcStatus.dwCurrentState = SERVICE_STOPPED;
- svcStatus.dwCheckPoint = 0;
- svcStatus.dwWaitHint = 0;
- ::SetServiceStatus(svcStatusHandle, &svcStatus);
-}
-
-} // namespace
-
-
-struct ProcessControlOptions : public qpid::Options {
- bool quit;
- bool check;
- std::string transport;
-
- ProcessControlOptions()
- : qpid::Options("Process control options"),
- quit(false),
- check(false),
- transport(TCP)
- {
- addOptions()
- ("check,c", qpid::optValue(check), "Prints the broker's process ID to stdout and returns 0 if the broker is running, otherwise returns 1")
- ("transport", qpid::optValue(transport, "TRANSPORT"), "The transport for which to return the port")
- ("quit,q", qpid::optValue(quit), "Tells the broker to shut down");
- }
-};
-
-struct ServiceOptions : public qpid::Options {
- bool install;
- bool start;
- bool stop;
- bool uninstall;
- bool daemon;
- std::string startType;
- std::string startArgs;
- std::string account;
- std::string password;
- std::string depends;
-
- ServiceOptions()
- : qpid::Options("Service options"),
- install(false),
- start(false),
- stop(false),
- uninstall(false),
- daemon(false),
- startType("demand"),
- startArgs(""),
- account("NT AUTHORITY\\LocalService"),
- password(""),
- depends("")
- {
- addOptions()
- ("install", qpid::optValue(install), "Install as service")
- ("start-type", qpid::optValue(startType, "auto|demand|disabled"), "Service start type\nApplied at install time only.")
- ("arguments", qpid::optValue(startArgs, "COMMAND LINE ARGS"), "Arguments to pass when service auto-starts")
- ("account", qpid::optValue(account, "(LocalService)"), "Account to run as, default is LocalService\nApplied at install time only.")
- ("password", qpid::optValue(password, "PASSWORD"), "Account password, if needed\nApplied at install time only.")
- ("depends", qpid::optValue(depends, "(comma delimited list)"), "Names of services that must start before this service\nApplied at install time only.")
- ("start", qpid::optValue(start), "Start the service.")
- ("stop", qpid::optValue(stop), "Stop the service.")
- ("uninstall", qpid::optValue(uninstall), "Uninstall the service.");
- }
-};
-
-struct QpiddWindowsOptions : public QpiddOptionsPrivate {
- ProcessControlOptions control;
- ServiceOptions service;
- QpiddWindowsOptions(QpiddOptions *parent) : QpiddOptionsPrivate(parent) {
- parent->add(service);
- parent->add(control);
- }
-};
-
-QpiddOptions::QpiddOptions(const char* argv0)
- : qpid::Options("Options"),
- common("", QPIDD_CONF_FILE, QPIDC_CONF_FILE),
- module(QPIDD_MODULE_DIR),
- log(argv0)
-{
- add(common);
- add(module);
- add(broker);
- add(log);
-
- platform.reset(new QpiddWindowsOptions(this));
- qpid::Plugin::addOptions(*this);
-}
-
-void QpiddOptions::usage() const {
- std::cout << "Usage: qpidd [OPTIONS]" << std::endl << std::endl
- << *this << std::endl;
-}
-
-int QpiddBroker::execute (QpiddOptions *options) {
-
- // If running as a service, bump the status checkpoint to let SCM know
- // we're still making progress.
- if (svcStatusHandle != 0) {
- svcStatus.dwCheckPoint++;
- ::SetServiceStatus(svcStatusHandle, &svcStatus);
- }
-
- // Options that affect a running daemon.
- QpiddWindowsOptions *myOptions =
- reinterpret_cast<QpiddWindowsOptions *>(options->platform.get());
- if (myOptions == 0)
- throw qpid::Exception("Internal error obtaining platform options");
-
- if (myOptions->service.install) {
- // Handle start type
- DWORD startType;
- if (myOptions->service.startType.compare("demand") == 0)
- startType = SERVICE_DEMAND_START;
- else if (myOptions->service.startType.compare("auto") == 0)
- startType = SERVICE_AUTO_START;
- else if (myOptions->service.startType.compare("disabled") == 0)
- startType = SERVICE_DISABLED;
- else if (!myOptions->service.startType.empty())
- throw qpid::Exception("Invalid service start type: " +
- myOptions->service.startType);
-
- // Install service and exit
- qpid::windows::SCM manager;
- manager.install(svcName,
- "Apache Qpid Message Broker",
- myOptions->service.startArgs,
- startType,
- myOptions->service.account,
- myOptions->service.password,
- myOptions->service.depends);
- return 0;
- }
-
- if (myOptions->service.start) {
- qpid::windows::SCM manager;
- manager.start(svcName);
- return 0;
- }
-
- if (myOptions->service.stop) {
- qpid::windows::SCM manager;
- manager.stop(svcName);
- return 0;
- }
-
- if (myOptions->service.uninstall) {
- qpid::windows::SCM manager;
- manager.uninstall(svcName);
- return 0;
- }
-
- if (myOptions->control.check || myOptions->control.quit) {
- // Relies on port number being set via --port or QPID_PORT env variable.
- NamedSharedMemory<BrokerInfo> info(brokerInfoName(options->broker.port));
- int pid = info.get().pid;
- if (pid < 0)
- return 1;
- if (myOptions->control.check)
- std::cout << pid << std::endl;
- if (myOptions->control.quit) {
- ShutdownEvent shutter(options->broker.port);
- shutter.open();
- shutter.signal();
- HANDLE brokerHandle = ::OpenProcess(SYNCHRONIZE, false, pid);
- QPID_WINDOWS_CHECK_NULL(brokerHandle);
- ::WaitForSingleObject(brokerHandle, INFINITE);
- ::CloseHandle(brokerHandle);
- }
- return 0;
- }
-
- boost::intrusive_ptr<Broker> brokerPtr(new Broker(options->broker));
-
- // Need the correct port number to use in the pid file name.
- if (options->broker.port == 0)
- options->broker.port = brokerPtr->getPort(myOptions->control.transport);
-
- BrokerInfo info;
- info.pid = ::GetCurrentProcessId();
-
- NamedSharedMemory<BrokerInfo> sharedInfo(brokerInfoName(options->broker.port));
- sharedInfo.create() = info;
-
- // Allow the broker to receive a shutdown request via a qpidd --quit
- // command. Note that when the broker is run as a service this operation
- // should not be allowed.
- ourPort = options->broker.port;
- ShutdownHandler waitShut(ourPort, brokerPtr);
- waitShut.create();
- qpid::sys::Thread waitThr(waitShut); // Wait for shutdown event
- ::SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
- brokerPtr->accept();
- std::cout << options->broker.port << std::endl;
-
- // If running as a service, tell SCM we're up. There's still a chance
- // that store recovery will drag out the time before the broker actually
- // responds to requests, but integrating that mechanism with the SCM
- // updating is probably more work than it's worth.
- if (svcStatusHandle != 0) {
- svcStatus.dwCheckPoint = 0;
- svcStatus.dwWaitHint = 0;
- svcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
- svcStatus.dwCurrentState = SERVICE_RUNNING;
- ::SetServiceStatus(svcStatusHandle, &svcStatus);
- }
-
- brokerPtr->run();
- waitShut.signal(); // In case we shut down some other way
- waitThr.join();
- return 0;
-}
-
-}} // namespace qpid::broker
-
-int main(int argc, char* argv[])
-{
- // If started as a service, notify the SCM we're up. Else just run.
- // If as a service, StartServiceControlDispatcher doesn't return until
- // the service is stopped.
- SERVICE_TABLE_ENTRY dispatchTable[] =
- {
- { "", (LPSERVICE_MAIN_FUNCTION)qpid::broker::ServiceMain },
- { NULL, NULL }
- };
- // Copy any command line args to be available in case we're started
- // as a service. Pick these back up in ServiceMain.
- for (int i = 1; i < argc; ++i)
- cmdline_args.push_back(argv[i]);
-
- if (!StartServiceCtrlDispatcher(dispatchTable)) {
- DWORD err = ::GetLastError();
- if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) // Run as console
- return qpid::broker::run_broker(argc, argv);
- throw QPID_WINDOWS_ERROR(err);
- }
- return 0;
-}
diff --git a/qpid/cpp/src/windows/SCM.cpp b/qpid/cpp/src/windows/SCM.cpp
deleted file mode 100644
index 2eeb143427..0000000000
--- a/qpid/cpp/src/windows/SCM.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "qpid/log/Statement.h"
-#include "qpid/sys/windows/check.h"
-#include "SCM.h"
-
-#pragma comment(lib, "advapi32.lib")
-
-namespace qpid {
-namespace windows {
-
-namespace {
-
-// Container that will close a SC_HANDLE upon destruction.
-class AutoServiceHandle {
-public:
- AutoServiceHandle(SC_HANDLE h_ = NULL) : h(h_) {}
- ~AutoServiceHandle() { if (h != NULL) ::CloseServiceHandle(h); }
- void release() { h = NULL; }
- void reset(SC_HANDLE newHandle)
- {
- if (h != NULL)
- ::CloseServiceHandle(h);
- h = newHandle;
- }
- operator SC_HANDLE() const { return h; }
-
-private:
- SC_HANDLE h;
-};
-
-}
-
-SCM::SCM() : scmHandle(NULL)
-{
-}
-
-SCM::~SCM()
-{
- if (NULL != scmHandle)
- ::CloseServiceHandle(scmHandle);
-}
-
-/**
- * Install this executable as a service
- */
-void SCM::install(const string& serviceName,
- const string& serviceDesc,
- const string& args,
- DWORD startType,
- const string& account,
- const string& password,
- const string& depends)
-{
- // Handle dependent service name list; Windows wants a set of nul-separated
- // names ending with a double nul.
- string depends2 = depends;
- if (!depends2.empty()) {
- // CDL to null delimiter w/ trailing double null
- size_t p = 0;
- while ((p = depends2.find_first_of( ',', p)) != string::npos)
- depends2.replace(p, 1, 1, '\0');
- depends2.push_back('\0');
- depends2.push_back('\0');
- }
-
-#if 0
- // I'm nervous about adding a user/password check here. Is this a
- // potential attack vector, letting users check passwords without
- // control? -Steve Huston, Feb 24, 2011
-
- // Validate account, password
- HANDLE hToken = NULL;
- bool logStatus = false;
- if (!account.empty() && !password.empty() &&
- !(logStatus = ::LogonUserA(account.c_str(),
- "",
- password.c_str(),
- LOGON32_LOGON_NETWORK,
- LOGON32_PROVIDER_DEFAULT,
- &hToken ) != 0))
- std::cout << "warning: supplied account & password failed with LogonUser." << std::endl;
- if (logStatus)
- ::CloseHandle(hToken);
-#endif
-
- // Get fully qualified .exe name
- char myPath[MAX_PATH];
- DWORD myPathLength = ::GetModuleFileName(NULL, myPath, MAX_PATH);
- QPID_WINDOWS_CHECK_NOT(myPathLength, 0);
- string imagePath(myPath, myPathLength);
- if (!args.empty())
- imagePath += " " + args;
-
- // Ensure there's a handle to the SCM database.
- openSvcManager();
-
- // Create the service
- SC_HANDLE svcHandle;
- svcHandle = ::CreateService(scmHandle, // SCM database
- serviceName.c_str(), // name of service
- serviceDesc.c_str(), // name to display
- SERVICE_ALL_ACCESS, // desired access
- SERVICE_WIN32_OWN_PROCESS, // service type
- startType, // start type
- SERVICE_ERROR_NORMAL, // error cntrl type
- imagePath.c_str(), // path to service's binary w/ optional arguments
- NULL, // no load ordering group
- NULL, // no tag identifier
- depends2.empty() ? NULL : depends2.c_str(),
- account.empty() ? NULL : account.c_str(), // account name, or NULL for LocalSystem
- password.empty() ? NULL : password.c_str()); // password, or NULL for none
- QPID_WINDOWS_CHECK_NULL(svcHandle);
- ::CloseServiceHandle(svcHandle);
- QPID_LOG(info, "Service installed successfully");
-}
-
-/**
- *
- */
-void SCM::uninstall(const string& serviceName)
-{
- // Ensure there's a handle to the SCM database.
- openSvcManager();
- AutoServiceHandle svc(::OpenService(scmHandle,
- serviceName.c_str(),
- DELETE));
- QPID_WINDOWS_CHECK_NULL((SC_HANDLE)svc);
- QPID_WINDOWS_CHECK_NOT(::DeleteService(svc), 0);
- QPID_LOG(info, "Service deleted successfully.");
-}
-
-/**
- * Attempt to start the service.
- */
-void SCM::start(const string& serviceName)
-{
- // Ensure we have a handle to the SCM database.
- openSvcManager();
-
- // Get a handle to the service.
- AutoServiceHandle svc(::OpenService(scmHandle,
- serviceName.c_str(),
- SERVICE_ALL_ACCESS));
- QPID_WINDOWS_CHECK_NULL(svc);
-
- // Check the status in case the service is not stopped.
- DWORD state = waitForStateChangeFrom(svc, SERVICE_STOP_PENDING);
- if (state == SERVICE_STOP_PENDING)
- throw qpid::Exception("Timed out waiting for running service to stop.");
-
- // Attempt to start the service.
- QPID_WINDOWS_CHECK_NOT(::StartService(svc, 0, NULL), 0);
-
- QPID_LOG(info, "Service start pending...");
-
- // Check the status until the service is no longer start pending.
- state = waitForStateChangeFrom(svc, SERVICE_START_PENDING);
- // Determine whether the service is running.
- if (state == SERVICE_RUNNING) {
- QPID_LOG(info, "Service started successfully");
- }
- else {
- throw qpid::Exception(QPID_MSG("Service not yet running; state now " << state));
- }
-}
-
-/**
- *
- */
-void SCM::stop(const string& serviceName)
-{
- // Ensure a handle to the SCM database.
- openSvcManager();
-
- // Get a handle to the service.
- AutoServiceHandle svc(::OpenService(scmHandle,
- serviceName.c_str(),
- SERVICE_STOP | SERVICE_QUERY_STATUS |
- SERVICE_ENUMERATE_DEPENDENTS));
- QPID_WINDOWS_CHECK_NULL(svc);
-
- // Make sure the service is not already stopped; if it's stop-pending,
- // wait for it to finalize.
- DWORD state = waitForStateChangeFrom(svc, SERVICE_STOP_PENDING);
- if (state == SERVICE_STOPPED) {
- QPID_LOG(info, "Service is already stopped");
- return;
- }
-
- // If the service is running, dependencies must be stopped first.
- std::auto_ptr<ENUM_SERVICE_STATUS> deps;
- DWORD numDeps = getDependentServices(svc, deps);
- for (DWORD i = 0; i < numDeps; i++)
- stop(deps.get()[i].lpServiceName);
-
- // Dependents stopped; send a stop code to the service.
- SERVICE_STATUS_PROCESS ssp;
- if (!::ControlService(svc, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&ssp))
- throw qpid::Exception(QPID_MSG("Stopping " << serviceName << ": " <<
- qpid::sys::strError(::GetLastError())));
-
- // Wait for the service to stop.
- state = waitForStateChangeFrom(svc, SERVICE_STOP_PENDING);
- if (state == SERVICE_STOPPED)
- QPID_LOG(info, QPID_MSG("Service " << serviceName <<
- " stopped successfully."));
-}
-
-/**
- *
- */
-void SCM::openSvcManager()
-{
- if (NULL != scmHandle)
- return;
-
- scmHandle = ::OpenSCManager(NULL, // local computer
- NULL, // ServicesActive database
- SC_MANAGER_ALL_ACCESS); // Rights
- QPID_WINDOWS_CHECK_NULL(scmHandle);
-}
-
-DWORD SCM::waitForStateChangeFrom(SC_HANDLE svc, DWORD originalState)
-{
- SERVICE_STATUS_PROCESS ssStatus;
- DWORD bytesNeeded;
- DWORD waitTime;
- if (!::QueryServiceStatusEx(svc, // handle to service
- SC_STATUS_PROCESS_INFO, // information level
- (LPBYTE)&ssStatus, // address of structure
- sizeof(ssStatus), // size of structure
- &bytesNeeded)) // size needed if buffer is too small
- throw QPID_WINDOWS_ERROR(::GetLastError());
-
- // Save the tick count and initial checkpoint.
- DWORD startTickCount = ::GetTickCount();
- DWORD oldCheckPoint = ssStatus.dwCheckPoint;
-
- // Wait for the service to change out of the noted state.
- while (ssStatus.dwCurrentState == originalState) {
- // Do not wait longer than the wait hint. A good interval is
- // one-tenth of the wait hint but not less than 1 second
- // and not more than 10 seconds.
- waitTime = ssStatus.dwWaitHint / 10;
- if (waitTime < 1000)
- waitTime = 1000;
- else if (waitTime > 10000)
- waitTime = 10000;
-
- ::Sleep(waitTime);
-
- // Check the status until the service is no longer stop pending.
- if (!::QueryServiceStatusEx(svc,
- SC_STATUS_PROCESS_INFO,
- (LPBYTE) &ssStatus,
- sizeof(ssStatus),
- &bytesNeeded))
- throw QPID_WINDOWS_ERROR(::GetLastError());
-
- if (ssStatus.dwCheckPoint > oldCheckPoint) {
- // Continue to wait and check.
- startTickCount = ::GetTickCount();
- oldCheckPoint = ssStatus.dwCheckPoint;
- } else {
- if ((::GetTickCount() - startTickCount) > ssStatus.dwWaitHint)
- break;
- }
- }
- return ssStatus.dwCurrentState;
-}
-
-/**
- * Get the services that depend on @arg svc. All dependent service info
- * is returned in an array of ENUM_SERVICE_STATUS structures via @arg deps.
- *
- * @retval The number of dependent services.
- */
-DWORD SCM::getDependentServices(SC_HANDLE svc,
- std::auto_ptr<ENUM_SERVICE_STATUS>& deps)
-{
- DWORD bytesNeeded;
- DWORD numEntries;
-
- // Pass a zero-length buffer to get the required buffer size.
- if (::EnumDependentServices(svc,
- SERVICE_ACTIVE,
- 0,
- 0,
- &bytesNeeded,
- &numEntries)) {
- // If the Enum call succeeds, then there are no dependent
- // services, so do nothing.
- return 0;
- }
-
- if (::GetLastError() != ERROR_MORE_DATA)
- throw QPID_WINDOWS_ERROR((::GetLastError()));
-
- // Allocate a buffer for the dependencies.
- deps.reset((LPENUM_SERVICE_STATUS)(new char[bytesNeeded]));
- // Enumerate the dependencies.
- if (!::EnumDependentServices(svc,
- SERVICE_ACTIVE,
- deps.get(),
- bytesNeeded,
- &bytesNeeded,
- &numEntries))
- throw QPID_WINDOWS_ERROR((::GetLastError()));
- return numEntries;
-}
-
-} } // namespace qpid::windows
diff --git a/qpid/cpp/src/windows/SCM.h b/qpid/cpp/src/windows/SCM.h
deleted file mode 100644
index bdc73bc210..0000000000
--- a/qpid/cpp/src/windows/SCM.h
+++ /dev/null
@@ -1,109 +0,0 @@
-#ifndef WINDOWS_SCM_H
-#define WINDOWS_SCM_H
-
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include <memory>
-#include <string>
-using std::string;
-
-#ifdef UNICODE
-#undef UNICODE
-#endif
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-
-#include <windows.h>
-
-namespace qpid {
-namespace windows {
-
-/**
- * @class SCM
- *
- * Access the Windows Service Control Manager.
- */
-class SCM
-{
-public:
- SCM();
- ~SCM();
-
- /**
- * Install this executable as a service
- *
- * @param serviceName The name of the service
- * @param serviceDesc Description of the service's purpose
- * @param args The argument list to pass into the service
- * @param startType The start type: SERVICE_DEMAND_START,
- * SERVICE_AUTO_START, SERVICE_DISABLED
- * @param account If not empty, the account name to install this
- * service under
- * @param password If not empty, the account password to install this
- * service with
- * @param depends If not empty, a comma delimited list of services
- * that must start before this one
- */
- void install(const string& serviceName,
- const string& serviceDesc,
- const string& args,
- DWORD startType = SERVICE_DEMAND_START,
- const string& account = "NT AUTHORITY\\LocalSystem",
- const string& password = "",
- const string& depends = "");
-
- /**
- * Uninstall this executable as a service
- *
- * @param serviceName the name of the service
- */
- void uninstall(const string& serviceName);
-
- /**
- * Start the specified service
- *
- * @param serviceName the name of the service
- */
- void start(const string& serviceName);
-
- /**
- * Stop the specified service
- *
- * @param serviceName the name of the service
- */
- void stop(const string &serviceName);
-
-private:
- SC_HANDLE scmHandle;
-
- void openSvcManager();
- DWORD waitForStateChangeFrom(SC_HANDLE svc, DWORD originalState);
- DWORD getDependentServices(SC_HANDLE svc,
- std::auto_ptr<ENUM_SERVICE_STATUS>& deps);
-
-};
-
-}} // namespace qpid::windows
-
-#endif /* #ifndef WINDOWS_SCM_H */
diff --git a/qpid/cpp/src/windows/resources/qpid-icon.ico b/qpid/cpp/src/windows/resources/qpid-icon.ico
deleted file mode 100644
index 112f5d8f1f..0000000000
--- a/qpid/cpp/src/windows/resources/qpid-icon.ico
+++ /dev/null
Binary files differ
diff --git a/qpid/cpp/src/windows/resources/template-resource.rc b/qpid/cpp/src/windows/resources/template-resource.rc
deleted file mode 100644
index 8ca0a90890..0000000000
--- a/qpid/cpp/src/windows/resources/template-resource.rc
+++ /dev/null
@@ -1,122 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-#include "version-resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "windows.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-#endif //_WIN32
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE
-BEGIN
- "version-resource.h\0"
-END
-
-2 TEXTINCLUDE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION ${winverFileVersionBinary}
- PRODUCTVERSION ${winverProductVersionBinary}
- FILEFLAGSMASK 0x17L
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x2L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904b0"
- BEGIN
- VALUE "FileDescription", "${winverFileDescription}"
- VALUE "FileVersion", "${winverFileVersionString}"
- VALUE "LegalCopyright", "${winverLegalCopyright}"
- VALUE "InternalName", "${winverInternalName}"
- VALUE "OriginalFilename", "${winverOriginalFilename}"
- VALUE "ProductName", "${winverProductName}"
- VALUE "ProductVersion", "${winverProductVersionString}"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1200
- END
-END
-
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDI_ICON1 ICON "qpid-icon.ico"
-
-#endif // English (U.S.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/qpid/cpp/src/windows/resources/version-resource.h b/qpid/cpp/src/windows/resources/version-resource.h
deleted file mode 100644
index bf942abbaf..0000000000
--- a/qpid/cpp/src/windows/resources/version-resource.h
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Preserved for common usage by any Qpid exe/dll.
-
-#define IDI_ICON1 101
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 104
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1001
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif