blob: 9008293e83dc73836cba33c00fa904f0d788364e [file] [log] [blame]
#pragma once
#ifndef APACHE_GEODE_GUARD_a7058f04d2a065ec8cd9179a5349a649
#define APACHE_GEODE_GUARD_a7058f04d2a065ec8cd9179a5349a649
/*
* 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 "PerfFwk.hpp"
#include "FwkLog.hpp"
#include "IpcHandler.hpp"
#include "FwkObjects.hpp"
#include <ace/Task.h>
#include <ace/SOCK_Acceptor.h>
#include <string>
namespace apache {
namespace geode {
namespace client {
namespace testframework {
#ifdef WIN32
#define pclose _pclose
#endif // WIN32
class TaskClient : public ACE_Task_Base {
private:
char* m_host;
int32_t m_port;
char* m_logDirectory;
char* m_testFile;
IpcHandler* m_ipc;
int32_t m_id;
bool m_busy;
bool m_assigned;
std::string m_name;
ACE_SOCK_Acceptor* m_listener;
std::string m_taskId;
bool m_runsTasks;
char* m_program;
char* m_arguments;
static FILE* m_pipe;
static uint32_t m_refCnt;
std::string m_hostGroup;
void openPipe();
void writePipe(const char* cmd);
public:
TaskClient(int32_t port, const char* logDir, const char* testFile,
ACE_SOCK_Acceptor* listener, int32_t id, const char* name = " ")
: m_host(NULL),
m_port(port),
m_logDirectory(strdup(logDir)),
m_testFile(strdup(testFile)),
m_ipc(0),
m_id(id),
m_busy(false),
m_assigned(false),
m_name(name),
m_listener(listener),
m_runsTasks(true),
m_program(NULL),
m_arguments(NULL),
m_hostGroup(FwkClientSet::m_defaultGroup) {
m_refCnt++;
}
TaskClient(const char* logDir, int32_t id, const char* program,
const char* arguments, const char* name = " ")
: m_host(NULL),
m_port(0),
m_logDirectory(strdup(logDir)),
m_testFile(NULL),
m_ipc(0),
m_id(id),
m_busy(false),
m_assigned(false),
m_name(name),
m_listener(NULL),
m_runsTasks(false),
m_program((program == NULL) ? NULL : strdup(program)),
m_arguments((arguments == NULL) ? NULL : strdup(arguments)),
m_hostGroup(FwkClientSet::m_defaultGroup) {
m_refCnt++;
}
~TaskClient() {
m_refCnt--;
if ((m_refCnt < 1) && (m_pipe != (FILE*)0)) {
// FWKINFO( "Closing pipe." );
const char* pexit = "exit\n";
writePipe(pexit);
perf::sleepSeconds(3);
pclose(m_pipe);
m_pipe = (FILE*)0;
// FWKINFO( "Pipe closed." );
}
if (m_host != NULL) {
free(m_host);
m_host = NULL;
}
if (m_logDirectory != NULL) {
free(m_logDirectory);
m_logDirectory = NULL;
}
if (m_testFile != NULL) {
free(m_testFile);
m_testFile = NULL;
}
if (m_ipc != NULL) {
delete m_ipc;
m_ipc = NULL;
}
}
int32_t getId() { return m_id; }
const char* getLogDirectory() { return m_logDirectory; }
bool isBusy() { return m_busy; }
void setBusy(bool busy) { m_busy = busy; }
bool isAssigned() { return m_assigned; }
void setAssigned(bool assigned) { m_assigned = assigned; }
std::string getName() { return m_name; }
std::string getTaskId() { return m_taskId; }
void setHostGroup(const std::string& grp) { m_hostGroup = grp; }
std::string getHostGroup() { return m_hostGroup; }
bool sendExit() { return m_ipc->sendExit(); }
bool sendTask(char* taskId) {
m_taskId = taskId;
return m_ipc->sendTask(taskId);
}
IpcMsg getIpcMsg(int32_t waitSeconds, std::string& result) {
IpcMsg msg = m_ipc->getIpcMsg(waitSeconds, result);
if (msg == IPC_DONE) m_busy = false;
return msg;
}
IpcMsg getIpcMsg(int32_t waitSeconds) {
IpcMsg msg = m_ipc->getIpcMsg(waitSeconds);
if (msg == IPC_DONE) m_busy = false;
return msg;
}
const char* getHost() { return m_host; }
void setHost(const char* host) {
if (host != NULL) {
if (m_host != NULL) free(m_host);
m_host = strdup(host);
}
}
void start();
void kill();
// void killAll( std::string & host );
bool runsTasks() { return m_runsTasks; }
}; // TaskClient
} // namespace testframework
} // namespace client
} // namespace geode
} // namespace apache
#endif // APACHE_GEODE_GUARD_a7058f04d2a065ec8cd9179a5349a649