From: Adam Stokes <astokes(a)fedoraproject.org>
---
src/CMakeLists.txt | 8 +++-
src/console/matahari-console.cpp | 89 ++++++++++++++++++++++++++++++++++++++
src/schema.xml | 5 ++
3 files changed, 101 insertions(+), 1 deletions(-)
create mode 100644 src/console/matahari-console.cpp
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ccef9da..6dd2bbb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,6 +21,7 @@ set(MCOMMON_VERSION 0.0.1)
set(MHOST_VERSION 0.0.1)
set(MSRV_VERSION 0.0.1)
set(MNET_VERSION 0.0.1)
+set(MCONSOLE_VERSION 0.0.1)
option(WITH-QMF "Build the QMF daemon" ON)
option(WITH-DBUS "Build the DBus daemon" ON)
@@ -37,8 +38,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
${CMAKE_MODULE_P
set(M_HOST "matahari-hostd")
set(M_NET "matahari-netd")
set(M_SRV "matahari-serviced")
+set(M_CONSOLE "matahari-consoled")
-set(DAEMONS ${M_HOST} ${M_NET} ${M_SRV})
+set(DAEMONS ${M_HOST} ${M_NET} ${M_SRV} ${M_CONSOLE})
file(GLOB SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/*.xml")
@@ -54,6 +56,7 @@ set(SCHEMA_SOURCES
${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/Console.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
@@ -93,6 +96,9 @@ target_link_libraries(${M_NET} mnet)
add_executable(${M_SRV} service/matahari-srv.cpp ${SCHEMA_SOURCES} ${COMMON_SOURCES})
target_link_libraries(${M_SRV} msrv)
+add_executable(${M_CONSOLE} console/matahari-console.cpp ${SCHEMA_SOURCES}
${COMMON_SOURCES})
+target_link_libraries(${M_CONSOLE} mhost)
+
foreach(daemon ${DAEMONS})
target_link_libraries(${daemon} mcommon)
if(WIN32)
diff --git a/src/console/matahari-console.cpp b/src/console/matahari-console.cpp
new file mode 100644
index 0000000..16f1618
--- /dev/null
+++ b/src/console/matahari-console.cpp
@@ -0,0 +1,89 @@
+/* matahari-console.cpp - Copyright (c) 2011 Red Hat, Inc.
+ * Written by Adam Stokes <astokes(a)fedoraproject.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef WIN32
+#include "config.h"
+#endif
+
+#include "matahari/mh_agent.h"
+#include <qmf/Data.h>
+#include <qmf/ConsoleEvent.h>
+#include <qmf/ConsoleSession.h>
+#include "qmf/org/matahariproject/Console.h"
+#include <qpid/sys/Time.h>
+
+#include <sstream>
+using namespace std;
+
+extern "C" {
+#include <sigar.h>
+#include "matahari/host.h"
+}
+
+class ConsoleAgent : public MatahariAgent
+{
+public:
+ int setup(qmf::AgentSession session);
+ gboolean invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data);
+};
+
+int main(int argc, char** argv)
+{
+ ConsoleAgent *agent = new ConsoleAgent();;
+ int rc = agent->init(argc, argv, "console");
+ if(rc == 0) {
+ agent->run();
+ }
+ return rc;
+}
+
+int
+ConsoleAgent::setup(qmf::AgentSession session)
+{
+ _instance = qmf::Data(_package.data_Console);
+ _instance.setProperty("uuid", host_get_uuid());
+ _instance.setProperty("hostname", host_get_hostname());
+ _instance.setProperty("status", "Waiting for console event");
+ session.addData(_instance);
+
+ qmf::ConsoleSession _console_session;
+ _console_session = qmf::ConsoleSession(_amqp_connection);
+ _console_session.open();
+ qmf::Agent agent;
+ while (true) {
+ if(_console_session.getAgentCount() > 0) {
+ agent = _console_session.getAgent(0);
+ qmf::ConsoleEvent result(agent.query("{class:Console,
package:'org.matahariproject', where:[eq, hostname, [quote,
supa.kooba]]}"));
+ if(result.getType() == qmf::CONSOLE_QUERY_RESPONSE) {
+ _instance.setProperty("status", "Received console event");
+ break;
+ }
+ }
+ qpid::sys::sleep(1);
+ }
+
+ return 0;
+}
+
+gboolean
+ConsoleAgent::invoke(qmf::AgentSession session, qmf::AgentEvent event, gpointer
user_data)
+{
+ if(event.getType() == qmf::AGENT_METHOD) {
+ //const std::string& methodName(event.getMethodName());
+ }
+}
diff --git a/src/schema.xml b/src/schema.xml
index ea82e4f..75c008b 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -244,4 +244,9 @@
</method-->
</class>
+ <class name="Console">
+ <property name="uuid" type="sstr"
access="RO" desc="Host UUID" />
+ <property name="hostname" type="sstr" access="RO"
desc="Hostname" index="y"/>
+ <property name="status" type="sstr" access="RW"
desc="Status of Instance" />
+ </class>
</schema>
--
1.7.4
Show replies by date