summaryrefslogtreecommitdiff
path: root/RC9/qpid/cpp/examples/qmf-agent
diff options
context:
space:
mode:
Diffstat (limited to 'RC9/qpid/cpp/examples/qmf-agent')
-rw-r--r--RC9/qpid/cpp/examples/qmf-agent/Makefile85
-rw-r--r--RC9/qpid/cpp/examples/qmf-agent/example.cpp200
-rw-r--r--RC9/qpid/cpp/examples/qmf-agent/schema.xml64
3 files changed, 349 insertions, 0 deletions
diff --git a/RC9/qpid/cpp/examples/qmf-agent/Makefile b/RC9/qpid/cpp/examples/qmf-agent/Makefile
new file mode 100644
index 0000000000..4c5daa6888
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-agent/Makefile
@@ -0,0 +1,85 @@
+#
+# 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.
+#
+
+SRC_DIR = .
+QPID_DIR = ../../..
+SCHEMA_FILE = $(SRC_DIR)/schema.xml
+GEN_DIR = $(SRC_DIR)/gen
+OUT_FILE = $(SRC_DIR)/qmf-agent
+
+CC = gcc
+LIB_DIR = $(QPID_DIR)/cpp/src/.libs
+CC_INCLUDES = -I$(SRC_DIR) -I$(QPID_DIR)/cpp/src -I$(QPID_DIR)/cpp/src/gen -I$(GEN_DIR)
+CC_FLAGS = -g -O3
+LD_FLAGS = -lqmfagent -L$(LIB_DIR)
+SPEC_DIR = $(QPID_DIR)/specs
+MGEN_DIR = $(QPID_DIR)/cpp/managementgen
+MGEN = $(MGEN_DIR)/qmf-gen
+
+vpath %.cpp $(SRC_DIR):$(GEN_DIR)
+vpath %.d $(OBJ_DIR)
+vpath %.o $(OBJ_DIR)
+
+cpps = $(wildcard $(SRC_DIR)/*.cpp)
+cpps += $(wildcard $(GEN_DIR)/qmf/org/apache/qpid/agent/example/*.cpp)
+deps = $(addsuffix .d, $(basename $(cpps)))
+objects = $(addsuffix .o, $(basename $(cpps)))
+
+.PHONY: all clean gen
+
+#==========================================================
+# Pass 0: generate source files from schema
+ifeq ($(MAKELEVEL), 0)
+
+all: gen
+ @$(MAKE)
+
+gen:
+ $(MGEN) -o $(GEN_DIR)/qmf $(SCHEMA_FILE)
+
+clean:
+ rm -rf $(GEN_DIR) $(OUT_FILE) *.d *.o
+
+
+#==========================================================
+# Pass 1: generate dependencies
+else ifeq ($(MAKELEVEL), 1)
+
+all: $(deps)
+ @$(MAKE)
+
+%.d : %.cpp
+ $(CC) -M $(CC_FLAGS) $(CC_INCLUDES) $< > $@
+
+
+#==========================================================
+# Pass 2: build project
+else ifeq ($(MAKELEVEL), 2)
+
+$(OUT_FILE) : $(objects)
+ $(CC) -o $(OUT_FILE) $(CC_FLAGS) $(LD_FLAGS) $(objects)
+
+include $(deps)
+
+%.o : %.cpp
+ $(CC) -c $(CC_FLAGS) $(CC_INCLUDES) -o $@ $<
+
+endif
+
+
diff --git a/RC9/qpid/cpp/examples/qmf-agent/example.cpp b/RC9/qpid/cpp/examples/qmf-agent/example.cpp
new file mode 100644
index 0000000000..4dec014370
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-agent/example.cpp
@@ -0,0 +1,200 @@
+/*
+ *
+ * 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 <qpid/management/Manageable.h>
+#include <qpid/management/ManagementObject.h>
+#include <qpid/agent/ManagementAgent.h>
+#include <qpid/sys/Mutex.h>
+#include "qmf/org/apache/qpid/agent/example/Parent.h"
+#include "qmf/org/apache/qpid/agent/example/Child.h"
+#include "qmf/org/apache/qpid/agent/example/ArgsParentCreate_child.h"
+#include "qmf/org/apache/qpid/agent/example/EventChildCreated.h"
+#include "qmf/org/apache/qpid/agent/example/Package.h"
+
+#include <signal.h>
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+#include <sstream>
+
+using namespace std;
+using qpid::management::ManagementAgent;
+using qpid::management::ManagementObject;
+using qpid::management::Manageable;
+using qpid::management::Args;
+using qpid::sys::Mutex;
+namespace _qmf = qmf::org::apache::qpid::agent::example;
+
+class ChildClass;
+
+//==============================================================
+// CoreClass is the operational class that corresponds to the
+// "Parent" class in the management schema.
+//==============================================================
+class CoreClass : public Manageable
+{
+ string name;
+ ManagementAgent* agent;
+ _qmf::Parent* mgmtObject;
+ std::vector<ChildClass*> children;
+ Mutex vectorLock;
+
+public:
+
+ CoreClass(ManagementAgent* agent, string _name);
+ ~CoreClass() { mgmtObject->resourceDestroy(); }
+
+ ManagementObject* GetManagementObject(void) const
+ { return mgmtObject; }
+
+ void doLoop();
+ status_t ManagementMethod (uint32_t methodId, Args& args, string& text);
+};
+
+class ChildClass : public Manageable
+{
+ string name;
+ _qmf::Child* mgmtObject;
+
+public:
+
+ ChildClass(ManagementAgent* agent, CoreClass* parent, string name);
+ ~ChildClass() { mgmtObject->resourceDestroy(); }
+
+ ManagementObject* GetManagementObject(void) const
+ { return mgmtObject; }
+
+ void doWork()
+ {
+ mgmtObject->inc_count(2);
+ }
+};
+
+CoreClass::CoreClass(ManagementAgent* _agent, string _name) : name(_name), agent(_agent)
+{
+ static uint64_t persistId = 0x111222333444555LL;
+ mgmtObject = new _qmf::Parent(agent, this, name);
+
+ agent->addObject(mgmtObject, persistId++);
+ mgmtObject->set_state("IDLE");
+}
+
+void CoreClass::doLoop()
+{
+ // Periodically bump a counter to provide a changing statistical value
+ while (1) {
+ sleep(1);
+ mgmtObject->inc_count();
+ mgmtObject->set_state("IN_LOOP");
+
+ {
+ Mutex::ScopedLock _lock(vectorLock);
+
+ for (std::vector<ChildClass*>::iterator iter = children.begin();
+ iter != children.end();
+ iter++) {
+ (*iter)->doWork();
+ }
+ }
+ }
+}
+
+Manageable::status_t CoreClass::ManagementMethod(uint32_t methodId, Args& args, string& /*text*/)
+{
+ Mutex::ScopedLock _lock(vectorLock);
+
+ switch (methodId) {
+ case _qmf::Parent::METHOD_CREATE_CHILD:
+ _qmf::ArgsParentCreate_child& ioArgs = (_qmf::ArgsParentCreate_child&) args;
+
+ ChildClass *child = new ChildClass(agent, this, ioArgs.i_name);
+ ioArgs.o_childRef = child->GetManagementObject()->getObjectId();
+
+ children.push_back(child);
+
+ agent->raiseEvent(_qmf::EventChildCreated(ioArgs.i_name));
+
+ return STATUS_OK;
+ }
+
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+ChildClass::ChildClass(ManagementAgent* agent, CoreClass* parent, string name)
+{
+ mgmtObject = new _qmf::Child(agent, this, parent, name);
+
+ agent->addObject(mgmtObject);
+}
+
+
+//==============================================================
+// Main program
+//==============================================================
+
+ManagementAgent::Singleton* singleton;
+
+void shutdown(int)
+{
+ delete singleton;
+ exit(0);
+}
+
+int main_int(int argc, char** argv)
+{
+ singleton = new ManagementAgent::Singleton();
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
+ qpid::client::ConnectionSettings settings;
+
+ settings.host = host;
+ settings.port = port;
+
+ signal(SIGINT, shutdown);
+
+ // Create the qmf management agent
+ ManagementAgent* agent = singleton->getInstance();
+
+ // Register the Qmf_example schema with the agent
+ _qmf::Package packageInit(agent);
+
+ // Start the agent. It will attempt to make a connection to the
+ // management broker
+ agent->init(settings, 5, false, ".magentdata");
+
+ // Allocate some core objects
+ CoreClass core1(agent, "Example Core Object #1");
+ CoreClass core2(agent, "Example Core Object #2");
+ CoreClass core3(agent, "Example Core Object #3");
+
+ core1.doLoop();
+}
+
+int main(int argc, char** argv)
+{
+ try {
+ return main_int(argc, argv);
+ } catch(std::exception& e) {
+ cout << "Top Level Exception: " << e.what() << endl;
+ }
+}
+
diff --git a/RC9/qpid/cpp/examples/qmf-agent/schema.xml b/RC9/qpid/cpp/examples/qmf-agent/schema.xml
new file mode 100644
index 0000000000..1bf701a655
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-agent/schema.xml
@@ -0,0 +1,64 @@
+<schema package="org.apache.qpid.agent.example">
+
+<!--
+ 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.
+-->
+
+ <!--
+ ===============================================================
+ Parent
+ ===============================================================
+ -->
+ <class name="Parent">
+
+ This class represents a parent object
+
+ <property name="name" type="sstr" access="RC" index="y"/>
+
+ <statistic name="state" type="sstr" desc="Operational state of the link"/>
+ <statistic name="count" type="count64" unit="tick" desc="Counter that increases monotonically"/>
+
+ <method name="create_child" desc="Create child object">
+ <arg name="name" dir="I" type="sstr"/>
+ <arg name="childRef" dir="O" type="objId"/>
+ </method>
+ </class>
+
+
+ <!--
+ ===============================================================
+ Child
+ ===============================================================
+ -->
+ <class name="Child">
+ <property name="ParentRef" type="objId" references="Parent" access="RC" index="y" parentRef="y"/>
+ <property name="name" type="sstr" access="RC" index="y"/>
+
+ <statistic name="count" type="count64" unit="tick" desc="Counter that increases monotonically"/>
+
+ <method name="delete"/>
+ </class>
+
+ <eventArguments>
+ <arg name="childName" type="sstr"/>
+ </eventArguments>
+
+ <event name="ChildCreated" args="childName"/>
+ <event name="ChildDestroyed" args="childName"/>
+</schema>
+