Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement trace

Signed-off-by: yayanyang <yayanyang@gmail.com>
  • Loading branch information...
commit c6dfd2d58b8c5250be4f0788e857d2a8e296dda1 1 parent 512cc58
yayanyang authored
View
10 trace/abi.h
@@ -144,6 +144,16 @@ LEMON_TRACE_API
//////////////////////////////////////////////////////////////////////////
//message
+typedef union LemonTraceNodeName
+{
+ struct in_addr IPv4;
+
+ struct in6_addr IPv6;
+
+ struct sockaddr IP;
+
+}LemonTraceNodeName;
+
typedef struct LemonTraceDescription{
struct sockaddr *Node;
View
58 trace/controller.cpp
@@ -0,0 +1,58 @@
+#include <lemon/trace/service.hpp>
+#include <lemon/trace/controller.hpp>
+
+
+namespace lemon{namespace trace{
+
+ Controller::Controller( Service * service )
+ :_service(service)
+ {
+ _service->Register(this);
+ }
+
+ Controller::~Controller()
+ {
+ _service->Unregister(this);
+
+ Flags::const_iterator iter ,end = _flags.end();
+
+ for ( iter = _flags.begin(); iter != end; ++ iter )
+ {
+ _service->CloseTrace(&iter->first);
+ }
+ }
+
+ lemon_trace_flag Controller::Flag(const LemonUuid * uuid)
+ {
+ lemon::mutex_t::scope_lock lock(_mutex);
+
+ Flags::const_iterator iter = _flags.find(lemon::uuid_t(*uuid));
+
+ if ( iter == _flags.end() ) return 0;
+
+ return iter->second;
+ }
+
+
+ void Controller::OpenTrace(const LemonUuid * provider , lemon_trace_flag flag)
+ {
+ {
+ lemon::mutex_t::scope_lock lock(_mutex);
+
+ _flags[lemon::uuid_t(*provider)] |= flag;
+ }
+
+ _service->OpenTrace(provider);
+ }
+
+ void Controller::CloseTrace(const LemonUuid * provider , lemon_trace_flag flag)
+ {
+ {
+ lemon::mutex_t::scope_lock lock(_mutex);
+
+ _flags[lemon::uuid_t(*provider)] ^= flag;
+ }
+
+ _service->CloseTrace(provider);
+ }
+}}
View
51 trace/controller.hpp
@@ -0,0 +1,51 @@
+/**
+ *
+ * @file controller
+ * @brief Copyright (C) 2012 yayanyang All Rights Reserved
+ * @author yayanyang
+ * @version 1.0.0.0
+ * @date 2012/08/28
+ */
+#ifndef LEMON_TRACE_CONTROLLER_HPP
+#define LEMON_TRACE_CONTROLLER_HPP
+#include <map>
+#include <lemon/trace/abi.h>
+#include <lemonxx/sys/sys.hpp>
+#include <lemonxx/utility/utility.hpp>
+
+namespace lemon{namespace trace{
+
+ class Service ;
+
+ class Controller : private lemon::nocopyable
+ {
+ public:
+
+ typedef std::map<lemon::uuid_t,lemon_trace_flag> Flags;
+
+ Controller( Service * service );
+
+ virtual ~Controller();
+
+ lemon_trace_flag Flag(const LemonUuid * uuid);
+
+ void OpenTrace(const LemonUuid * provider , lemon_trace_flag flag);
+
+ void CloseTrace(const LemonUuid * provider , lemon_trace_flag flag);
+
+ public:
+
+ virtual void OnMessage( const Message & message ) = 0;
+
+ private:
+
+ Service *_service;
+
+ Flags _flags;
+
+ lemon::mutex_t _mutex;
+ };
+
+}}
+
+#endif // LEMON_TRACE_CONTROLLER_HPP
View
11 trace/message.hpp
@@ -14,15 +14,6 @@
namespace lemon{namespace trace{
- union Node
- {
- struct in_addr IPv4;
-
- struct in6_addr IPv6;
-
- struct sockaddr IP;
- };
-
class Message : private lemon::nocopyable
{
public:
@@ -51,7 +42,7 @@ namespace lemon{namespace trace{
private:
- Node _node;
+ LemonTraceNodeName _node;
lemon_pid_t _processid;
View
17 trace/provider.cpp
@@ -1,17 +1,22 @@
+#include <lemon/trace/service.hpp>
+#include <lemon/trace/message.hpp>
#include <lemon/trace/provider.hpp>
+
+
namespace lemon{namespace trace{
- Provider::Provider( const LemonUuid * uuid )
- ,_uuid(uuid)
+ Provider::Provider( Service * service , const ProviderId & id )
+ :_service(service)
+ ,_id(id)
,_flag(0)
{
-
+ _service->Register(this);
}
Provider::~Provider( )
{
-
+ _service->Unregister(this);
}
void Provider::OnFlagChanged( lemon_trace_flag flag )
@@ -19,11 +24,11 @@ namespace lemon{namespace trace{
_flag = flag;
}
- void Message * Provider::NewMessage( lemon_trace_flag flag )
+ Message * Provider::NewMessage( lemon_trace_flag flag )
{
if ( (flag & _flag) == 0 ) return NULL;
- if ( _message.empty( ) ) _message.reset( new Message( &_uuid ) );
+ if ( _message.empty( ) ) _message.reset( new Message( &_id.Uuid ) );
_message->Reset( flag );
View
39 trace/provider.hpp
@@ -11,31 +11,58 @@
#include <lemon/trace/abi.h>
#include <lemonxx/sys/sys.hpp>
#include <lemonxx/utility/utility.hpp>
-#include <lemon/trace/message.hpp>
namespace lemon{namespace trace{
class Service;
+ class Message;
+
+ struct ProviderId
+ {
+ LemonTraceNodeName NodeName;
+
+ lemon_pid_t ProcessId;
+
+ lemon::uuid_t Uuid;
+
+ bool operator < (const ProviderId & rhs) const
+ {
+ return memcmp( this , &rhs , sizeof(ProviderId) ) < 0;
+ }
+
+ bool operator > (const ProviderId & rhs) const
+ {
+ return memcmp( this , &rhs , sizeof(ProviderId) ) > 0;
+ }
+
+ bool operator == (const ProviderId & rhs) const
+ {
+ return memcmp( this , &rhs , sizeof(ProviderId) ) == 0;
+ }
+ };
+
class Provider : private lemon::nocopyable
{
public:
- Provider( const LemonUuid * uuid );
+ Provider( Service * service , const ProviderId & id );
virtual ~Provider( );
void OnFlagChanged( lemon_trace_flag flag );
- const uuid_t & Uuid() const { return _uuid; }
+ const ProviderId & Id() { return _id; }
- void Message * NewMessage( lemon_trace_flag flag );
+ Message * NewMessage( lemon_trace_flag flag );
- virtual void OnTrace( Message * message ) = 0;
+ virtual void Trace(const Message * msg) = 0;
private:
- uuid_t _uuid;
+ Service *_service;
+
+ ProviderId _id;
lemon_trace_flag _flag;
View
56 trace/service.cpp
@@ -1,5 +1,7 @@
#include <cassert>
#include <lemon/trace/service.hpp>
+#include <lemon/trace/provider.hpp>
+#include <lemon/trace/controller.hpp>
namespace lemon{namespace trace{
@@ -31,27 +33,75 @@ namespace lemon{namespace trace{
{
lemon::mutex_t::scope_lock lock( _providersMutex );
- //_providers.find(object->)
+ _providers.insert( object );
+
}
void Service::Unregister(Provider * object)
{
+ lemon::mutex_t::scope_lock lock( _controllersMutex );
+
+ Providers::iterator iter = _providers.find( object );
+ assert( iter != _providers.end() );
+
+ _providers.erase( iter );
}
- void Service::OpenTrace(const LemonUuid * provider,lemon_trace_flag flag)
+ void Service::OnFlagChanged( const LemonUuid * provider )
{
+ lemon_trace_flag flag = 0;
+
+ {
+ lemon::mutex_t::scope_lock lock( _controllersMutex );
+
+ Controllers::iterator iter , end = _controllers.end();
+
+ for ( iter = _controllers.begin() ; iter != end; ++ iter )
+ {
+ flag |= (*iter)->Flag(provider);
+ }
+ }
+
+ {
+ lemon::mutex_t::scope_lock lock( _providersMutex );
+
+ Providers::iterator iter , end = _providers.end();
+
+ for ( iter = _providers.begin() ; iter != end; ++ iter )
+ {
+ if( (*iter)->Id().Uuid == *provider )
+ {
+ (*iter)->OnFlagChanged(flag);
+ }
+ }
+ }
}
- void Service::CloseTrace(const LemonUuid * provider,lemon_trace_flag flag)
+ void Service::OpenTrace( const LemonUuid * provider )
{
+ OnFlagChanged(provider);
+
+ }
+ void Service::CloseTrace(const LemonUuid * provider)
+ {
+ OnFlagChanged(provider);
}
void Service::OnTrace(const Message & message)
{
+ {
+ lemon::mutex_t::scope_lock lock( _controllersMutex );
+
+ Controllers::iterator iter , end = _controllers.end();
+ for ( iter = _controllers.begin() ; iter != end; ++ iter )
+ {
+ (*iter)->OnMessage(message);
+ }
+ }
}
}}
View
13 trace/service.hpp
@@ -9,7 +9,6 @@
#ifndef LEMON_TRACE_SERVICE_HPP
#define LEMON_TRACE_SERVICE_HPP
#include <set>
-#include <map>
#include <lemon/trace/abi.h>
#include <lemonxx/sys/sys.hpp>
#include <lemonxx/utility/utility.hpp>
@@ -31,7 +30,7 @@ namespace lemon{namespace trace{
typedef std::set<Controller*> Controllers;
- typedef std::multimap<lemon::uuid_t,Provider*> Providers;
+ typedef std::set<Provider*> Providers;
virtual ~Service();
@@ -47,11 +46,15 @@ namespace lemon{namespace trace{
public:
- void OpenTrace(const LemonUuid * provider,lemon_trace_flag flag);
+ void OpenTrace( const LemonUuid * provider );
- void CloseTrace(const LemonUuid * provider,lemon_trace_flag flag);
+ void CloseTrace( const LemonUuid * provider );
- void OnTrace(const Message & message);
+ void OnTrace( const Message & message );
+
+ private:
+
+ void OnFlagChanged( const LemonUuid * provider );
private:
Please sign in to comment.
Something went wrong with that request. Please try again.