mach_client_utilities.h [plain text]
#ifndef MACH_CLIENT_UTILITIES_H
#define MACH_CLIENT_UTILITIES_H
#include <mach/mach.h>
#include <mach/message.h>
#include <mach/boolean.h>
#include <servers/bootstrap.h>
#include <sys/param.h>
#include <Kerberos/LoginSessions.h>
#define kMachIPCMaxMsgSize 2048 + MAX_TRAILER_SIZE
#define kMachIPCTimeout 200
#if __cplusplus
extern "C" {
#endif
kern_return_t
mach_client_lookup_server (const char *inServiceName,
mach_port_t *outServicePort);
kern_return_t
mach_client_lookup_and_launch_server (const char *inServiceName,
const char *inServerPath,
mach_port_t *outServicePort);
kern_return_t __KerberosIPCError (kern_return_t inError, const char *function, const char *file, int line);
#define KerberosIPCError_(err) __KerberosIPCError(err, __FUNCTION__, __FILE__, __LINE__)
#if __cplusplus
}
#endif
#if __cplusplus
class MachServerPort {
public:
MachServerPort (const char *inServiceName, const char *inServerPath,
bool inLaunchIfNecessary) : mPort (MACH_PORT_NULL)
{
kern_return_t err = KERN_SUCCESS;
mach_port_t port = MACH_PORT_NULL;
if (inLaunchIfNecessary) {
err = mach_client_lookup_and_launch_server (inServiceName, inServerPath, &port);
} else {
err = mach_client_lookup_server (inServiceName, &port);
}
if (!err) {
mPort = port;
port = MACH_PORT_NULL;
}
if (port != MACH_PORT_NULL) { mach_port_deallocate (mach_task_self(), port); }
}
~MachServerPort ()
{
if (mPort != MACH_PORT_NULL) { mach_port_deallocate (mach_task_self(), mPort); }
}
mach_port_t Get () const
{
return mPort;
}
private:
mach_port_t mPort;
char *serviceName;
};
#endif
#endif