Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update

Signed-off-by: yayanyang <yayanyang@gmail.com>
  • Loading branch information...
commit 0b624baa6aa34c21d0b93790d06108baea7a15b8 1 parent c6dfd2d
yayanyang authored
2  sys/thread.cpp
View
@@ -92,6 +92,8 @@ LEMON_SYS_API LemonMutex LemonCreateMutex(__lemon_inout LemonErrorInfo* errorCod
LEMON_SYS_API void LemonReleaseMutex(__lemon_in LemonMutex mutex){
DeleteCriticalSection((CRITICAL_SECTION*)mutex);
+
+ delete (CRITICAL_SECTION*)mutex;
}
LEMON_SYS_API void LemonMutexLock(__lemon_in LemonMutex mutex,__lemon_inout LemonErrorInfo * errorCode){
312 trace/abi.cpp
View
@@ -1 +1,313 @@
#include <lemon/trace/abi.h>
+#include <lemon/trace/object.hpp>
+
+#include <lemon/trace/local/provider.hpp>
+#include <lemon/trace/local/controller.hpp>
+
+using namespace lemon;
+using namespace lemon::trace;
+
+LEMON_TRACE_API
+ LemonTraceService
+ LemonCreateTraceService(
+ __lemon_in const char * url,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ return reinterpret_cast<LemonTraceService>( CreateTraceService(url) );
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
+ }
+}
+
+LEMON_TRACE_API
+ void
+ LemonCloseTraceService(
+ __lemon_free LemonTraceService service)
+{
+ delete reinterpret_cast<IService*>(service);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+
+LEMON_TRACE_API
+ LemonTraceController
+ LemonCreateTraceController(
+ __lemon_in LemonTraceService service,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ return reinterpret_cast<LemonTraceController>(new Controller(reinterpret_cast<IService*>(service)));
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
+ }
+}
+
+LEMON_TRACE_API
+ LemonTraceController
+ LemonCreateRemoteTraceController(
+ __lemon_in const char * serviceurl,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_TRACE_API
+ void
+ LemonCloseTraceController(
+ __lemon_free LemonTraceController controller)
+{
+ delete reinterpret_cast<IController*>(controller);
+}
+
+LEMON_TRACE_API
+ LemonTraceConsumer
+ LemonCreateTraceConsumer(
+ __lemon_in LemonTraceController controller,
+ __lemon_in LemonTraceProc proc,
+ __lemon_in void * userdata,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ return reinterpret_cast<LemonTraceConsumer>(new Consumer(reinterpret_cast<IController*>(controller),proc,userdata));
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
+ }
+}
+
+LEMON_TRACE_API
+ void
+ LemonCloseTraceConsumer(
+ __lemon_free LemonTraceConsumer consumer)
+{
+ delete reinterpret_cast<Consumer*>(consumer);
+}
+
+LEMON_TRACE_API
+ void LemonOpenTrace(
+ __lemon_in LemonTraceController controller,
+ __lemon_in const LemonUuid * provider,
+ __lemon_in lemon_trace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ reinterpret_cast<IController*>(controller)->OpenTrace(provider,flag);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+ }
+}
+
+LEMON_TRACE_API
+ void LemonCloseTrace(
+ __lemon_in LemonTraceController controller,
+ __lemon_in const LemonUuid * provider,
+ __lemon_in lemon_trace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ reinterpret_cast<IController*>(controller)->CloseTrace(provider,flag);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+
+LEMON_TRACE_API
+ LemonTraceProvider
+ LemonCreateTraceProvider(
+ __lemon_in LemonTraceService service,
+ __lemon_in const LemonUuid * uuid,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ return reinterpret_cast<LemonTraceProvider>(new Provider(reinterpret_cast<IService*>(service),uuid));
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
+ }
+
+}
+
+LEMON_TRACE_API
+ LemonTraceProvider
+ LemonCreateRemoteTraceProvider(
+ __lemon_in const char * serviceurl,
+ __lemon_in const LemonUuid * uuid,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_TRACE_API
+ void
+ LemonCloseTraceProvider(
+ __lemon_free LemonTraceProvider provider)
+{
+ delete reinterpret_cast<IProvider*>(provider);
+}
+
+LEMON_TRACE_API
+ LemonTraceMessage
+ LemonNewTraceMessage(
+ __lemon_in LemonTraceProvider provider,
+ __lemon_in lemon_trace_flag flag)
+{
+ return reinterpret_cast<LemonTraceMessage>(reinterpret_cast<IProvider*>(provider)->NewMessage(flag));
+}
+
+LEMON_TRACE_API
+ void LemonTrace(
+ __lemon_in LemonTraceProvider provider,
+ __lemon_in LemonTraceMessage message,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ reinterpret_cast<IProvider*>(provider)->Trace(reinterpret_cast<Message*>(message));
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+LEMON_TRACE_API
+ void LemonGetTraceDescription(
+ __lemon_in LemonTraceMessage message,
+ __lemon_inout LemonTraceDescription * description)
+{
+ reinterpret_cast<Message*>(message)->Description(description);
+}
+
+LEMON_TRACE_API
+ size_t LemonTraceWrite(
+ __lemon_in LemonTraceMessage message,
+ __lemon_in const void * data,
+ __lemon_in size_t length,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ return reinterpret_cast<Message*>(message)->Write(data,length);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return (size_t)-1;
+ }
+}
+
+LEMON_TRACE_API
+ size_t LemonTraceRead(
+ __lemon_in LemonTraceMessage message,
+ __lemon_in void * data,
+ __lemon_in size_t length,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ return reinterpret_cast<Message*>(message)->Read(data,length);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return (size_t)-1;
+ }
+}
+
+LEMON_TRACE_API
+ size_t LemonTraceSeek(
+ __lemon_in LemonTraceMessage message,
+ __lemon_in int offset,
+ __lemon_in size_t position)
+{
+ return reinterpret_cast<Message*>(message)->Seek(offset,(lemon::io::seek::Value)position);
+}
+
+LEMON_TRACE_API
+ size_t LemonTraceDump(
+ __lemon_in LemonTraceMessage message,
+ __lemon_in LemonIoWriter writer,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ io::c_writer wrapper(writer);
+
+ return reinterpret_cast<Message*>(message)->Dump(wrapper);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return (size_t)-1;
+ }
+}
+
+LEMON_TRACE_API
+ size_t LemonTraceLoad(
+ __lemon_in LemonTraceMessage message,
+ __lemon_in LemonIoReader reader,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ LEMON_RESET_ERRORINFO(*errorCode);
+
+ io::c_reader wrapper(reader);
+
+ return reinterpret_cast<Message*>(message)->Load(wrapper);
+ }
+ catch(const error_info & e)
+ {
+ *errorCode = e;
+
+ return (size_t)-1;
+ }
+}
12 trace/abi.h
View
@@ -33,6 +33,8 @@
#define LEMON_TRACE_MESSAGE_MAX_LENGTH 1024
+#define LEMON_TRACE_MESSAGE_MAX_CACHE 1024 * 1024
+
typedef lemon_uint64_t lemon_trace_flag;
#define LEMON_MAKE_TRACE_FLAG(level,catalog)\
@@ -98,13 +100,15 @@ LEMON_TRACE_API
void LemonOpenTrace(
__lemon_in LemonTraceController controller,
__lemon_in const LemonUuid * provider,
- __lemon_in lemon_trace_flag flag);
+ __lemon_in lemon_trace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode);
LEMON_TRACE_API
void LemonCloseTrace(
__lemon_in LemonTraceController controller,
__lemon_in const LemonUuid * provider,
- __lemon_in lemon_trace_flag flag);
+ __lemon_in lemon_trace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode);
//////////////////////////////////////////////////////////////////////////
@@ -156,7 +160,7 @@ typedef union LemonTraceNodeName
typedef struct LemonTraceDescription{
- struct sockaddr *Node;
+ const struct sockaddr *Node;
lemon_pid_t ProcessId;
@@ -164,7 +168,7 @@ typedef struct LemonTraceDescription{
lemon_trace_flag Flag;
- LemonUuid *Uuid;
+ const LemonUuid *Uuid;
lemon_uint32_t Length;
58 trace/controller.cpp
View
@@ -1,58 +0,0 @@
-#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);
- }
-}}
51 trace/controller.hpp
View
@@ -1,51 +0,0 @@
-/**
- *
- * @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
73 trace/local/controller.cpp
View
@@ -0,0 +1,73 @@
+#include <lemon/trace/local/controller.hpp>
+
+namespace lemon{namespace trace{
+
+ Controller::Controller(IService * service) :_service(service)
+ {
+ _service->Register(this);
+ }
+
+ Controller::~Controller()
+ {
+ _service->UnRegister(this);
+ }
+
+ lemon_trace_flag Controller::QueryFlag(const LemonUuid * uuid)
+ {
+ 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 * uuid , lemon_trace_flag flag)
+ {
+ {
+ mutex_t::scope_lock lock(_mutex);
+
+ _flags[uuid_t(*uuid)] |= flag;
+ }
+
+ _service->OnFlagChanged(uuid);
+ }
+
+ void Controller::CloseTrace(const LemonUuid * uuid , lemon_trace_flag flag)
+ {
+ {
+ mutex_t::scope_lock lock(_mutex);
+
+ _flags[uuid_t(*uuid)] ^= flag;
+ }
+
+ _service->OnFlagChanged(uuid);
+ }
+
+ void Controller::OnMessage(const Message * message)
+ {
+ mutex_t::scope_lock lock(_consumersMutex);
+
+ Consumers::iterator iter,end = _consumers.end();
+
+ for( iter = _consumers.begin(); iter != end; ++ iter )
+ {
+ (*iter)->OnMessage(message);
+ }
+ }
+
+ void Controller::Register(Consumer * consumer)
+ {
+ mutex_t::scope_lock lock(_consumersMutex);
+
+ _consumers.insert(consumer);
+ }
+
+ void Controller::UnRegister(Consumer * consumer)
+ {
+ mutex_t::scope_lock lock(_consumersMutex);
+
+ _consumers.erase(consumer);
+ }
+}}
60 trace/local/controller.hpp
View
@@ -0,0 +1,60 @@
+/**
+*
+* @file controller
+* @brief Copyright (C) 2012 yayanyang All Rights Reserved
+* @author yayanyang
+* @version 1.0.0.0
+* @date 2012/08/29
+*/
+#ifndef LEMON_TRACE_LOCAL_CONTROLLER_HPP
+#define LEMON_TRACE_LOCAL_CONTROLLER_HPP
+
+#include <set>
+#include <map>
+#include <lemon/trace/object.hpp>
+
+namespace lemon{namespace trace{
+
+ class Controller : public IController
+ {
+ public:
+
+ typedef std::set<Consumer*> Consumers;
+
+ typedef std::map<lemon::uuid_t,lemon_trace_flag> Flags;
+
+ Controller(IService * service);
+
+ ~Controller();
+
+ public:
+
+ lemon_trace_flag QueryFlag(const LemonUuid * uuid);
+
+ void OpenTrace(const LemonUuid * uuid , lemon_trace_flag flag);
+
+ void CloseTrace(const LemonUuid * uuid , lemon_trace_flag flag);
+
+ void OnMessage(const Message * message);
+
+ void Register(Consumer * consumer);
+
+ void UnRegister(Consumer * consumer);
+
+ private:
+
+ IService *_service;
+
+ Consumers _consumers;
+
+ Flags _flags;
+
+ mutex_t _mutex;
+
+ mutex_t _consumersMutex;
+ };
+
+}}
+
+
+#endif //LEMON_TRACE_LOCAL_CONTROLLER_HPP
38 trace/local/provider.cpp
View
@@ -0,0 +1,38 @@
+#include <lemon/trace/local/provider.hpp>
+
+namespace lemon{namespace trace{
+
+ Provider::Provider(IService *service,const LemonUuid * uuid) :_service(service),_uuid(*uuid),_flag(0)
+ {
+ _service->Register(this);
+ }
+
+ Provider::~Provider()
+ {
+ _service->UnRegister(this);
+ }
+ void Provider::OnFlagChanged(lemon_trace_flag flag)
+ {
+ _flag = flag;
+ }
+
+ Message * Provider::NewMessage(lemon_trace_flag flag)
+ {
+ if((_flag & flag) != flag) return NULL;
+
+ if(_message.empty())
+ {
+ _message.reset(new Message(&_uuid));
+ }
+
+ _message->Reset(flag);
+
+ return _message.get();
+ }
+
+ void Provider::Trace(Message * message)
+ {
+ _service->OnMessage(message);
+ }
+
+}}
45 trace/local/provider.hpp
View
@@ -0,0 +1,45 @@
+/**
+*
+* @file provider
+* @brief Copyright (C) 2012 yayanyang All Rights Reserved
+* @author yayanyang
+* @version 1.0.0.0
+* @date 2012/08/29
+*/
+#ifndef LEMON_TRACE_LOCAL_PROVIDER_HPP
+#define LEMON_TRACE_LOCAL_PROVIDER_HPP
+
+#include <lemon/trace/object.hpp>
+
+namespace lemon{namespace trace{
+
+ class Provider : public IProvider
+ {
+ public:
+ Provider(IService *service,const LemonUuid * uuid);
+
+ ~Provider();
+
+ private:
+
+ void OnFlagChanged(lemon_trace_flag flag);
+
+ Message * NewMessage(lemon_trace_flag flag);
+
+ void Trace(Message * message);
+
+ const lemon::uuid_t & Uuid() const { return _uuid; }
+
+ private:
+
+ IService *_service;
+
+ lemon::uuid_t _uuid;
+
+ tlsptr<Message> _message;
+
+ lemon_trace_flag _flag;
+ };
+}}
+
+#endif //LEMON_TRACE_LOCAL_PROVIDER_HPP
137 trace/local/service.cpp
View
@@ -0,0 +1,137 @@
+#include <cassert>
+#include <lemonxx/function/bind.hpp>
+#include <lemon/trace/local/service.hpp>
+
+
+namespace lemon{namespace trace{
+
+ Service::Service() : _exit(false) , _ringbuffer(LEMON_TRACE_MESSAGE_MAX_CACHE)
+ {
+ _dispatchThread.start(lemon::bind(&Service::Dispatch,this));
+ }
+
+ Service::~Service()
+ {
+ {
+ mutex_t::scope_lock lock(_mutex);
+
+ _exit = true;
+
+ _cv.notify();
+ }
+
+ _dispatchThread.join();
+ }
+
+ void Service::Register(IProvider * object)
+ {
+ lemon::mutex_t::scope_lock lock(_providerMutex);
+
+ _providers.insert(object);
+ }
+
+ void Service::UnRegister(IProvider * object)
+ {
+ lemon::mutex_t::scope_lock lock(_providerMutex);
+
+ _providers.erase(object);
+ }
+
+ void Service::Register(IController * object)
+ {
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ _controllers.insert(object);
+ }
+
+ void Service::UnRegister(IController * object)
+ {
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ _controllers.erase(object);
+ }
+
+ void Service::OnMessage(const Message * message)
+ {
+ bool used;
+
+ mutex_t::scope_lock lock(_mutex);
+
+ void * data = _ringbuffer.push_front(used);
+
+ assert( !used );
+
+ io::buffer_writer writer(data,ringbuffer_type::block_size::value);
+
+ message->Dump(writer);
+
+ _cv.notify();
+
+ }
+
+ void Service::OnFlagChanged(const LemonUuid * uuid)
+ {
+ lemon_trace_flag flag = 0;
+ {
+
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ Controllers::iterator iter ,end = _controllers.end();
+
+ for ( iter = _controllers.begin(); iter != end; ++ iter )
+ {
+ flag |= (*iter)->QueryFlag(uuid);
+ }
+ }
+
+ {
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ Providers::iterator iter ,end = _providers.end();
+
+ for ( iter = _providers.begin(); iter != end; ++ iter )
+ {
+ if( (*iter)->Uuid() == *uuid )
+ {
+ (*iter)->OnFlagChanged(flag);
+ }
+ }
+ }
+ }
+
+ void Service::Dispatch()
+ {
+ Message message;
+
+ mutex_t::scope_lock lock(_mutex);
+
+ while(!_exit)
+ {
+ if(_ringbuffer.empty()) { _cv.wait(lock); continue; }
+
+ io::buffer_reader reader(_ringbuffer.pop_front(),ringbuffer_type::block_size::value);
+
+ message.Load(reader);
+
+ {
+ mutex_t::scope_lock::scope_unlock unlock(lock);
+
+ LemonTraceDescription description;
+
+ message.Description(&description);
+
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ Controllers::iterator iter ,end = _controllers.end();
+
+ for ( iter = _controllers.begin(); iter != end; ++ iter )
+ {
+ if( ((*iter)->QueryFlag(description.Uuid) & description.Flag) == description.Flag )
+ {
+ (*iter)->OnMessage(&message);
+ }
+ }
+ }
+ }
+ }
+}}
71 trace/local/service.hpp
View
@@ -0,0 +1,71 @@
+/**
+*
+* @file service
+* @brief Copyright (C) 2012 yayanyang All Rights Reserved
+* @author yayanyang
+* @version 1.0.0.0
+* @date 2012/08/29
+*/
+#ifndef LEMON_TRACE_LOCAL_SERVICE_HPP
+#define LEMON_TRACE_LOCAL_SERVICE_HPP
+#include <set>
+#include <lemon/trace/object.hpp>
+#include <lemonxx/memory/ringbuffer.hpp>
+
+namespace lemon{namespace trace{
+
+ class Service : public IService
+ {
+ public:
+
+ typedef std::set<IProvider*> Providers;
+
+ typedef std::set<IController*> Controllers;
+
+ typedef lemon::memory::ringbuffer::allocator<LEMON_TRACE_MESSAGE_MAX_LENGTH> ringbuffer_type;
+
+ Service();
+
+ ~Service();
+
+ private:
+
+ void Register(IProvider * object);
+
+ void UnRegister(IProvider * object);
+
+ void Register(IController * object);
+
+ void UnRegister(IController * object);
+
+ void OnMessage(const Message * message);
+
+ void OnFlagChanged(const LemonUuid * uuid);
+
+ private:
+
+ void Dispatch();
+
+ private:
+
+ bool _exit;
+
+ Controllers _controllers;
+
+ Providers _providers;
+
+ lemon::mutex_t _controllerMutex;
+
+ lemon::mutex_t _providerMutex;
+
+ lemon::mutex_t _mutex;
+
+ lemon::condition_variable _cv;
+
+ lemon::thread_t _dispatchThread;
+
+ ringbuffer_type _ringbuffer;
+ };
+
+}}
+#endif //LEMON_TRACE_LOCAL_SERVICE_HPP
18 trace/message.cpp
View
@@ -34,6 +34,10 @@ namespace lemon{namespace trace{
_uuid = *uuid;
_threadId = current_thread_id();
+
+ _length = 0;
+
+ _offset = 0;
}
void Message::Reset( lemon_trace_flag flag )
@@ -41,6 +45,10 @@ namespace lemon{namespace trace{
_flag = flag;
_threadId = current_thread_id();
+
+ _length = 0;
+
+ _offset = 0;
}
size_t Message::Read( void * data, size_t length )
@@ -67,6 +75,8 @@ namespace lemon{namespace trace{
_offset += length;
+ if(_offset > _length) _length = (lemon_uint32_t)_offset;
+
return length;
}
@@ -115,7 +125,7 @@ namespace lemon{namespace trace{
return _offset;
}
- void Message::Description( LemonTraceDescription * description )
+ void Message::Description( LemonTraceDescription * description ) const
{
description->Flag = _flag;
@@ -130,7 +140,7 @@ namespace lemon{namespace trace{
description->Uuid = &_uuid;
}
- size_t Message::Dump( io::writer &writer )
+ size_t Message::Dump( io::writer &writer ) const
{
size_t result = writer.write((const byte_t*)&_node,sizeof(_node));
@@ -177,7 +187,7 @@ namespace lemon{namespace trace{
result += reader.read((byte_t*)&tid,sizeof(tid));
- _processid = ntohl(tid);
+ _threadId = ntohl(tid);
result += reader.read((byte_t*)&flag,sizeof(flag));
@@ -185,6 +195,8 @@ namespace lemon{namespace trace{
_flag = flag;
+ result += reader.read((byte_t*)&_uuid,sizeof(uuid_t));
+
result += reader.read((byte_t*)&length,sizeof(length));
_length = ntohl(length);
4 trace/message.hpp
View
@@ -34,9 +34,9 @@ namespace lemon{namespace trace{
size_t Seek( int offset , io::seek::Value position );
- void Description( LemonTraceDescription * description );
+ void Description( LemonTraceDescription * description ) const;
- size_t Dump( io::writer &writer );
+ size_t Dump( io::writer &writer ) const;
size_t Load( io::reader &reader );
27 trace/object.cpp
View
@@ -0,0 +1,27 @@
+#include <lemon/trace/object.hpp>
+#include <lemon/trace/local/service.hpp>
+
+namespace lemon{namespace trace{
+
+ Consumer::Consumer(IController * controller,LemonTraceProc proc, void * userdata)
+ :_controller(controller),_proc(proc),_userdata(userdata)
+ {
+ _controller->Register(this);
+ }
+
+ Consumer::~Consumer()
+ {
+ _controller->UnRegister(this);
+ }
+
+ void Consumer::OnMessage(const Message * message)
+ {
+ _proc((LemonTraceMessage)(message),_userdata);
+ }
+
+ IService * CreateTraceService(const char * /*url*/)
+ {
+ //TODO : parse the url ,create the real service
+ return new Service();
+ }
+}}
98 trace/object.hpp
View
@@ -0,0 +1,98 @@
+/**
+*
+* @file object
+* @brief Copyright (C) 2012 yayanyang All Rights Reserved
+* @author yayanyang
+* @version 1.0.0.0
+* @date 2012/08/29
+*/
+#ifndef LEMON_TRACE_OJBECT_HPP
+#define LEMON_TRACE_OJBECT_HPP
+#include <lemon/trace/abi.h>
+#include <lemonxx/sys/sys.hpp>
+#include <lemon/trace/message.hpp>
+#include <lemonxx/utility/utility.hpp>
+
+
+namespace lemon{namespace trace{
+
+ struct IService;
+
+ struct IProvider;
+
+ struct IController;
+
+ class Consumer;
+
+
+ struct IService : private nocopyable
+ {
+ virtual ~IService() {}
+
+ virtual void Register(IProvider * object) = 0;
+
+ virtual void UnRegister(IProvider * object) = 0;
+
+ virtual void Register(IController * object) = 0;
+
+ virtual void UnRegister(IController * object) = 0;
+
+ virtual void OnMessage(const Message * message) = 0;
+
+ virtual void OnFlagChanged(const LemonUuid * uuid) = 0;
+ };
+
+ struct IProvider : private nocopyable
+ {
+ virtual ~IProvider() {}
+
+ virtual void OnFlagChanged(lemon_trace_flag flag) = 0;
+
+ virtual Message * NewMessage(lemon_trace_flag flag) = 0;
+
+ virtual void Trace(Message * message) = 0;
+
+ virtual const lemon::uuid_t & Uuid() const = 0;
+ };
+
+ struct IController : private nocopyable
+ {
+ virtual ~ IController() {}
+
+ virtual lemon_trace_flag QueryFlag(const LemonUuid * uuid) = 0;
+
+ virtual void OpenTrace(const LemonUuid * uuid , lemon_trace_flag flag) = 0;
+
+ virtual void CloseTrace(const LemonUuid * uuid , lemon_trace_flag flag) = 0;
+
+ virtual void OnMessage(const Message * message) = 0;
+
+ virtual void Register(Consumer * consumer) = 0;
+
+ virtual void UnRegister(Consumer * consumer) = 0;
+ };
+
+ class Consumer : private lemon::nocopyable
+ {
+ public:
+
+ Consumer(IController * controller,LemonTraceProc proc, void * userdata);
+
+ ~Consumer();
+
+ void OnMessage(const Message * message);
+
+ private:
+
+ IController *_controller;
+
+ LemonTraceProc _proc;
+
+ void *_userdata;
+ };
+
+ IService * CreateTraceService(const char * url);
+
+}}
+
+#endif //LEMON_TRACE_OJBECT_HPP
38 trace/provider.cpp
View
@@ -1,38 +0,0 @@
-#include <lemon/trace/service.hpp>
-#include <lemon/trace/message.hpp>
-#include <lemon/trace/provider.hpp>
-
-
-
-namespace lemon{namespace trace{
-
- 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 )
- {
- _flag = flag;
- }
-
- Message * Provider::NewMessage( lemon_trace_flag flag )
- {
- if ( (flag & _flag) == 0 ) return NULL;
-
- if ( _message.empty( ) ) _message.reset( new Message( &_id.Uuid ) );
-
- _message->Reset( flag );
-
- return _message.get( );
- }
-
-}}
76 trace/provider.hpp
View
@@ -1,76 +0,0 @@
-/**
- *
- * @file provider
- * @brief Copyright (C) 2012 yayanyang All Rights Reserved
- * @author yayanyang
- * @version 1.0.0.0
- * @date 2012/08/26
- */
-#ifndef LEMON_TRACE_PROVIDER_HPP
-#define LEMON_TRACE_PROVIDER_HPP
-#include <lemon/trace/abi.h>
-#include <lemonxx/sys/sys.hpp>
-#include <lemonxx/utility/utility.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( Service * service , const ProviderId & id );
-
- virtual ~Provider( );
-
- void OnFlagChanged( lemon_trace_flag flag );
-
- const ProviderId & Id() { return _id; }
-
- Message * NewMessage( lemon_trace_flag flag );
-
- virtual void Trace(const Message * msg) = 0;
-
- private:
-
- Service *_service;
-
- ProviderId _id;
-
- lemon_trace_flag _flag;
-
- tlsptr<Message> _message;
- };
-
-
-}}
-
-#endif // LEMON_TRACE_PROVIDER_HPP
-
107 trace/service.cpp
View
@@ -1,107 +0,0 @@
-#include <cassert>
-#include <lemon/trace/service.hpp>
-#include <lemon/trace/provider.hpp>
-#include <lemon/trace/controller.hpp>
-
-
-namespace lemon{namespace trace{
-
- Service::~Service()
- {
-
- }
-
- void Service::Register( Controller * object )
- {
- lemon::mutex_t::scope_lock lock( _controllersMutex );
-
- _controllers.insert(object);
- }
-
- void Service::Unregister( Controller * object )
- {
- lemon::mutex_t::scope_lock lock( _controllersMutex );
-
- Controllers::iterator iter = _controllers.find( object );
-
- assert( iter != _controllers.end() );
-
- _controllers.erase( iter );
- }
-
- void Service::Register(Provider * object)
- {
- lemon::mutex_t::scope_lock lock( _providersMutex );
-
- _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::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::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);
- }
- }
- }
-
-}}
71 trace/service.hpp
View
@@ -1,71 +0,0 @@
-/**
- *
- * @file service
- * @brief Copyright (C) 2012 yayanyang All Rights Reserved
- * @author yayanyang
- * @version 1.0.0.0
- * @date 2012/08/25
- */
-#ifndef LEMON_TRACE_SERVICE_HPP
-#define LEMON_TRACE_SERVICE_HPP
-#include <set>
-#include <lemon/trace/abi.h>
-#include <lemonxx/sys/sys.hpp>
-#include <lemonxx/utility/utility.hpp>
-
-
-namespace lemon{namespace trace{
-
- class Message;
-
- class Provider;
-
- class Controller;
-
- struct Command;
-
- class Service : private lemon::nocopyable
- {
- public:
-
- typedef std::set<Controller*> Controllers;
-
- typedef std::set<Provider*> Providers;
-
- virtual ~Service();
-
- public:
-
- void Register(Controller * object);
-
- void Unregister(Controller * object);
-
- void Register(Provider * object);
-
- void Unregister(Provider * object);
-
- public:
-
- void OpenTrace( const LemonUuid * provider );
-
- void CloseTrace( const LemonUuid * provider );
-
- void OnTrace( const Message & message );
-
- private:
-
- void OnFlagChanged( const LemonUuid * provider );
-
- private:
-
- Controllers _controllers;
-
- Providers _providers;
-
- lemon::mutex_t _controllersMutex;
-
- lemon::mutex_t _providersMutex;
- };
-}}
-
-#endif // LEMON_TRACE_SERVICE_HPP
Please sign in to comment.
Something went wrong with that request. Please try again.