[PATCH 0/3] Add doxygen infrastructure
by russell@russellbryant.net
Add infrastructure for generating API documentation with doxygen. The docs
are generated by runing "make doxygen" from the top level directory. You must
have doxygen and graphviz installed.
To see the current docs without generating them yourself, see:
http://russellbryant.net/matahari/
[PATCH 1/3] GNUmakefile: Add doxygen target.
[PATCH 2/3] Doxyfile.in: Add doxygen configuration file
[PATCH 3/3] doxygen: Spice up generated docs.
GNUmakefile | 32
doc/.gitignore | 2
doc/Doxyfile.in | 1720 +++++++++++++++++++++++++++++++++++++++
src/include/matahari/host.h | 12
src/include/matahari/logging.h | 6
src/include/matahari/mainloop.h | 7
src/include/matahari/mh_agent.h | 6
src/include/matahari/network.h | 12
src/include/matahari/services.h | 11
src/include/matahari/utilities.h | 9
10 files changed, 1807 insertions(+), 10 deletions(-)
13 years
[PATCH] Add tags to gitignore.
by russell@russellbryant.net
Add 'tags' to the gitignore file. This file is generated by ctags.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
.gitignore | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 3ecf135..d9c0808 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@ build-win
src/include/matahari.h
src/matahari-*
linux.build
+tags
--
1.7.4.4
13 years
[PATCH 1/2] mh_agent.cpp: formatting changes.
by russell@russellbryant.net
Use spaces for indentation and strip trailing whitespace.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/mh_agent.cpp | 278 +++++++++++++++++++++++++-------------------------
1 files changed, 139 insertions(+), 139 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 3f72d0f..a71925b 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -5,12 +5,12 @@
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This software 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -64,21 +64,21 @@ RegistryRead (HKEY hHive, const wchar_t *szKeyPath, const wchar_t *szValue, char
DWORD nSize = BUFFER_SIZE;
wchar_t szData[BUFFER_SIZE];
long lSuccess = RegOpenKey (hHive, szKeyPath, &hKey);
-
+
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not open %ls key from the registry: %ld", szKeyPath, lSuccess);
- return;
+ mh_debug("Could not open %ls key from the registry: %ld", szKeyPath, lSuccess);
+ return;
}
-
+
lSuccess = RegQueryValueEx (hKey, szValue, NULL, NULL, (LPBYTE) szData, &nSize);
if (lSuccess != ERROR_SUCCESS) {
- mh_debug("Could not read '%ls[%ls]' from the registry: %ld", szKeyPath, szValue, lSuccess);
- return;
+ mh_debug("Could not read '%ls[%ls]' from the registry: %ld", szKeyPath, szValue, lSuccess);
+ return;
}
mh_info("Obtained '%ls[%ls]' = '%ls' from the registry", szKeyPath, szValue, szData);
if(out) {
- *out = (char *)malloc( BUFFER_SIZE );
- wcstombs(*out, szData, (size_t)BUFFER_SIZE);
+ *out = (char *)malloc( BUFFER_SIZE );
+ wcstombs(*out, szData, (size_t)BUFFER_SIZE);
}
}
#else
@@ -109,15 +109,15 @@ print_usage(const char *proc_name)
}
#endif
-static gboolean
+static gboolean
mh_qpid_callback(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data)
{
MatahariAgent *agent = (MatahariAgent*) user_data;
mh_trace("Qpid message recieved");
if(event.hasDataAddr()) {
- mh_trace("Message is for %s (type: %s)",
- event.getDataAddr().getName().c_str(),
- event.getDataAddr().getAgentName().c_str());
+ mh_trace("Message is for %s (type: %s)",
+ event.getDataAddr().getName().c_str(),
+ event.getDataAddr().getAgentName().c_str());
}
return agent->invoke(session, event, user_data);
}
@@ -149,129 +149,129 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
qpid::management::ConnectionSettings settings;
/* Set up basic logging */
- mh_log_init(proc_name, LOG_INFO, FALSE);
+ mh_log_init(proc_name, LOG_INFO, FALSE);
#ifdef WIN32
RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"DebugLevel",
- &value);
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"DebugLevel",
+ &value);
if(value) {
- mh_log_level = LOG_INFO+atoi(value);
- free(value);
- value = NULL;
+ mh_log_level = LOG_INFO+atoi(value);
+ free(value);
+ value = NULL;
}
-
+
RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Broker",
- &servername);
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Broker",
+ &servername);
RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Port",
- &value);
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Port",
+ &value);
if(value) {
- serverport = atoi(value);
- free(value);
- value = NULL;
+ serverport = atoi(value);
+ free(value);
+ value = NULL;
}
RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Service",
- &service);
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Service",
+ &service);
RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"User",
- &username);
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"User",
+ &username);
RegistryRead (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\services\\Matahari",
- L"Password",
- &password);
-
+ HKEY_LOCAL_MACHINE,
+ L"SYSTEM\\CurrentControlSet\\services\\Matahari",
+ L"Password",
+ &password);
+
#else
-
+
// Get args
while ((arg = getopt_long(argc, argv, "hdb:gu:P:s:p:v", opt, &idx)) != -1) {
- switch (arg) {
- case 'h':
- case '?':
- print_usage(proc_name);
- exit(0);
- break;
- case 'd':
- daemonize = true;
- break;
- case 'v':
- mh_log_level++;
- mh_enable_stderr(1);
- break;
- case 's':
- if (optarg) {
- service = strdup(optarg);
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'u':
- if (optarg) {
- username = strdup(optarg);
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'P':
- if (optarg) {
- password = strdup(optarg);
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'g':
- gssapi = true;
- break;
- case 'p':
- if (optarg) {
- serverport = atoi(optarg);
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- case 'b':
- if (optarg) {
- servername = strdup(optarg);
- } else {
- print_usage(proc_name);
- exit(1);
- }
- break;
- default:
- fprintf(stderr, "unsupported option '-%c'. See --help.\n", arg);
- print_usage(proc_name);
- exit(0);
- break;
- }
+ switch (arg) {
+ case 'h':
+ case '?':
+ print_usage(proc_name);
+ exit(0);
+ break;
+ case 'd':
+ daemonize = true;
+ break;
+ case 'v':
+ mh_log_level++;
+ mh_enable_stderr(1);
+ break;
+ case 's':
+ if (optarg) {
+ service = strdup(optarg);
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'u':
+ if (optarg) {
+ username = strdup(optarg);
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'P':
+ if (optarg) {
+ password = strdup(optarg);
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'g':
+ gssapi = true;
+ break;
+ case 'p':
+ if (optarg) {
+ serverport = atoi(optarg);
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ case 'b':
+ if (optarg) {
+ servername = strdup(optarg);
+ } else {
+ print_usage(proc_name);
+ exit(1);
+ }
+ break;
+ default:
+ fprintf(stderr, "unsupported option '-%c'. See --help.\n", arg);
+ print_usage(proc_name);
+ exit(0);
+ break;
+ }
}
if (daemonize == true) {
- if (daemon(0, 0) < 0) {
- fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
- exit(1);
- }
+ if (daemon(0, 0) < 0) {
+ fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
+ exit(1);
+ }
}
#endif
@@ -291,16 +291,16 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
qpid::types::Variant::Map options;
options["reconnect"] = bool(true);
if (username) {
- options["username"] = username;
+ options["username"] = username;
}
if (password) {
- options["password"] = password;
+ options["password"] = password;
}
if (service) {
- options["sasl-service"] = service;
+ options["sasl-service"] = service;
}
if (gssapi) {
- options["sasl-mechanism"] = "GSSAPI";
+ options["sasl-mechanism"] = "GSSAPI";
}
std::stringstream url;
@@ -318,14 +318,14 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
/* Do any setup required by our agent */
if(this->setup(_agent_session) < 0) {
- mh_err("Failed to set up broker connection to %s on %d for %s\n",
- servername, serverport, proc_name);
- return -1;
+ mh_err("Failed to set up broker connection to %s on %d for %s\n",
+ servername, serverport, proc_name);
+ return -1;
}
this->mainloop = g_main_new(FALSE);
this->qpid_source = mainloop_add_qmf(
- G_PRIORITY_HIGH, _agent_session, mh_qpid_callback, mh_qpid_disconnect, this);
+ G_PRIORITY_HIGH, _agent_session, mh_qpid_callback, mh_qpid_disconnect, this);
return 0;
}
@@ -342,9 +342,9 @@ mainloop_qmf_prepare(GSource* source, gint *timeout)
{
mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
if (qmf->event) {
- return TRUE;
+ return TRUE;
}
-
+
*timeout = 1;
return FALSE;
}
@@ -354,10 +354,10 @@ mainloop_qmf_check(GSource* source)
{
mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
if (qmf->event) {
- return TRUE;
+ return TRUE;
} else if(qmf->session.nextEvent(qmf->event, qpid::messaging::Duration::IMMEDIATE)) {
- return TRUE;
+ return TRUE;
}
return FALSE;
}
@@ -368,15 +368,15 @@ mainloop_qmf_dispatch(GSource *source, GSourceFunc callback, gpointer userdata)
mainloop_qmf_t *qmf = (mainloop_qmf_t*)source;
mh_trace("%p", source);
if (qmf->dispatch != NULL) {
- qmf::AgentEvent event = qmf->event;
- qmf->event = NULL;
-
- if(qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
- g_source_unref(source); /* Really? */
- return FALSE;
- }
+ qmf::AgentEvent event = qmf->event;
+ qmf->event = NULL;
+
+ if(qmf->dispatch(qmf->session, event, qmf->user_data) == FALSE) {
+ g_source_unref(source); /* Really? */
+ return FALSE;
+ }
}
-
+
return TRUE;
}
@@ -387,7 +387,7 @@ mainloop_qmf_destroy(GSource* source)
mh_trace("%p", source);
if (qmf->dnotify) {
- qmf->dnotify(qmf->user_data);
+ qmf->dnotify(qmf->user_data);
}
}
@@ -400,8 +400,8 @@ static GSourceFuncs mainloop_qmf_funcs = {
mainloop_qmf_t*
mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer userdata),
- GDestroyNotify notify, gpointer userdata)
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer userdata),
+ GDestroyNotify notify, gpointer userdata)
{
GSource *source = NULL;
mainloop_qmf_t *qmf_source = NULL;
@@ -424,7 +424,7 @@ mainloop_add_qmf(int priority, qmf::AgentSession session,
g_source_set_priority(source, priority);
g_source_set_can_recurse(source, FALSE);
-
+
qmf_source->id = g_source_attach(source, NULL);
mh_info("Added source: %d", qmf_source->id);
return qmf_source;
@@ -436,6 +436,6 @@ mainloop_destroy_qmf(mainloop_qmf_t* source)
g_source_remove(source->id);
source->id = 0;
g_source_unref((GSource*)source);
-
+
return TRUE;
}
--
1.7.4.4
13 years
[PATCH] Mark virtual functions as virtual.
by russell@russellbryant.net
The init() and invoke() functions are virtual. Mark them as such in the
classes that derive from MatahariAgent to make that more clear. There
are no functional changes here.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/host/matahari-host.cpp | 5 +++--
src/net/matahari-net.cpp | 5 +++--
src/service/matahari-srv.cpp | 5 +++--
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/host/matahari-host.cpp b/src/host/matahari-host.cpp
index d405ded..7e42002 100644
--- a/src/host/matahari-host.cpp
+++ b/src/host/matahari-host.cpp
@@ -38,8 +38,9 @@ class HostAgent : public MatahariAgent
{
public:
int heartbeat();
- int setup(qmf::AgentSession session);
- gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
};
static gboolean heartbeat_timer(gpointer data)
diff --git a/src/net/matahari-net.cpp b/src/net/matahari-net.cpp
index 1cd02b7..87e8fee 100644
--- a/src/net/matahari-net.cpp
+++ b/src/net/matahari-net.cpp
@@ -47,8 +47,9 @@ extern "C" {
class NetAgent : public MatahariAgent
{
public:
- int setup(qmf::AgentSession session);
- gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
};
int
diff --git a/src/service/matahari-srv.cpp b/src/service/matahari-srv.cpp
index fc2b00f..426426c 100644
--- a/src/service/matahari-srv.cpp
+++ b/src/service/matahari-srv.cpp
@@ -50,8 +50,9 @@ class SrvAgent : public MatahariAgent
public:
void raiseEvent(svc_action_t *op, int service);
- int setup(qmf::AgentSession session);
- gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
+ virtual int setup(qmf::AgentSession session);
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
+ gpointer user_data);
};
--
1.7.4.4
13 years
[PATCH] mh_agent.h: formatting changes.
by russell@russellbryant.net
Use spaces for indentation and strip some trailing whitespace. Also,
list public members of MatahariAgent before protected.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/include/matahari/mh_agent.h | 42 ++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 62c5aef..50fd85f 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -40,27 +40,34 @@ using namespace std;
namespace _qmf = qmf::org::matahariproject;
namespace _qtype = ::qpid::types;
-typedef struct mainloop_qmf_s
-{
- GSource source;
- qmf::AgentSession session;
- qmf::AgentEvent event;
- guint id;
- void *user_data;
- GDestroyNotify dnotify;
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
-
+typedef struct mainloop_qmf_s {
+ GSource source;
+ qmf::AgentSession session;
+ qmf::AgentEvent event;
+ guint id;
+ void *user_data;
+ GDestroyNotify dnotify;
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data);
} mainloop_qmf_t;
extern mainloop_qmf_t *mainloop_add_qmf(int priority, qmf::AgentSession session,
- gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer userdata),
- GDestroyNotify notify, gpointer userdata);
+ gboolean (*dispatch)(qmf::AgentSession session, qmf::AgentEvent event, gpointer userdata),
+ GDestroyNotify notify, gpointer userdata);
extern gboolean mainloop_destroy_qmf(mainloop_qmf_t* source);
class MatahariAgent
{
- protected:
+public:
+ MatahariAgent() {};
+ ~MatahariAgent() {};
+
+ virtual int setup(qmf::AgentSession session) { return 0; };
+ virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) { return FALSE; };
+ int init(int argc, char **argv, const char* proc_name);
+ void run();
+
+protected:
GMainLoop *mainloop;
mainloop_qmf_t *qpid_source;
@@ -68,15 +75,6 @@ class MatahariAgent
qmf::AgentSession _agent_session;
qpid::messaging::Connection _amqp_connection;
qmf::org::matahariproject::PackageDefinition _package;
-
- public:
- MatahariAgent() {};
- ~MatahariAgent() {};
-
- virtual int setup(qmf::AgentSession session) { return 0; };
- virtual gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer user_data) { return FALSE; };
- int init(int argc, char **argv, const char* proc_name);
- void run();
};
#endif // __MATAHARI_DAEMON_H
--
1.7.4.4
13 years
[PATCH] Allow a "make clean" from the top level dir.
by russell@russellbryant.net
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
GNUmakefile | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index 8cf41cf..cad193c 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -98,4 +98,11 @@ rpm-win:
mock-win:
make PROFILE=$(PROFILE) VARIANT=mingw32- srpm mock-nodeps
-.PHONY: check linux.build windows.build
+clean:
+ @if [ -d linux.build ] ; then \
+ $(MAKE) --no-print-dir -C linux.build clean ; \
+ elif [ -d windows.build ] ; then \
+ $(MAKE) --no-print-dir -C windows.build clean ; \
+ fi
+
+.PHONY: check linux.build windows.build clean
--
1.7.4.4
13 years
[PATCH] MatahariAgent: fix memory leaks, removed unused object
by russell@russellbryant.net
1) Resolve some memory leaks in places where strdup() was being
used but was not cleaned up. These strings were converted to
std::string.
2) Remove an object from MatahariAgent::init() that was unused.
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/mh_agent.cpp | 83 ++++++++++++++++++++++++++++++++------------------
1 files changed, 53 insertions(+), 30 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 3f72d0f..e103dc1 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -140,13 +140,11 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
#endif
bool gssapi = false;
- char *servername = strdup(MATAHARI_BROKER);
- char *username = NULL;
- char *password = NULL;
- char *service = NULL;
- int serverport = MATAHARI_PORT;
-
- qpid::management::ConnectionSettings settings;
+ string servername;
+ string username;
+ string password;
+ string service;
+ int serverport = MATAHARI_PORT;
/* Set up basic logging */
mh_log_init(proc_name, LOG_INFO, FALSE);
@@ -168,7 +166,13 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\services\\Matahari",
L"Broker",
- &servername);
+ &value);
+
+ if(value) {
+ servername = value;
+ free(value);
+ value = NULL;
+ }
RegistryRead (
HKEY_LOCAL_MACHINE,
@@ -186,19 +190,38 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\services\\Matahari",
L"Service",
- &service);
+ &value);
+
+ if(value) {
+ service = value;
+ free(value);
+ value = NULL;
+ }
RegistryRead (
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\services\\Matahari",
L"User",
- &username);
+ &value);
+
+ if(value) {
+ username = value;
+ free(value);
+ value = NULL;
+ }
+
RegistryRead (
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\services\\Matahari",
L"Password",
- &password);
-
+ &value);
+
+ if(value) {
+ password = value;
+ free(value);
+ value = NULL;
+ }
+
#else
// Get args
@@ -218,7 +241,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
break;
case 's':
if (optarg) {
- service = strdup(optarg);
+ service = optarg;
} else {
print_usage(proc_name);
exit(1);
@@ -226,7 +249,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
break;
case 'u':
if (optarg) {
- username = strdup(optarg);
+ username = optarg;
} else {
print_usage(proc_name);
exit(1);
@@ -234,7 +257,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
break;
case 'P':
if (optarg) {
- password = strdup(optarg);
+ password = optarg;
} else {
print_usage(proc_name);
exit(1);
@@ -253,7 +276,7 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
break;
case 'b':
if (optarg) {
- servername = strdup(optarg);
+ servername = optarg;
} else {
print_usage(proc_name);
exit(1);
@@ -275,29 +298,27 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
}
#endif
+ if (servername.length() == 0) {
+ servername = MATAHARI_BROKER;
+ }
+
/* Re-initialize logging now that we've completed option processing */
mh_log_init(proc_name, mh_log_level, mh_log_level > LOG_INFO);
// Set up the cleanup handler for sigint
signal(SIGINT, shutdown);
- // Connect to the broker
- settings.host = servername;
- settings.port = serverport;
-
- mh_info("Connecting to Qpid broker at %s on port %d", servername, serverport);
-
// Create a v2 API options map.
qpid::types::Variant::Map options;
options["reconnect"] = bool(true);
- if (username) {
- options["username"] = username;
+ if (!username.empty()) {
+ options["username"] = username.c_str();
}
- if (password) {
- options["password"] = password;
+ if (!password.empty()) {
+ options["password"] = password.c_str();
}
- if (service) {
- options["sasl-service"] = service;
+ if (!service.empty()) {
+ options["sasl-service"] = service.c_str();
}
if (gssapi) {
options["sasl-mechanism"] = "GSSAPI";
@@ -306,6 +327,8 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
std::stringstream url;
url << servername << ":" << serverport ;
+ mh_info("Connecting to Qpid broker at %s", url.str().c_str());
+
_amqp_connection = qpid::messaging::Connection(url.str(), options);
_amqp_connection.open();
@@ -318,8 +341,8 @@ MatahariAgent::init(int argc, char **argv, const char* proc_name)
/* Do any setup required by our agent */
if(this->setup(_agent_session) < 0) {
- mh_err("Failed to set up broker connection to %s on %d for %s\n",
- servername, serverport, proc_name);
+ mh_err("Failed to set up broker connection to %s for %s\n",
+ url.str().c_str(), proc_name);
return -1;
}
--
1.7.4
13 years
Fwd: Forw: matahari: comparing Sigar and PCP for data gathering
by Andrew Beekhof
Sorry, somehow I took this off-list.
Resending to add those lists back.
---------- Forwarded message ----------
From: Andrew Beekhof <andrew(a)beekhof.net>
Date: Wed, Apr 6, 2011 at 1:45 PM
Subject: Re: [Matahari] Forw: matahari: comparing Sigar and PCP for
data gathering
To: "Frank Ch. Eigler" <fche(a)redhat.com>
On Tue, Apr 5, 2011 at 5:17 PM, Frank Ch. Eigler <fche(a)redhat.com> wrote:
> I believe this represents a mapping between the Sigar stuff used by
> matahari, and what's available from equivalent local PCP sources. The
> PCP API, being a little more generic, is a little more wordy than
> Sigar, but not too much so. The only nontrivial amount of work here
> appears to be the network-interface metadata, which is rather richer
> in Sigar than in PCP.
>
> The design of PCP makes it straightforward to extend it with data
> sources like this via out-of-tree PMDAs, so no change of the PCP core
> code is required to add the missing data. OTOH the PCP people are
> friendly to contributions, so merging such things into the master tree
> would probably not be a big deal.
>
> Thanks for reading through all this. Any questions?
First up, thankyou for the very detailed analysis.
The challenge, from my perspective, is not so much "does PCP check the
same boxes as Sigar" but more "Is there something compelling in PCP
that makes the migration work worthwhile".
To date, I'd have to say no.
That said, and in contrast to what you're saying about PCP, Sigar
upstream is not exactly responsive.
So depending on what level of frustration we reach trying to get out
windows device name patch merged, this may well provide sufficient
justification to switch.
On that topic, how does PCP represent/name network interfaces on Windows?
Sigar maps everything to the ethX naming standard - which is utterly
useless as windows exposes two virtual devices for every real one
(that deal with routing or something). So far we're having trouble
getting many replies out of the Sigar people.
-- Andrew
13 years
[PATCH] CMake changes
by Radek Novacek
I finally finished reworking cmake. The patch is "little" messy but it now
supports disabling QMF/DBus parts. Compilation was moved from
src/CMakeList.txt to subdirectories. All shared libraries (mhost, msrv, mnet,
mcommon, mcommon_qmf, mcommon_dbus) are now built in the libs/, both QMF and
DBus agents are built in agent's subdirectory (e.g. in src/host/ the matahari-
qmf-hostd and matahari-dbus-hostd are built).
Another feature is ability of build independent agent on the top of Matahari
infrastructure. To achieve this it was necessary to create mcommon_qmf and
mcommon_dbus shared libraries. Also _package variable had to be moved from
MatahariAgent class to all subclasses because it is generated from schema and
not universal. Separate agents can use FindMatahari.cmake module for finding
Matahari.
I also created pull request on github, so you can look on changes there or
look on commits here:
https://github.com/rnovacek/matahari/commits/cmake
Radek Novacek
src/CMakeLists.txt | 284
++++++++------------
src/cmake/modules/FindMatahari.cmake | 47 ++++
.../{DBusMacros.cmake => MatahariDBusMacros.cmake} | 21 +-
src/host/CMakeLists.txt | 89 ++++---
src/host/matahari-host-dbus.c | 2 +-
src/host/matahari-host.cpp | 4 +
src/include/matahari/mh_agent.h | 5 +-
src/{common => include/matahari}/mh_dbus_common.h | 0
.../matahari}/mh_gobject_class.h | 0
src/lib/CMakeLists.txt | 72 +++++
src/lib/mh_agent.cpp | 3 +-
src/{common => lib}/mh_dbus_common.c | 2 +-
src/net/CMakeLists.txt | 94 ++++---
src/net/matahari-net.cpp | 4 +
src/net/matahari-network-dbus.c | 2 +-
src/service/CMakeLists.txt | 94 ++++---
src/service/matahari-services-dbus.c | 2 +-
src/service/matahari-srv.cpp | 7 +-
18 files changed, 422 insertions(+), 310 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cf2e789..9fc902a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,19 +12,14 @@ if(WIN32)
else(WIN32)
set(VARIANT "linux")
+ # DBus makes sense only on linux
+ option(WITH-DBUS "Build the DBus daemon" ON)
endif(WIN32)
+option(WITH-QMF "Build the QMF daemon" ON)
set(CMAKE_C_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS "-Wall")
-set(MCOMMON_VERSION 0.0.1)
-set(MHOST_VERSION 0.0.1)
-set(MSRV_VERSION 0.0.1)
-set(MNET_VERSION 0.0.1)
-
-option(WITH-QMF "Build the QMF daemon" ON)
-option(WITH-DBUS "Build the DBus daemon" ON)
-
include(FindPkgConfig)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
@@ -33,73 +28,8 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
${CMAKE_MODULE_PATH} )
-# set service name var's
-set(M_HOST "matahari-hostd")
-set(M_NET "matahari-netd")
-set(M_SRV "matahari-serviced")
-
-set(DAEMONS ${M_HOST} ${M_NET} ${M_SRV})
-
file(GLOB SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/*.xml")
-# Defines
-add_definitions(-DSUPPORT_TRACING=${SUPPORT_TRACING})
-add_definitions(-DMATAHARI_PORT=${MATAHARI_PORT})
-add_definitions(-DMATAHARI_BROKER="${MATAHARI_BROKER}")
-
-# Build targets
-## Schema
-set(SCHEMA_SOURCES
- ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Host.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Network.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Services.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Resources.cpp
-
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/EventHeartbeat.cpp
-
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/EventService_op.cpp
-
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/EventResource_op.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Package.cpp)
-
-## Libraries and Common code
-set(COMMON_SOURCES lib/mh_agent.cpp)
-
-add_library (mcommon SHARED lib/utilities.c lib/mainloop.c)
-set_target_properties(mcommon PROPERTIES SOVERSION ${MCOMMON_VERSION})
-
-add_library (mhost SHARED lib/host.c lib/host_${VARIANT}.c)
-set_target_properties(mhost PROPERTIES SOVERSION ${MHOST_VERSION})
-target_link_libraries(mhost mcommon)
-
-add_library (msrv SHARED lib/services.c lib/services_${VARIANT}.c)
-set_target_properties(msrv PROPERTIES SOVERSION ${MSRV_VERSION})
-target_link_libraries(msrv mcommon)
-
-add_library (mnet SHARED lib/network.c lib/network_${VARIANT}.c)
-set_target_properties(mnet PROPERTIES SOVERSION ${MNET_VERSION})
-target_link_libraries(mnet mcommon)
-
-if(WIN32)
- target_link_libraries(mhost wsock32)
- target_link_libraries(mcommon wsock32)
-endif(WIN32)
-
-## Daemons
-add_executable(${M_HOST} host/matahari-host.cpp ${SCHEMA_SOURCES}
${COMMON_SOURCES} )
-target_link_libraries(${M_HOST} mhost)
-
-add_executable(${M_NET} net/matahari-net.cpp ${SCHEMA_SOURCES}
${COMMON_SOURCES})
-target_link_libraries(${M_NET} mnet)
-
-add_executable(${M_SRV} service/matahari-srv.cpp ${SCHEMA_SOURCES}
${COMMON_SOURCES})
-target_link_libraries(${M_SRV} msrv)
-
-foreach(daemon ${DAEMONS})
- target_link_libraries(${daemon} mcommon)
- if(WIN32)
- target_link_libraries(${daemon} wsock32)
- endif(WIN32)
-endforeach(daemon ${DAEMONS})
-
# Configure checks
## Includes
include (CheckIncludeFiles)
@@ -108,123 +38,141 @@ check_include_files (sys/ioctl.h HAVE_SYS_IOCTL_H)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/include/matahari.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h)
-## Modules
-pkg_check_modules(glib REQUIRED glib-2.0)
-pkg_check_modules(pcre REQUIRED libpcre)
-pkg_check_modules(dbus-glib REQUIRED dbus-glib-1)
-pkg_check_modules(polkit REQUIRED polkit-gobject-1)
-
if(NOT PKG_CONFIG_FOUND)
message("pkg-config not found")
endif(NOT PKG_CONFIG_FOUND)
+## Modules
+# pcre
+pkg_check_modules(pcre REQUIRED libpcre)
if(NOT pcre_FOUND)
- IF(MSVC)
+ if(MSVC)
find_path(pcre_FOUND pcre.h "${PCRE_PATH}")
find_library(pcre_LIBRARIES pcre.lib "${PCRE_PATH}")
- ELSE(MSVC)
+ else(MSVC)
find_path(pcre_FOUND pcre.h)
find_library(pcre_LIBRARIES pcre)
- string(REPLACE "pcre.h" "" pcre_INCLUDE_DIRS ${pcre_FOUND})
+ string(REPLACE "pcre.h" "" pcre_INCLUDE_DIRS ${pcre_FOUND})
endif(MSVC)
string(REPLACE "pcre.h" "" pcre_INCLUDE_DIRS ${pcre_FOUND})
endif(NOT pcre_FOUND)
-if(pcre_FOUND)
- target_link_libraries(mhost ${pcre_LIBRARIES})
- include_directories(${pcre_INCLUDE_DIRS})
-else(pcre_FOUND)
+if(NOT pcre_FOUND)
message(FATAL_ERROR "PCRE header/library not found.")
-endif(pcre_FOUND)
-
-if(glib_FOUND)
- include_directories(${glib_INCLUDE_DIRS})
- foreach(daemon ${DAEMONS})
- target_link_libraries(${daemon} ${glib_LIBRARIES})
- endforeach(daemon ${DAEMONS})
- target_link_libraries(mcommon ${glib_LIBRARIES})
-else(glib_FOUND)
- message(FATAL_ERROR "Glib2 header/library not found.")
-endif(glib_FOUND)
-
-## dbus
+endif(NOT pcre_FOUND)
-# Create src/dbus directory and generate DBus XML definition files into it
-execute_process(COMMAND mkdir -p src/dbus)
-find_file(XSLTPROC xsltproc)
-execute_process(
- COMMAND ${XSLTPROC} ${CMAKE_CURRENT_SOURCE_DIR}/schema-to-dbus.xsl
${CMAKE_CURRENT_SOURCE_DIR}/schema.xml
- WORKING_DIRECTORY src/dbus
-)
+# Sigar
+find_library(SIGAR sigar)
+if(SIGAR-NOTFOUND)
+ message(FATAL_ERROR "SIGAR library not found.")
+endif(SIGAR-NOTFOUND)
+# GLib
+pkg_check_modules(glib REQUIRED glib-2.0)
+if(NOT glib_FOUND)
+ message(FATAL_ERROR "Glib2 header/library not found.")
+endif(NOT glib_FOUND)
+include_directories(${glib_INCLUDE_DIRS})
-### DBus
+## dbus
+if(WITH-DBUS)
+ pkg_check_modules(dbus-glib REQUIRED dbus-glib-1)
+ pkg_check_modules(polkit REQUIRED polkit-gobject-1)
+
+ if(NOT dbus-glib_FOUND)
+ message(FATAL_ERROR "dbus-glib headers/libraries not found.")
+ endif(NOT dbus-glib_FOUND)
+
+ if(NOT polkit_FOUND)
+ message(FATAL_ERROR "polkit headers/libraries not found.")
+ endif(NOT polkit_FOUND)
+
+ # Create src/dbus directory and generate DBus XML definition files into
it
+ execute_process(COMMAND mkdir -p src/dbus)
+ find_file(XSLTPROC xsltproc)
+ execute_process(
+ COMMAND ${XSLTPROC} ${CMAKE_CURRENT_SOURCE_DIR}/schema-to-dbus.xsl
${CMAKE_CURRENT_SOURCE_DIR}/schema.xml
+ WORKING_DIRECTORY src/dbus
+ )
+endif(WITH-DBUS)
+## qpid
+if(WITH-QMF)
+ # Defines
+ add_definitions(-DSUPPORT_TRACING=${SUPPORT_TRACING})
+ add_definitions(-DMATAHARI_PORT=${MATAHARI_PORT})
+ add_definitions(-DMATAHARI_BROKER="${MATAHARI_BROKER}")
+
+ set(SCHEMA_SOURCES
+ ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Host.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Network.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Services.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Resources.cpp
+
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/EventHeartbeat.cpp
+
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/EventService_op.cpp
+
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/EventResource_op.cpp
+
${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/QmfPackage.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/qmf/org/matahariproject/Package.cpp)
+
+
+ find_package(QPID REQUIRED)
+ if(QPID-NOTFOUND)
+ message(FATAL_ERROR "QPID library not found.")
+ endif(QPID-NOTFOUND)
+
+ string(REGEX REPLACE "\\." "" QPID_VERSION ${QPID_VERSION})
+
+ message("Building against: ${QPID_VERSION_LONG} (${QPID_VERSION} )")
+ add_definitions(-DQPID_VERSION=${QPID_VERSION})
+
+ set(regen_schema OFF)
+ message(STATUS "Regenerating QMF schemas: ${SCHEMAS}")
+ foreach (schema_file ${SCHEMAS} ${QMFGEN})
+ foreach (file ${SCHEMA_SOURCES})
+ if (EXISTS ${file})
+ if (${schema_file} IS_NEWER_THAN ${file})
+ set(regen_schema ON)
+ message("${schema_file} is newer than ${file}")
+ endif (${schema_file} IS_NEWER_THAN ${file})
+ else (EXISTS ${file})
+ set(regen_schema ON)
+ endif (EXISTS ${file})
+ endforeach (file ${SCHEMA_SOURCES})
+ endforeach (schema_file ${SCHEMAS})
+
+ if (regen_schema)
+ # Regenerate everything
+ execute_process(COMMAND rm -f ${SCHEMA_SOURCES})
+ execute_process(COMMAND ${QMFGEN} -o ./qmf ${SCHEMAS}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ execute_process(COMMAND ${QMFGEN} -2 -o ./qmf ${SCHEMAS}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ else (regen_schema)
+ message(STATUS "No need to generate QMF schema")
+ endif (regen_schema)
+endif(WITH-QMF)
+
+
+### Subdirectories
+add_subdirectory(lib)
add_subdirectory(host)
add_subdirectory(service)
add_subdirectory(net)
-## qpid
-
-find_package(QPID REQUIRED)
-
-## sigar
-find_library(SIGAR sigar)
-if(NOT_SIGAR)
- message(FATAL_ERROR "SIGAR library not found.")
-endif(NOT_SIGAR)
-
-target_link_libraries(mcommon ${SIGAR})
-target_link_libraries(mhost ${SIGAR})
-target_link_libraries(mnet ${SIGAR})
-
-string(REGEX REPLACE "\\." "" QPID_VERSION ${QPID_VERSION})
-
-message("Building against: ${QPID_VERSION_LONG} (${QPID_VERSION} )")
-add_definitions(-DQPID_VERSION=${QPID_VERSION})
-
-set(regen_schema OFF)
-message(STATUS "Regenerating QMF schemas: ${SCHEMAS}")
-foreach (schema_file ${SCHEMAS} ${QMFGEN})
- foreach (file ${SCHEMA_SOURCES})
- if (EXISTS ${file})
- if (${schema_file} IS_NEWER_THAN ${file})
- set(regen_schema ON)
- message("${schema_file} is newer than ${file}")
- endif (${schema_file} IS_NEWER_THAN ${file})
- else (EXISTS ${file})
- set(regen_schema ON)
- endif (EXISTS ${file})
- endforeach (file ${SCHEMA_SOURCES})
-endforeach (schema_file ${SCHEMAS})
-
-if (regen_schema)
- # Regenerate everything
- execute_process(COMMAND rm -f ${SCHEMA_SOURCES})
- execute_process(COMMAND ${QMFGEN} -o ./qmf ${SCHEMAS}
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
- execute_process(COMMAND ${QMFGEN} -2 -o ./qmf ${SCHEMAS}
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-else (regen_schema)
- message(STATUS "No need to generate QMF schema")
-endif (regen_schema)
-
-# Add QF libraries
-foreach(daemon ${DAEMONS})
- target_link_libraries(${daemon} ${QPIDCOMMON_LIBRARY}
${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
- IF(QPIDTYPES_FOUND)
- target_link_libraries(${daemon} ${QPIDTYPES_LIBRARY})
- ENDIF(QPIDTYPES_FOUND)
-endforeach(daemon ${DAEMONS})
-
-# Install targets
-install(TARGETS ${DAEMONS} DESTINATION sbin)
-
-if(WIN32)
-install(TARGETS mcommon mhost mnet msrv DESTINATION sbin)
-else(WIN32)
-install(TARGETS mcommon mhost mnet msrv DESTINATION lib${LIB_SUFFIX})
-endif(WIN32)
+### Installation
install(FILES ${SCHEMAS} DESTINATION share/matahari)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/matahari.h DESTINATION
include)
+install(FILES cmake/modules/FindMatahari.cmake DESTINATION
share/cmake/Modules)
+
+if(WITH-QMF)
+ install(FILES cmake/modules/FindQPID.cmake DESTINATION
share/cmake/Modules)
+ install(FILES include/matahari/mh_agent.h DESTINATION include/matahari)
+endif(WITH-QMF)
+
+if(WITH-DBUS)
+ install(FILES schema-to-dbus.xsl DESTINATION share/matahari)
+ install(FILES include/matahari/mh_dbus_common.h DESTINATION
include/matahari)
+ install(FILES include/matahari/mh_gobject_class.h DESTINATION
include/matahari)
+ install(FILES cmake/modules/MatahariDBusMacros.cmake DESTINATION
share/cmake/Modules)
+endif(WITH-DBUS)
diff --git a/src/cmake/modules/FindMatahari.cmake
b/src/cmake/modules/FindMatahari.cmake
new file mode 100644
index 0000000..942c9ff
--- /dev/null
+++ b/src/cmake/modules/FindMatahari.cmake
@@ -0,0 +1,47 @@
+
+find_path(MATAHARI_INCLUDE_DIR mh_agent.h
+ HINTS
+ $ENV{MATAHARI_DIR}
+ PATH_SUFFIXES include/matahari include
+ PATHS
+ /usr
+ /usr/local
+)
+
+find_library(MATAHARI_LIBRARY
+ NAMES mcommon
+ HINTS
+ $ENV{MATAHARI_DIR}
+ PATH_SUFFIXES lib64 lib
+ PATHS
+ /usr
+ /usr/local
+)
+
+find_library(MATAHARI_QMF_LIBRARY
+ NAMES mcommon_qmf
+ HINTS
+ $ENV{MATAHARI_DIR}
+ PATH_SUFFIXES lib64 lib
+ PATHS
+ /usr
+ /usr/local
+)
+
+find_library(MATAHARI_DBUS_LIBRARY
+ NAMES mcommon_dbus
+ HINTS
+ $ENV{MATAHARI_DIR}
+ PATH_SUFFIXES lib64 lib
+ PATHS
+ /usr
+ /usr/local
+)
+
+set(MATAHARI_QMF_LIBRARIES ${MATAHARI_LIBRARY} ${MATAHARI_QMF_LIBRARY})
+set(MATAHARI_DBUS_LIBRARIES ${MATAHARI_LIBRARY} ${MATAHARI_DBUS_LIBRARY})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Matahari DEFAULT_MSG MATAHARI_QMF_LIBRARIES
MATAHARI_DBUS_LIBRARIES MATAHARI_INCLUDE_DIR)
+
+mark_as_advanced(MATAHARI_INCLUDE_DIR MATAHARI_QMF_LIBRARIES
MATAHARI_DBUS_LIBRARIES)
diff --git a/src/cmake/modules/DBusMacros.cmake
b/src/cmake/modules/MatahariDBusMacros.cmake
similarity index 53%
rename from src/cmake/modules/DBusMacros.cmake
rename to src/cmake/modules/MatahariDBusMacros.cmake
index b8e7a28..92d350e 100644
--- a/src/cmake/modules/DBusMacros.cmake
+++ b/src/cmake/modules/MatahariDBusMacros.cmake
@@ -5,27 +5,24 @@
# First one contains gobject definition generated by dbus-binding-tool
# Second one is definition of properties of the object
-macro(generate_dbus_headers API)
+macro(generate_dbus_headers API XML)
find_file(XSLTPROC xsltproc)
find_file(BIND_TOOL dbus-binding-tool)
- # Lowercase
- string(TOLOWER ${API} lAPI)
-
# Convert dbus interface to glue and properties files
add_custom_command(
- OUTPUT matahari-${lAPI}-dbus-glue.h
+ OUTPUT matahari-${API}-dbus-glue.h
COMMAND ${BIND_TOOL} --prefix=matahari --mode=glib-server
- --output=matahari-${lAPI}-dbus-glue.h
- ${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.${API}.xml
- COMMENT "Generating matahari-${lAPI}-dbus-glue.h"
+ --output=matahari-${API}-dbus-glue.h
+ ${XML}
+ COMMENT "Generating matahari-${API}-dbus-glue.h"
)
add_custom_command(
- OUTPUT matahari-${lAPI}-dbus-properties.h
- COMMAND ${XSLTPROC} --output matahari-${lAPI}-dbus-properties.h
+ OUTPUT matahari-${API}-dbus-properties.h
+ COMMAND ${XSLTPROC} --output matahari-${API}-dbus-properties.h
${CMAKE_CURRENT_SOURCE_DIR}/../dbus-to-c.xsl
- ${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.${API}.xml
- COMMENT "Generating matahari-${lAPI}-dbus-properties.h"
+ ${XML}
+ COMMENT "Generating matahari-${API}-dbus-properties.h"
)
endmacro(generate_dbus_headers)
diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt
index a3dac7e..013c019 100644
--- a/src/host/CMakeLists.txt
+++ b/src/host/CMakeLists.txt
@@ -1,40 +1,49 @@
-set(MHOST_VERSION 0.0.1)
-
-include(DBusMacros)
-generate_dbus_headers(Host)
-
-set(HOST_DBUS_SOURCE
- matahari-host-dbus.c
- ../common/mh_dbus_common.c
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-host-dbus-glue.h
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-host-dbus-properties.h
-)
-
-# Daemon
-set(M_HOST_DBUS "matahari-host-dbusd")
-add_executable(${M_HOST_DBUS} ${HOST_DBUS_SOURCE})
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-target_link_libraries(${M_HOST_DBUS} mhost )
-
-if(polkit_FOUND)
- include_directories(${polkit_INCLUDE_DIRS})
- target_link_libraries(${M_HOST_DBUS} ${polkit_LIBRARIES})
-else(polkit_FOUND)
- message(FATAL_ERROR "polkit headers/libraries not found.")
-endif(polkit_FOUND)
-
-if(dbus-glib_FOUND)
- include_directories(${dbus-glib_INCLUDE_DIRS})
- target_link_libraries(${M_HOST_DBUS} ${dbus-glib_LIBRARIES})
-else(dbus-glib_FOUND)
- message(FATAL_ERROR "dbus-glib headers/libraries not found.")
-endif(dbus-glib_FOUND)
-
-# Install targets
-# TODO: fix hardcoded paths, should go to libexec
-install(TARGETS ${M_HOST_DBUS} DESTINATION sbin)
-install(FILES ${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Host.xml
DESTINATION share/dbus-1/interfaces)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Host.service
DESTINATION share/dbus-1/system-services)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Host.conf
DESTINATION /etc/dbus-1/system.d)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Host.policy
DESTINATION share/polkit-1/actions)
+set(HOST_LIB "mhost")
+set(HOST_QMF "matahari-qmf-hostd")
+set(HOST_DBUS "matahari-dbus-hostd")
+
+# QMF daemon
+if(WITH-QMF)
+ add_executable(${HOST_QMF} matahari-host.cpp ${SCHEMA_SOURCES})
+ target_link_libraries(${HOST_QMF} ${HOST_LIB} mcommon mcommon_qmf)
+
+ target_link_libraries(${HOST_QMF} ${QPIDCOMMON_LIBRARY}
${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ if(QPIDTYPES_LIBRARY)
+ target_link_libraries(${HOST_QMF} ${QPIDTYPES_LIBRARY})
+ endif(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${HOST_QMF} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${HOST_QMF} DESTINATION sbin)
+endif(WITH-QMF)
+
+
+# DBus daemon
+if(WITH-DBUS)
+ # Auto-generated stuff
+ include(MatahariDBusMacros)
+ generate_dbus_headers(host
${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Host.xml)
+ # Must be included to find matahari-API-dbus-properties.h
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+ set(HOST_DBUS_SOURCE
+ matahari-host-dbus.c
+ matahari-host-dbus-glue.h
+ matahari-host-dbus-properties.h
+ )
+
+ add_executable(${HOST_DBUS} ${HOST_DBUS_SOURCE})
+
+ target_link_libraries(${HOST_DBUS} ${HOST_LIB} mcommon_dbus ${dbus-
glib_LIBRARIES})
+ include_directories(${dbus-glib_INCLUDE_DIRS})
+
+ # Install targets
+ # TODO: fix hardcoded paths, should go to libexec
+ install(TARGETS ${HOST_DBUS} DESTINATION sbin)
+ install(FILES ${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Host.xml
DESTINATION share/dbus-1/interfaces)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Host.service DESTINATION
share/dbus-1/system-services)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Host.conf
DESTINATION /etc/dbus-1/system.d)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Host.policy
DESTINATION share/polkit-1/actions)
+endif(WITH-DBUS)
diff --git a/src/host/matahari-host-dbus.c b/src/host/matahari-host-dbus.c
index 9605ab0..1a2caf7 100644
--- a/src/host/matahari-host-dbus.c
+++ b/src/host/matahari-host-dbus.c
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
-#include "mh_dbus_common.h"
+#include "matahari/mh_dbus_common.h"
/* Host methods */
#include "matahari/host.h"
diff --git a/src/host/matahari-host.cpp b/src/host/matahari-host.cpp
index 82f7d88..340795e 100644
--- a/src/host/matahari-host.cpp
+++ b/src/host/matahari-host.cpp
@@ -26,6 +26,7 @@
#include <qmf/Data.h>
#include "qmf/org/matahariproject/Host.h"
#include "qmf/org/matahariproject/EventHeartbeat.h"
+#include "qmf/org/matahariproject/QmfPackage.h"
extern "C" {
#include <string.h>
@@ -36,6 +37,8 @@ extern "C" {
class HostAgent : public MatahariAgent
{
+ private:
+ qmf::org::matahariproject::PackageDefinition _package;
public:
int heartbeat();
int setup(qmf::AgentSession session);
@@ -85,6 +88,7 @@ HostAgent::invoke(qmf::AgentSession session, qmf::AgentEvent
event, gpointer use
int
HostAgent::setup(qmf::AgentSession session)
{
+ _package.configure(session);
_instance = qmf::Data(_package.data_Host);
_instance.setProperty("update_interval", 5);
diff --git a/src/include/matahari/mh_agent.h b/src/include/matahari/mh_agent.h
index 62c5aef..376cee3 100644
--- a/src/include/matahari/mh_agent.h
+++ b/src/include/matahari/mh_agent.h
@@ -26,6 +26,8 @@
#include <qpid/management/Manageable.h>
#include <qpid/messaging/Connection.h>
#include <qmf/AgentEvent.h>
+#include <qmf/AgentSession.h>
+#include <qmf/Data.h>
extern "C" {
#include "matahari/mainloop.h"
@@ -36,8 +38,6 @@ extern "C" {
using namespace qpid::management;
using namespace std;
-#include "qmf/org/matahariproject/QmfPackage.h" // v2 schema
-namespace _qmf = qmf::org::matahariproject;
namespace _qtype = ::qpid::types;
typedef struct mainloop_qmf_s
@@ -67,7 +67,6 @@ class MatahariAgent
qmf::Data _instance;
qmf::AgentSession _agent_session;
qpid::messaging::Connection _amqp_connection;
- qmf::org::matahariproject::PackageDefinition _package;
public:
MatahariAgent() {};
diff --git a/src/common/mh_dbus_common.h
b/src/include/matahari/mh_dbus_common.h
similarity index 100%
rename from src/common/mh_dbus_common.h
rename to src/include/matahari/mh_dbus_common.h
diff --git a/src/common/mh_gobject_class.h
b/src/include/matahari/mh_gobject_class.h
similarity index 100%
rename from src/common/mh_gobject_class.h
rename to src/include/matahari/mh_gobject_class.h
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
new file mode 100644
index 0000000..ab7a4d0
--- /dev/null
+++ b/src/lib/CMakeLists.txt
@@ -0,0 +1,72 @@
+# Library
+
+set(MHOST_VERSION 0.0.1)
+set(MSRV_VERSION 0.0.1)
+set(MNET_VERSION 0.0.1)
+set(MCOMMON_VERSION 0.0.1)
+set(MCOMMON_QMF_VERSION 0.0.1)
+set(MCOMMON_DBUS_VERSION 0.0.1)
+
+set(HOST_LIB "mhost")
+set(SRV_LIB "msrv")
+set(NET_LIB "mnet")
+
+add_library (${HOST_LIB} SHARED host.c host_${VARIANT}.c)
+add_library (${SRV_LIB} SHARED services.c services_${VARIANT}.c)
+add_library (${NET_LIB} SHARED network.c network_${VARIANT}.c)
+add_library (mcommon SHARED utilities.c mainloop.c)
+
+include_directories(${pcre_INCLUDE_DIRS})
+target_link_libraries(${HOST_LIB} ${pcre_LIBRARIES} mcommon ${SIGAR}
${glib_LIBRARIES})
+target_link_libraries(${SRV_LIB} ${pcre_LIBRARIES} mcommon ${SIGAR}
${glib_LIBRARIES})
+target_link_libraries(${NET_LIB} ${pcre_LIBRARIES} mcommon ${SIGAR}
${glib_LIBRARIES})
+target_link_libraries(mcommon ${SIGAR} ${glib_LIBRARIES})
+
+set_target_properties(${HOST_LIB} PROPERTIES SOVERSION ${MHOST_VERSION})
+set_target_properties(${SRV_LIB} PROPERTIES SOVERSION ${MSRV_VERSION})
+set_target_properties(${NET_LIB} PROPERTIES SOVERSION ${MNET_VERSION})
+set_target_properties(mcommon PROPERTIES SOVERSION ${MCOMMON_VERSION})
+
+if(WIN32)
+ target_link_libraries(${HOST_LIB} wsock32)
+ target_link_libraries(${SRV_LIB} wsock32)
+ target_link_libraries(${NET_LIB} wsock32)
+ target_link_libraries(mcommon wsock32)
+
+ install(TARGETS ${HOST_LIB} DESTINATION sbin)
+ install(TARGETS ${SRV_LIB} DESTINATION sbin)
+ install(TARGETS ${NET_LIB} DESTINATION sbin)
+ install(TARGETS mcommon DESTINATION sbin)
+else(WIN32)
+ install(TARGETS ${HOST_LIB} DESTINATION lib${LIB_SUFFIX})
+ install(TARGETS ${SRV_LIB} DESTINATION lib${LIB_SUFFIX})
+ install(TARGETS ${NET_LIB} DESTINATION lib${LIB_SUFFIX})
+ install(TARGETS mcommon DESTINATION lib${LIB_SUFFIX})
+endif(WIN32)
+
+if(WITH-QMF)
+ add_library (mcommon_qmf SHARED mh_agent.cpp)
+
+ target_link_libraries(mcommon_qmf ${QPIDCOMMON_LIBRARY}
${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ set_target_properties(mcommon_qmf PROPERTIES SOVERSION
${MCOMMON_QMF_VERSION})
+
+ if(WIN32)
+ target_link_libraries(mcommon_qmf wsock32)
+ install(TARGETS mcommon_qmf DESTINATION sbin)
+ else(WIN32)
+ install(TARGETS mcommon_qmf DESTINATION lib${LIB_SUFFIX})
+ endif(WIN32)
+endif(WITH-QMF)
+
+
+if(WITH-DBUS)
+ add_library (mcommon_dbus SHARED mh_dbus_common.c)
+
+ include_directories(${dbus-glib_INCLUDE_DIRS})
+ include_directories(${polkit_INCLUDE_DIRS})
+
+ target_link_libraries(mcommon_dbus ${polkit_LIBRARIES})
+ set_target_properties(mcommon_dbus PROPERTIES SOVERSION
${MCOMMON_DBUS_VERSION})
+
+ install(TARGETS mcommon_dbus DESTINATION lib${LIB_SUFFIX})
+endif(WITH-DBUS)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp
index 3f72d0f..6994171 100644
--- a/src/lib/mh_agent.cpp
+++ b/src/lib/mh_agent.cpp
@@ -38,6 +38,7 @@ int use_stderr = 0;
#include <qpid/sys/Time.h>
#include <qpid/agent/ManagementAgent.h>
#include <qpid/client/ConnectionSettings.h>
+#include <qmf/DataAddr.h>
#include "matahari/mh_agent.h"
extern "C" {
@@ -47,7 +48,6 @@ extern "C" {
using namespace qpid::management;
using namespace qpid::client;
using namespace std;
-namespace _qmf = qmf::org::matahariproject;
void
shutdown(int /*signal*/)
@@ -313,7 +313,6 @@ MatahariAgent::init(int argc, char **argv, const char*
proc_name)
_agent_session.setVendor("matahariproject.org");
_agent_session.setProduct(proc_name);
- _package.configure(_agent_session);
_agent_session.open();
/* Do any setup required by our agent */
diff --git a/src/common/mh_dbus_common.c b/src/lib/mh_dbus_common.c
similarity index 99%
rename from src/common/mh_dbus_common.c
rename to src/lib/mh_dbus_common.c
index b516729..105fe03 100644
--- a/src/common/mh_dbus_common.c
+++ b/src/lib/mh_dbus_common.c
@@ -20,7 +20,7 @@
*
*/
-#include "mh_dbus_common.h"
+#include "matahari/mh_dbus_common.h"
#include "matahari/logging.h"
#include <glib/gi18n.h>
diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt
index 1ca5c65..9d7df1a 100644
--- a/src/net/CMakeLists.txt
+++ b/src/net/CMakeLists.txt
@@ -1,40 +1,54 @@
-set(MHOST_VERSION 0.0.1)
-
-include(DBusMacros)
-generate_dbus_headers(Network)
-
-set(NET_DBUS_SOURCE
- matahari-network-dbus.c
- ../common/mh_dbus_common.c
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-network-dbus-glue.h
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-network-dbus-properties.h
-)
-
-# Daemon
-set(M_NET_DBUS "matahari-network-dbusd")
-add_executable(${M_NET_DBUS} ${NET_DBUS_SOURCE})
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-target_link_libraries(${M_NET_DBUS} mnet)
-
-if(polkit_FOUND)
- include_directories(${polkit_INCLUDE_DIRS})
- target_link_libraries(${M_NET_DBUS} ${polkit_LIBRARIES})
-else(polkit_FOUND)
- message(FATAL_ERROR "polkit headers/libraries not found.")
-endif(polkit_FOUND)
-
-if(dbus-glib_FOUND)
- include_directories(${dbus-glib_INCLUDE_DIRS})
- target_link_libraries(${M_NET_DBUS} ${dbus-glib_LIBRARIES})
-else(dbus-glib_FOUND)
- message(FATAL_ERROR "dbus-glib headers/libraries not found.")
-endif(dbus-glib_FOUND)
-
-# Install targets
-# TODO: fix hardcoded paths, should go to libexec
-install(TARGETS ${M_NET_DBUS} DESTINATION sbin)
-install(FILES ${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Network.xml
DESTINATION share/dbus-1/interfaces)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Network.service
DESTINATION share/dbus-1/system-services)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Network.conf
DESTINATION /etc/dbus-1/system.d)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Network.policy
DESTINATION share/polkit-1/actions)
+set(NET_LIB "mnet")
+set(NET_QMF "matahari-qmf-netd")
+set(NET_DBUS "matahari-dbus-netd")
+
+# QMF daemon
+if(WITH-QMF)
+ add_executable(${NET_QMF} matahari-net.cpp ${SCHEMA_SOURCES})
+ target_link_libraries(${NET_QMF} ${NET_LIB} mcommon mcommon_qmf)
+
+ target_link_libraries(${NET_QMF} ${QPIDCOMMON_LIBRARY}
${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ if(QPIDTYPES_LIBRARY)
+ target_link_libraries(${NET_QMF} ${QPIDTYPES_LIBRARY})
+ endif(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${NET_QMF} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${NET_QMF} DESTINATION sbin)
+endif(WITH-QMF)
+
+
+# DBus daemon
+if(WITH-DBUS)
+ # Auto-generated stuff
+ include(MatahariDBusMacros)
+ generate_dbus_headers(network
${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Network.xml)
+ # Must be included to find matahari-API-dbus-properties.h
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+ set(NET_DBUS_SOURCE
+ matahari-network-dbus.c
+ matahari-network-dbus-glue.h
+ matahari-network-dbus-properties.h
+ )
+
+ add_executable(${NET_DBUS} ${NET_DBUS_SOURCE})
+
+ target_link_libraries(${NET_DBUS} ${NET_LIB} mcommon_dbus)
+
+ include_directories(${polkit_INCLUDE_DIRS})
+ target_link_libraries(${NET_DBUS} ${polkit_LIBRARIES})
+
+ include_directories(${dbus-glib_INCLUDE_DIRS})
+ target_link_libraries(${NET_DBUS} ${dbus-glib_LIBRARIES})
+
+ # Install targets
+ # TODO: fix hardcoded paths, should go to libexec
+ install(TARGETS ${NET_DBUS} DESTINATION sbin)
+ install(FILES
${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Network.xml DESTINATION
share/dbus-1/interfaces)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Network.service DESTINATION
share/dbus-1/system-services)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Network.conf DESTINATION
/etc/dbus-1/system.d)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Network.policy DESTINATION
share/polkit-1/actions)
+endif(WITH-DBUS)
diff --git a/src/net/matahari-net.cpp b/src/net/matahari-net.cpp
index 36882b2..4d72250 100644
--- a/src/net/matahari-net.cpp
+++ b/src/net/matahari-net.cpp
@@ -29,6 +29,7 @@
#include "qmf/org/matahariproject/ArgsNetworkStatus.h"
#include "qmf/org/matahariproject/ArgsNetworkGet_ip_address.h"
#include "qmf/org/matahariproject/ArgsNetworkGet_mac_address.h"
+#include "qmf/org/matahariproject/QmfPackage.h"
#include <qpid/agent/ManagementAgent.h>
@@ -46,6 +47,8 @@ extern "C" {
class NetAgent : public MatahariAgent
{
+ private:
+ qmf::org::matahariproject::PackageDefinition _package;
public:
int setup(qmf::AgentSession session);
gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event,
gpointer user_data);
@@ -79,6 +82,7 @@ static int interface_status(const char *iface)
int
NetAgent::setup(qmf::AgentSession session)
{
+ _package.configure(session);
_instance = qmf::Data(_package.data_Network);
_instance.setProperty("hostname", matahari_hostname());
diff --git a/src/net/matahari-network-dbus.c b/src/net/matahari-network-dbus.c
index 28f6214..bbc636d 100644
--- a/src/net/matahari-network-dbus.c
+++ b/src/net/matahari-network-dbus.c
@@ -25,7 +25,7 @@
#include <sigar.h>
-#include "mh_dbus_common.h"
+#include "matahari/mh_dbus_common.h"
/* Network methods */
#include "matahari/network.h"
diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt
index 7559082..86e35f2 100644
--- a/src/service/CMakeLists.txt
+++ b/src/service/CMakeLists.txt
@@ -1,40 +1,54 @@
-set(MHOST_VERSION 0.0.1)
-
-include(DBusMacros)
-generate_dbus_headers(Services)
-
-set(SRV_DBUS_SOURCE
- matahari-services-dbus.c
- ../common/mh_dbus_common.c
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-services-dbus-glue.h
- ${CMAKE_CURRENT_BINARY_DIR}/matahari-services-dbus-properties.h
-)
-
-# Daemon
-set(M_SRV_DBUS "matahari-services-dbusd")
-add_executable(${M_SRV_DBUS} ${SRV_DBUS_SOURCE})
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-target_link_libraries(${M_SRV_DBUS} msrv)
-
-if(polkit_FOUND)
- include_directories(${polkit_INCLUDE_DIRS})
- target_link_libraries(${M_SRV_DBUS} ${polkit_LIBRARIES})
-else(polkit_FOUND)
- message(FATAL_ERROR "polkit headers/libraries not found.")
-endif(polkit_FOUND)
-
-if(dbus-glib_FOUND)
- include_directories(${dbus-glib_INCLUDE_DIRS})
- target_link_libraries(${M_SRV_DBUS} ${dbus-glib_LIBRARIES})
-else(dbus-glib_FOUND)
- message(FATAL_ERROR "dbus-glib headers/libraries not found.")
-endif(dbus-glib_FOUND)
-
-# Install targets
-# TODO: fix hardcoded paths, should go to libexec
-install(TARGETS ${M_SRV_DBUS} DESTINATION sbin)
-install(FILES ${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Services.xml
DESTINATION share/dbus-1/interfaces)
-install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.service DESTINATION
share/dbus-1/system-services)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.conf
DESTINATION /etc/dbus-1/system.d)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.policy
DESTINATION share/polkit-1/actions)
+set(SRV_LIB "msrv")
+set(SRV_QMF "matahari-qmf-serviced")
+set(SRV_DBUS "matahari-dbus-serviced")
+
+# QMF daemon
+if(WITH-QMF)
+ add_executable(${SRV_QMF} matahari-srv.cpp ${SCHEMA_SOURCES})
+ target_link_libraries(${SRV_QMF} ${SRV_LIB} mcommon mcommon_qmf)
+
+ target_link_libraries(${SRV_QMF} ${QPIDCOMMON_LIBRARY}
${QPIDCLIENT_LIBRARY} ${QPIDMESSAGING_LIBRARY} ${QMF2_LIBRARY})
+ IF(QPIDTYPES_LIBRARY)
+ target_link_libraries(${SRV_QMF} ${QPIDTYPES_LIBRARY})
+ ENDIF(QPIDTYPES_LIBRARY)
+
+ if(WIN32)
+ target_link_libraries(${daemon} wsock32)
+ endif(WIN32)
+
+ install(TARGETS ${SRV_QMF} DESTINATION sbin)
+endif(WITH-QMF)
+
+
+# DBus daemon
+if(WITH-DBUS)
+ # Auto-generated stuff
+ include(MatahariDBusMacros)
+ generate_dbus_headers(services
${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Services.xml)
+ # Must be included to find matahari-API-dbus-properties.h
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+ set(SRV_DBUS_SOURCE
+ matahari-services-dbus.c
+ matahari-services-dbus-glue.h
+ matahari-services-dbus-properties.h
+ )
+
+ add_executable(${SRV_DBUS} ${SRV_DBUS_SOURCE})
+
+ target_link_libraries(${SRV_DBUS} ${SRV_LIB} mcommon_dbus)
+
+ include_directories(${polkit_INCLUDE_DIRS})
+ target_link_libraries(${SRV_DBUS} ${polkit_LIBRARIES})
+
+ include_directories(${dbus-glib_INCLUDE_DIRS})
+ target_link_libraries(${SRV_DBUS} ${dbus-glib_LIBRARIES})
+
+ # Install targets
+ # TODO: fix hardcoded paths, should go to libexec
+ install(TARGETS ${SRV_DBUS} DESTINATION sbin)
+ install(FILES
${CMAKE_BINARY_DIR}/src/dbus/org.matahariproject.Services.xml DESTINATION
share/dbus-1/interfaces)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.service DESTINATION
share/dbus-1/system-services)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.conf DESTINATION
/etc/dbus-1/system.d)
+ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/org.matahariproject.Services.policy DESTINATION
share/polkit-1/actions)
+endif(WITH-DBUS)
diff --git a/src/service/matahari-services-dbus.c b/src/service/matahari-
services-dbus.c
index 6896792..cef8279 100644
--- a/src/service/matahari-services-dbus.c
+++ b/src/service/matahari-services-dbus.c
@@ -22,7 +22,7 @@
#include <string.h>
-#include "mh_dbus_common.h"
+#include "matahari/mh_dbus_common.h"
/* Services methods */
#include "matahari/services.h"
diff --git a/src/service/matahari-srv.cpp b/src/service/matahari-srv.cpp
index 38ae48b..33e2688 100644
--- a/src/service/matahari-srv.cpp
+++ b/src/service/matahari-srv.cpp
@@ -23,6 +23,7 @@
#include <string>
#include <qpid/management/Manageable.h>
#include <qpid/agent/ManagementAgent.h>
+#include <qmf/DataAddr.h>
#include "matahari/mh_agent.h"
#include "qmf/org/matahariproject/Services.h"
@@ -31,6 +32,8 @@
#include "qmf/org/matahariproject/Resources.h"
#include "qmf/org/matahariproject/EventResource_op.h"
+#include "qmf/org/matahariproject/QmfPackage.h"
+
extern "C" {
#include "matahari/logging.h"
#include "matahari/services.h"
@@ -47,7 +50,8 @@ class SrvAgent : public MatahariAgent
gboolean invoke_services(qmf::AgentSession session, qmf::AgentEvent
event, gpointer user_data);
gboolean invoke_resources(qmf::AgentSession session, qmf::AgentEvent
event, gpointer user_data);
-
+
+ qmf::org::matahariproject::PackageDefinition _package;
public:
void raiseEvent(svc_action_t *op, int service);
int setup(qmf::AgentSession session);
@@ -137,6 +141,7 @@ void SrvAgent::raiseEvent(svc_action_t *op, int service)
int
SrvAgent::setup(qmf::AgentSession session)
{
+ _package.configure(session);
_services = qmf::Data(_package.data_Services);
_services.setProperty("uuid", matahari_uuid());
13 years
[PATCH] Misc cleanups in src/lib/network.c.
by russell@russellbryant.net
1) Try to make the formatting more consistent. I went with what seemed
most common in the file (4 space indent, etc.). It would be good to
decide on a style guide, though, if that has not already been done.
Also trim trailing whitespace in passing.
2) Add checking for failures of memory allocations and handle them
gracefully.
3) Use calloc() instead of malloc() + memset().
4) Use asprintf() instead of a malloc() + snprintf().
5) Use a stack buffer instead of a mallocd buffer that is local to
services_action_cancel().
Signed-off-by: Russell Bryant <russell(a)russellbryant.net>
---
src/lib/services.c | 198 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 134 insertions(+), 64 deletions(-)
diff --git a/src/lib/services.c b/src/lib/services.c
index 43e1fcc..7cc380f 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -37,68 +37,140 @@ GHashTable *recurring_actions = NULL;
svc_action_t *services_action_create(
const char *name, const char *action, int interval, int timeout)
{
- svc_action_t *op = malloc(sizeof(svc_action_t));
- memset(op, 0, sizeof(svc_action_t));
-
- op->opaque = malloc(sizeof(svc_action_private_t));
- memset(op->opaque, 0, sizeof(svc_action_private_t));
-
- op->rsc = strdup(name);
- op->action = strdup(action);
+ svc_action_t *op;
+
+ if(!(op = calloc(1, sizeof(svc_action_t)))) {
+ return NULL;
+ }
+
+ if(!(op->opaque = calloc(1, sizeof(svc_action_private_t)))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->rsc = strdup(name))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->action = strdup(action))) {
+ goto return_cleanup;
+ }
+
op->interval = interval;
op->timeout = timeout;
- op->rclass = strdup("lsb");
- op->agent = strdup(name);
+ if(!(op->rclass = strdup("lsb"))) {
+ goto return_cleanup;
+ }
- op->id = malloc(500);
- snprintf(op->id, 500, "%s_%s_%d", name, action, interval);
+ if(!(op->agent = strdup(name))) {
+ goto return_cleanup;
+ }
+
+ if(asprintf(&op->id, "%s_%s_%d", name, action, interval) == -1) {
+ op->id = NULL;
+ goto return_cleanup;
+ }
services_os_set_exec(op);
-
+
return op;
+
+return_cleanup:
+ free(op->opaque);
+ free(op->rsc);
+ free(op->action);
+ free(op->rclass);
+ free(op->agent);
+ free(op->id);
+ free(op);
+
+ return NULL;
}
svc_action_t *resources_action_create(
const char *name, const char *provider, const char *agent,
const char *action, int interval, int timeout, GHashTable *params)
{
- svc_action_t *op = malloc(sizeof(svc_action_t));
- memset(op, 0, sizeof(svc_action_t));
-
- op->opaque = malloc(sizeof(svc_action_private_t));
- memset(op->opaque, 0, sizeof(svc_action_private_t));
-
- op->rsc = strdup(name);
- op->action = strdup(action);
+ svc_action_t *op;
+
+ if(!(op = calloc(1, sizeof(svc_action_t)))) {
+ return NULL;
+ }
+
+ if(!(op->opaque = calloc(1, sizeof(svc_action_private_t)))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->rsc = strdup(name))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->action = strdup(action))) {
+ goto return_cleanup;
+ }
+
op->interval = interval;
op->timeout = timeout;
- op->rclass = strdup("ocf");
- op->agent = strdup(agent);
- op->provider = strdup(provider);
+ if(!(op->rclass = strdup("ocf"))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->agent = strdup(agent))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->provider = strdup(provider))) {
+ goto return_cleanup;
+ }
op->params = params;
- op->id = malloc(500);
- snprintf(op->id, 500, "%s_%s_%d", name, action, interval);
+ if(asprintf(&op->id, "%s_%s_%d", name, action, interval) == -1) {
+ op->id = NULL;
+ goto return_cleanup;
+ }
- op->opaque->exec = malloc(500);
- snprintf(op->opaque->exec, 500, "%s/resource.d/%s/%s", OCF_ROOT, provider, agent);
+ if(asprintf(&op->opaque->exec, "%s/resource.d/%s/%s", OCF_ROOT,
+ provider, agent) == -1) {
+ op->opaque->exec = NULL;
+ goto return_cleanup;
+ }
+
+ if(!(op->opaque->args[0] = strdup(op->opaque->exec))) {
+ goto return_cleanup;
+ }
+
+ if(!(op->opaque->args[1] = strdup(action))) {
+ goto return_cleanup;
+ }
- op->opaque->args[0] = strdup(op->opaque->exec);
- op->opaque->args[1] = strdup(action);
- op->opaque->args[2] = NULL;
-
return op;
+
+return_cleanup:
+ free(op->rsc);
+ free(op->action);
+ free(op->rclass);
+ free(op->agent);
+ free(op->provider);
+ free(op->id);
+ if(op->opaque) {
+ free(op->opaque->exec);
+ free(op->opaque->args[0]);
+ free(op->opaque->args[1]);
+ }
+ free(op->opaque);
+ free(op);
+
+ return NULL;
}
void services_action_free(svc_action_t *op)
{
if(op == NULL) {
- return;
+ return;
}
-
+
free(op->id);
free(op->opaque->exec);
@@ -118,8 +190,8 @@ void services_action_free(svc_action_t *op)
free(op->stderr_data);
if(op->params) {
- g_hash_table_destroy(op->params);
- op->params = NULL;
+ g_hash_table_destroy(op->params);
+ op->params = NULL;
}
free(op);
@@ -128,42 +200,40 @@ void services_action_free(svc_action_t *op)
gboolean services_action_cancel(const char *name, const char *action, int interval)
{
svc_action_t* op = NULL;
- gboolean found = FALSE;
- char *id = malloc(500);
-
- snprintf(id, 500, "%s_%s_%d", name, action, interval);
- op = g_hash_table_lookup(recurring_actions, id);
- free(id);
-
- if(op) {
- found = TRUE;
- op->opaque->cancel = TRUE;
- mh_debug("Removing %s", op->id);
- if(op->opaque->repeat_timer) {
- g_source_remove(op->opaque->repeat_timer);
- }
- services_action_free(op);
- }
-
- return found;
+ char id[512];
+
+ snprintf(id, sizeof(id), "%s_%s_%d", name, action, interval);
+
+ if (!(op = g_hash_table_lookup(recurring_actions, id))) {
+ return FALSE;
+ }
+
+ op->opaque->cancel = TRUE;
+ mh_debug("Removing %s", op->id);
+ if(op->opaque->repeat_timer) {
+ g_source_remove(op->opaque->repeat_timer);
+ }
+ services_action_free(op);
+
+ return TRUE;
}
gboolean
services_action_async(svc_action_t* op, void (*action_callback)(svc_action_t*))
{
if(action_callback) {
- op->opaque->callback = action_callback;
+ op->opaque->callback = action_callback;
}
if(recurring_actions == NULL) {
- recurring_actions = g_hash_table_new_full(
- g_str_hash, g_str_equal, NULL, NULL);
+ recurring_actions = g_hash_table_new_full(
+ g_str_hash, g_str_equal, NULL, NULL);
}
if(op->interval > 0) {
- g_hash_table_replace(recurring_actions, op->id, op);
+ g_hash_table_replace(recurring_actions, op->id, op);
}
-
+
return services_os_action_execute(op, FALSE);
}
@@ -173,10 +243,10 @@ services_action_sync(svc_action_t* op)
gboolean rc = services_os_action_execute(op, TRUE);
mh_trace(" > %s_%s_%d: %s = %d", op->rsc, op->action, op->interval, op->opaque->exec, op->rc);
if(op->stdout_data) {
- mh_trace(" > stdout: %s", op->stdout_data);
+ mh_trace(" > stdout: %s", op->stdout_data);
}
if(op->stderr_data) {
- mh_trace(" > stderr: %s", op->stderr_data);
+ mh_trace(" > stderr: %s", op->stderr_data);
}
return rc;
}
@@ -187,17 +257,17 @@ get_directory_list(const char *root, gboolean files)
return services_os_get_directory_list(root, files);
}
-GList *services_list(void)
+GList *services_list(void)
{
return services_os_list();
}
-GList *resources_list_ocf_providers(void)
+GList *resources_list_ocf_providers(void)
{
return resources_os_list_ocf_providers();
}
-GList *resources_list_ocf_agents(const char *provider)
+GList *resources_list_ocf_agents(const char *provider)
{
return resources_os_list_ocf_agents(provider);
}
--
1.7.4
13 years