Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.o | ||
.*\.swp | ||
mcpp | ||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#------------------------------------------------------------------------------ | ||
# --soname vs macosx | ||
# http://www.corpit.ru/pipermail/udns/2011q1/000124.html | ||
|
||
SOURCE=mc-discovery.cpp | ||
#SOURCE=x1.cpp | ||
PROGRAM=mcpp | ||
MYINCLUDES=-I/opt/include/activemq-cpp-3.4.1 | ||
|
||
MYLIBRARIES= | ||
#MYLIBRARIES=-L/opt/lib -lactivemq-cpp -lyaml-cpp -lapr-1 -laprutil-1 -lpthread | ||
MYLIBRARIES=-L/opt/lib -lactivemq-cpp -lyaml-cpp -lapr-1 -laprutil-1 -lcrypto -lssl -lpthread | ||
#MYLIBRARIES=-L/opt/lib -Wl,-Bstatic -lssl -lcrypto -lapr-1 -laprutil-1 -lactivemq-cpp -lyaml-cpp -Wl,-Bdynamic -lpthread -lssl -lcrypto | ||
#MYLIBRARIES=-L/usr/lib64 -Wl,-Bstatic -lssl -lcrypto -L/opt/lib -Wl,-Bdynamic -lapr-1 -laprutil-1 -lactivemq-cpp -lyaml-cpp -lpthread | ||
CXX=g++ | ||
|
||
#------------------------------------------------------------------------------ | ||
|
||
main: libmcollective.so main.o | ||
$(CXX) -o $(PROGRAM) main.o -L. -lmcollective | ||
|
||
libmcollective.so: mcollective_listener.cpp | ||
$(CXX) -fPIC -c mcollective_listener.cpp -o mcollective.o | ||
$(CXX) -shared -Wl -o libmcollective.so mcollective.o | ||
|
||
clean: | ||
rm *.o *.so $(PROGRAM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "base.h" | ||
|
||
void agentbase::setx(int newx) { myx = newx; } | ||
int agentbase::getx() { return myx; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class agentbase { | ||
int myx; | ||
|
||
public: | ||
|
||
agentbase() { myx=0; } | ||
void setx(int newx); | ||
int getx(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
//Constructor passes the session | ||
|
||
// // Create the destination (Topic or Queue) | ||
// destination = session->createTopic ("mcollective.discovery.command"); | ||
|
||
|
||
// // Create a MessageConsumer from the Session to the Topic or Queue | ||
// consumer = session->createConsumer (destination); | ||
|
||
// Set listener (a class that has onMessage(const Message * message) throw() | ||
// consumer->setMessageListener (this); | ||
// | ||
// | ||
// | ||
|
||
|
||
// Called from the consumer since this class is a registered MessageListener | ||
// virtual void | ||
// onMessage (const Message * message) | ||
// throw () | ||
|
||
// extract message to yaml and pass it to handle | ||
|
||
// const BytesMessage * | ||
// bytesMessage = dynamic_cast < const | ||
// BytesMessage * >(message); | ||
|
||
// if (bytesMessage != NULL) | ||
// { | ||
// //std::cout << bytesMessage->getBodyBytes(); | ||
// //bytesMessage->reset(); | ||
// | ||
// size_t i = bytesMessage->getBodyLength (); | ||
// printf ("%lu", i); | ||
// ofstream ofs ("message.yaml", ofstream::out); | ||
// for (int x = 1; x <= i; x++) | ||
// { | ||
// ofs << bytesMessage->readByte (); | ||
// } | ||
// ofs.flush (); | ||
// ofs.close (); | ||
// | ||
// try | ||
// { | ||
// std::ifstream fin ("message.yaml"); | ||
// //std::stringstream fin(std::string(bytesMessage->getBodyBytes())); | ||
// YAML::Parser parser (fin); | ||
// YAML::Node doc; | ||
// // We assume only the first doc, need to check with doc.size | ||
// parser.GetNextDocument (doc); | ||
|
||
|
||
/////////////////////// String to YAML | ||
// std::stringstream bodystream (body); | ||
// YAML::Parser bodyparser (bodystream); | ||
// YAML::Node bodydoc; | ||
// std::string action; | ||
// bodyparser.GetNextDocument (bodydoc); | ||
// bodydoc >> action; | ||
// std::cout << action; | ||
|
||
/////////////// Construct body | ||
// // Construct YAML body | ||
// YAML::Emitter reply_message_body_yaml; | ||
// reply_message_body_yaml << "pong"; | ||
|
||
///////////// MD5 sign body | ||
// std::string reply_message_body = reply_message_body_yaml.c_str(); | ||
// std::cout << reply_message_body << std::endl; | ||
// // Append PSK to it | ||
// std::string psk = "unset"; | ||
// std::string body_psk = reply_message_body; | ||
// body_psk.append(psk); | ||
// std::stringstream md5sumstream; | ||
|
||
// // MD5 - https://gist.github.com/2389719 | ||
// // but needs a real string | ||
// // http://social.msdn.microsoft.com/Forums/en/Vsexpressvc/thread/e1774395-ba99-4fe6-98eb-2224a67984b9 | ||
// unsigned char md5_result[MD5_DIGEST_LENGTH]; | ||
// const unsigned char * constStr = reinterpret_cast<const unsigned char *> (body_psk.c_str()); | ||
// MD5(constStr, body_psk.length() , md5_result); | ||
// for (i=0; i < MD5_DIGEST_LENGTH; i++) | ||
// { | ||
// printf("%02x", md5_result[i]); | ||
// char digit[2]; | ||
// sprintf(digit,"%02x", md5_result[i]); | ||
// md5sumstream << digit; | ||
// } | ||
// printf("\\n"); | ||
// | ||
|
||
|
||
// Construct answer | ||
|
||
// YAML::Emitter reply_message_yaml; | ||
// | ||
// reply_message_yaml << YAML::BeginMap; | ||
// reply_message_yaml << YAML::Key << ":msgtime"; | ||
// reply_message_yaml << YAML::Value << 1010101; | ||
// reply_message_yaml << YAML::Key << ":requestid"; | ||
// reply_message_yaml << YAML::Value << requestid; | ||
// reply_message_yaml << YAML::Key << ":body"; | ||
// reply_message_yaml << YAML::Value << reply_message_body; | ||
// reply_message_yaml << YAML::Key << ":senderid"; | ||
// reply_message_yaml << YAML::Value << "mcpp"; | ||
// reply_message_yaml << YAML::Key << ":senderagent"; | ||
// reply_message_yaml << YAML::Value << "discovery"; | ||
// reply_message_yaml << YAML::Key << ":msgtarget"; | ||
// reply_message_yaml << YAML::Value << "/topic/mcollective.discovery.reply"; | ||
// | ||
// reply_message_yaml << YAML::Key << ":hash"; | ||
// reply_message_yaml << YAML::Value << hash; | ||
// reply_message_yaml << YAML::EndMap; | ||
// | ||
// | ||
// // Put it in a string | ||
// std::string reply_message = reply_message_yaml.c_str(); | ||
// std::cout << reply_message << std::endl; | ||
|
||
// // Create the destination (Topic or Queue) | ||
// destination = session->createTopic( "mcollective.discovery.reply" ); | ||
|
||
// // Create a MessageProducer from the Session to the Topic or Queue | ||
// producer = session->createProducer( destination ); | ||
// producer->setDeliveryMode( DeliveryMode::NON_PERSISTENT ); | ||
|
||
// // Create a messages | ||
// BytesMessage* reply = session->createBytesMessage(); | ||
|
||
// reply->writeString(reply_message.c_str()); | ||
// producer->send( reply ); | ||
// printf("reply send \\n"); | ||
|
||
// delete reply; | ||
|
||
// }catch ( CMSException& e ) { | ||
// e.printStackTrace(); | ||
// } |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "mcollective_listener.h" | ||
int main(int argc, char *argv[]) | ||
{ | ||
McollectiveListener a; | ||
a.DoSomething(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "agent/base.h" | ||
#include "mcollective_listener.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <iostream> | ||
|
||
using namespace | ||
std; | ||
|
||
McollectiveListener::McollectiveListener() { | ||
} | ||
|
||
void McollectiveListener::DoSomething() { | ||
|
||
// Initialize the library | ||
//activemq::library::ActiveMQCPP::initializeLibrary (); | ||
|
||
//Set the connection string | ||
std::string brokerURI = "tcp://127.0.0.1:6163" "?wireFormat=stomp"; | ||
|
||
std::cout << "=====================================================\n"; | ||
std::cout << "Starting Listener:" << std::endl; | ||
std::cout << "-----------------------------------------------------\n"; | ||
|
||
// Create a ConnectionFactory | ||
// auto_ptr < ConnectionFactory > | ||
// connectionFactory (ConnectionFactory::createCMSConnectionFactory | ||
// (brokerURI)); | ||
// | ||
|
||
// Create a Connection | ||
// connection = | ||
// connectionFactory->createConnection ("mcollective", "marionette"); | ||
// connection->start (); | ||
// connection->setExceptionListener (this); | ||
|
||
// Create a Session | ||
//session = connection->createSession (Session::AUTO_ACKNOWLEDGE); | ||
|
||
//DiscoveryAgent discoveryAgent(&session); | ||
//PuppetAgent puppetAgent(&session); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef __MCOLLECTIVELISTENER__ | ||
#define __MCOLLECTIVELISTENER__ | ||
|
||
class McollectiveListener | ||
{ | ||
public: | ||
McollectiveListener(); | ||
|
||
/* use virtual otherwise linker will try to perform static linkage */ | ||
virtual void DoSomething(); | ||
|
||
private: | ||
int x; | ||
}; | ||
|
||
#endif |