I'm surprised to still see this sort of thing:
-string +const char* host_get_architecture() { - return Platform::instance()->getArchitecture(); + return Platform::instance()->getArchitecture().c_str(); }
I don't think you want to be returning a const char *, thats going to be problematic for any property that might change. But mainly I would have expected something closer to:
char* host_get_architecture() { #ifdef LINUX /* Do something with /proc/cpuinfo */ #else /* windows stuff */ #endif }
And:
LinuxPlatform::getArchitecture() { return host_get_architecture(); }
Is that coming in a subsequent patch?
On Fri, Jun 11, 2010 at 10:11 PM, Darryl L. Pierce dpierce@redhat.com wrote:
Since we're steering the total codebase (except the QMF transport) away from C++, this piece needed to be replaced. So this patch introduces a singly linked list that holds the registered functions that receive callbacks on heartbeat events.
Signed-off-by: Darryl L. Pierce dpierce@redhat.com
configure.ac | 1 + src/host.cpp | 94 ++++++++++++++++++++++++++++++++++--------------- src/host.h | 21 ++++------- src/hostlistener.h | 34 ------------------ src/main.cpp | 13 ++++++- src/qmf/hostagent.cpp | 7 +--- src/qmf/hostagent.h | 3 +- 7 files changed, 88 insertions(+), 85 deletions(-) delete mode 100644 src/hostlistener.h
diff --git a/configure.ac b/configure.ac index 3481c09..658fee3 100644 --- a/configure.ac +++ b/configure.ac @@ -6,6 +6,7 @@ AM_INIT_AUTOMAKE # Checks for programs. AC_PROG_CXX AC_PROG_CC +AM_PROG_CC_C_O AC_PROG_CPP
AC_CHECK_PROG(HASQMFGEN, qmf-gen, "yes") diff --git a/src/host.cpp b/src/host.cpp index 39655d2..a826545 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -20,23 +20,66 @@ #include "host.h"
#include "platform.h" -#include <set>
-using namespace std; +typedef struct _heartbeat_listener +{
- t_host_heartbeat_callback listener;
- _heartbeat_listener* next;
+} t_heartbeat_listener;
+t_heartbeat_listener* listeners = NULL;
-set<HostListener*> _listeners; -unsigned int _heartbeat_sequence; +unsigned int _heartbeat_sequence = 0;
void -host_register_listener(HostListener* listener) +host_register_listener(t_host_heartbeat_callback listener) {
- _listeners.insert(listener);
- t_heartbeat_listener* current = new t_heartbeat_listener;
- current->listener = listener;
- current->next = NULL;
- if(listeners)
- {
- t_heartbeat_listener* tail = listeners;
- while(tail->next) tail = tail->next;
- tail->next = current;
- }
- else
- {
- listeners = current;
- }
}
void -host_remove_listener(HostListener* listener) +host_remove_listener(t_host_heartbeat_callback listener) {
- _listeners.erase(listener);
- t_heartbeat_listener* current = listeners;
- t_heartbeat_listener* last = NULL;
- while(current)
- {
- if (current->listener == listener)
- {
- if(current == listeners)
- {
- listeners = current->next;
- }
- else
- {
- last->next = current->next;
- current->next = NULL;
- }
- delete current;
- current = NULL;
- }
- else
- {
- last = current;
- current = current->next;
- }
- }
}
void @@ -47,44 +90,37 @@ host_update_event() time_t __time; time(&__time);
- for(set<HostListener*>::iterator iter = _listeners.begin();
- iter != _listeners.end();
- iter++)
- {
- (*iter)->heartbeat((unsigned long)__time,
- _heartbeat_sequence);
- }
- t_heartbeat_listener* current = listeners;
- for(set<HostListener*>::iterator iter = _listeners.begin();
- iter != _listeners.end();
- iter++)
- while(current)
{
- (*iter)->updated();
- current->listener((unsigned long)time, _heartbeat_sequence);
- current = current->next;
} }
-string +const char* host_get_uuid() {
- return Platform::instance()->getUUID();
- return Platform::instance()->getUUID().c_str();
}
-string +const char* host_get_hostname() {
- return Platform::instance()->getHostname();
- return Platform::instance()->getHostname().c_str();
}
-string +const char* host_get_hypervisor() {
- return Platform::instance()->getHypervisor();
- return Platform::instance()->getHypervisor().c_str();
}
-string +const char* host_get_architecture() {
- return Platform::instance()->getArchitecture();
- return Platform::instance()->getArchitecture().c_str();
}
unsigned int @@ -93,10 +129,10 @@ host_get_memory() return Platform::instance()->getMemory(); }
-string +const char* host_get_cpu_model() {
- return Platform::instance()->getCPUModel();
- return Platform::instance()->getCPUModel().c_str();
}
unsigned int diff --git a/src/host.h b/src/host.h index dab88ad..530107c 100644 --- a/src/host.h +++ b/src/host.h @@ -20,30 +20,25 @@ * also available at http://www.gnu.org/copyleft/gpl.html. */
-#include <string> -#include <set> +typedef void(*t_host_heartbeat_callback)(unsigned long, unsigned int);
-#include "hostlistener.h" +void host_register_listener(t_host_heartbeat_callback listener);
-using namespace std;
-void host_register_listener(HostListener* listener);
-void host_remove_istener(HostListener* listener); +void host_remove_istener(t_host_heartbeat_callback listener);
void host_update_event();
-string host_get_uuid(); +const char* host_get_uuid();
-string host_get_hostname(); +const char* host_get_hostname();
-string host_get_hypervisor(); +const char* host_get_hypervisor();
-string host_get_architecture(); +const char* host_get_architecture();
unsigned int host_get_memory();
-string host_get_cpu_model(); +const char* host_get_cpu_model();
unsigned int host_get_number_of_cpu_cores();
diff --git a/src/hostlistener.h b/src/hostlistener.h deleted file mode 100644 index 307ab92..0000000 --- a/src/hostlistener.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __HOSTLISTENER_H -#define __HOSTLISTENER_H
-/* hostlistener.h - Copyright (C) 2009 Red Hat, Inc.
- Written by Darryl Pierce dpierce@redhat.com.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 2 of the License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- MA 02110-1301, USA. A copy of the GNU General Public License is
- also available at http://www.gnu.org/copyleft/gpl.html.
- */
-/*
- HostListener defines a type which receives notification
- whenever a Host event occurs.
- */
-class HostListener -{
- public:
- virtual void heartbeat(unsigned long timestamp, unsigned int sequence) = 0;
- virtual void updated() = 0;
-};
-#endif diff --git a/src/main.cpp b/src/main.cpp index c0ffd94..d7f2b0a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,8 @@ namespace _qmf = qmf::com::redhat::matahari; // Global Variables ManagementAgent::Singleton* singleton;
+HostAgent _hostagent;
void shutdown(int /*signal*/) { @@ -64,6 +66,12 @@ print_usage() printf("\t-p | --port specify broker port.\n"); }
+void +sendHeartbeatToQmf(unsigned long timestamp, unsigned int sequence) +{
- _hostagent.heartbeat(timestamp, sequence);
+}
int main(int argc, char **argv) { @@ -77,9 +85,10 @@ main(int argc, char **argv) char *service = NULL; int serverport = 5672;
- host_register_listener(sendHeartbeatToQmf);
ConnectionSettings settings; ManagementAgent *agent;
- HostAgent hostAgent;
struct option opt[] = { {"help", no_argument, NULL, 'h'}, @@ -181,7 +190,7 @@ main(int argc, char **argv) agent->init(settings, 5, false, ".magentdata");
// Get the info and post it to the broker
- hostAgent.setup(agent);
- _hostagent.setup(agent);
while(1) { diff --git a/src/qmf/hostagent.cpp b/src/qmf/hostagent.cpp index 682ad1c..ba74c61 100644 --- a/src/qmf/hostagent.cpp +++ b/src/qmf/hostagent.cpp @@ -23,13 +23,10 @@ #include "qmf/com/redhat/matahari/EventHeartbeat.h"
HostAgent::HostAgent() -{
- host_register_listener(this);
-} +{ }
HostAgent::~HostAgent() -{ -} +{ }
void HostAgent::setup(ManagementAgent* agent) diff --git a/src/qmf/hostagent.h b/src/qmf/hostagent.h index 7f7bbaa..6744400 100644 --- a/src/qmf/hostagent.h +++ b/src/qmf/hostagent.h @@ -24,7 +24,6 @@ #include <string>
#include "host.h" -#include "hostlistener.h"
#include "qmf/com/redhat/matahari/Host.h"
@@ -33,7 +32,7 @@ using namespace std;
namespace _qmf = qmf::com::redhat::matahari;
-class HostAgent : public Manageable, public HostListener +class HostAgent : public Manageable { private: _qmf::Host* _management_object; -- 1.7.0.1
Matahari mailing list Matahari@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/matahari