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 5cda075079310982b675ab01dac27abef0512e70 1 parent e8739ae
yayanyang authored
90 dtrace/abi.cpp
View
@@ -28,4 +28,94 @@ LEMON_DTRACE_API
__lemon_in LemonDTraceService service)
{
delete reinterpret_cast<IService*>(service);
+}
+
+LEMON_DTRACE_API
+ LemonDTraceController
+ LemonCreateDTraceController(
+ __lemon_in LemonDTraceService service,
+ __lemon_inout LemonErrorInfo * errorCode)
+{
+ try
+ {
+ return reinterpret_cast<LemonDTraceController>(reinterpret_cast<IService*>(service)->CreateController());
+ }
+ catch(const lemon::error_info &e)
+ {
+ *errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
+ }
+}
+
+LEMON_DTRACE_API
+ void
+ LemonCloseDTraceController(
+ __lemon_free LemonDTraceController controller )
+{
+ reinterpret_cast<IController*>(controller)->Release();
+}
+
+
+LEMON_DTRACE_API
+ LemonDTraceConsumer
+ LemonCreateDTraceConsumer(
+ __lemon_in LemonDTraceController controller,
+ __lemon_in LemonDTraceConsumerCallback callback,
+ __lemon_in void * userdata,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ return reinterpret_cast<LemonDTraceConsumer>(reinterpret_cast<IController*>(controller)->CreateConsumer(callback,userdata));
+ }
+ catch(const lemon::error_info &e)
+ {
+ *errorCode = e;
+
+ return LEMON_HANDLE_NULL_VALUE;
+ }
+}
+
+LEMON_DTRACE_API
+ void
+ LemonCloseDTraceConsumer(
+ __lemon_free LemonDTraceConsumer consumer)
+{
+ delete reinterpret_cast<Consumer*>(consumer);
+}
+
+
+LEMON_DTRACE_API
+ void LemonOpenTrace(
+ __lemon_in LemonDTraceController controller,
+ __lemon_in const LemonUuid * provider,
+ __lemon_in lemon_dtrace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ reinterpret_cast<IController*>(controller)->OpenTrace(provider,flag);
+ }
+ catch(const lemon::error_info &e)
+ {
+ *errorCode = e;
+ }
+}
+
+LEMON_DTRACE_API
+ void LemonCloseTrace(
+ __lemon_in LemonDTraceController controller,
+ __lemon_in const LemonUuid * provider,
+ __lemon_in lemon_dtrace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode)
+{
+ try
+ {
+ reinterpret_cast<IController*>(controller)->CloseTrace(provider,flag);
+ }
+ catch(const lemon::error_info &e)
+ {
+ *errorCode = e;
+ }
}
40 dtrace/abi.h
View
@@ -23,6 +23,8 @@ LEMON_DECLARE_HANDLE(LemonDTraceController);
typedef lemon_uint64_t lemon_dtrace_flag;
+#define LEMON_DTRACE_MESSAGE_MAX_LENGTH 1024
+
#define LEMON_MAKE_DTRACE_FLAG(level,catalog)\
(((((lemon_uint64_t)level) << 32) & 0xffffffff00000000) |\
(((lemon_uint64_t)catalog) & 0x00000000ffffffff))
@@ -54,5 +56,43 @@ LEMON_DTRACE_API
LemonCloseDTraceService(
__lemon_in LemonDTraceService service);
+LEMON_DTRACE_API
+ LemonDTraceController
+ LemonCreateDTraceController(
+ __lemon_in LemonDTraceService service,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_DTRACE_API
+ void
+ LemonCloseDTraceController(
+ __lemon_free LemonDTraceController controller );
+
+LEMON_DTRACE_API
+ void LemonOpenTrace(
+ __lemon_in LemonDTraceController controller,
+ __lemon_in const LemonUuid * provider,
+ __lemon_in lemon_dtrace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_DTRACE_API
+ void LemonCloseTrace(
+ __lemon_in LemonDTraceController controller,
+ __lemon_in const LemonUuid * provider,
+ __lemon_in lemon_dtrace_flag flag,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_DTRACE_API
+ LemonDTraceConsumer
+ LemonCreateDTraceConsumer(
+ __lemon_in LemonDTraceController controller,
+ __lemon_in LemonDTraceConsumerCallback callback,
+ __lemon_in void * userdata,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_DTRACE_API
+ void
+ LemonCloseDTraceConsumer(
+ __lemon_free LemonDTraceConsumer consumer);
+
#endif //LEMON_DTRACE_ABI_H
9 dtrace/assemblyinfo.lua
View
@@ -1,4 +1,13 @@
assembly =
{
name = "lemon-dtrace";
+
+ errorcode =
+ {
+ {
+ name = "PROVIDER_ID_ERROR";
+
+ descrpition = "there is already a provider,which's uuid is same as the creating one";
+ }
+ };
};
85 dtrace/local/service.cpp
View
@@ -1,42 +1,95 @@
-#include <lemon/sys/assembly.h>
+#include <cassert>
+#include <lemon/dtrace/assembly.h>
#include <lemon/dtrace/local/service.hpp>
+#include <lemon/dtrace/local/provider.hpp>
+#include <lemon/dtrace/local/controller.hpp>
namespace lemon{namespace dtrace{
- IProvider * Service::CreateProvider(const LemonUuid * /*provider*/)
+ IProvider * Service::CreateProvider(const LemonUuid * provider)
{
- error_info errorCode;
+ lemon::mutex_t::scope_lock lock(_providerMutex);
- LEMON_USER_ERROR(errorCode,LEMON_SYS_NOT_IMPLEMENT);
+ if(_providers.end() != _providers.find(*(lemon::uuid_t*)provider))
+ {
+ scope_error_info errorCode;
- throw errorCode;
+ LEMON_USER_ERROR(errorCode,LEMON_DTRACE_PROVIDER_ID_ERROR);
+ }
+
+ IProvider *result = new Provider(this,provider);
+
+ _providers[*(lemon::uuid_t*)provider] = result;
+
+ return result;
}
- void Service::CloseProvider(IProvider * /*provider*/)
+ void Service::CloseProvider(IProvider * provider)
{
- error_info errorCode;
+ lemon::mutex_t::scope_lock lock(_providerMutex);
+
+ Providers::iterator iter = _providers.find(provider->Uuid());
+
+ assert(_providers.end() != iter);
- LEMON_USER_ERROR(errorCode,LEMON_SYS_NOT_IMPLEMENT);
+ _providers.erase(iter);
- throw errorCode;
+ delete provider;
}
IController * Service::CreateController()
{
- error_info errorCode;
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
- LEMON_USER_ERROR(errorCode,LEMON_SYS_NOT_IMPLEMENT);
+ IController * controller = new Controller(this);
- throw errorCode;
+ _controllers.insert(controller);
+
+ return controller;
}
- void Service::CloseController(IController * /*controller*/)
+ void Service::CloseController(IController * controller)
{
- error_info errorCode;
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ {
+ Controllers::iterator iter = _controllers.find(controller);
+
+ assert(iter != _controllers.end());
+
+ _controllers.erase(iter);
+ }
+
+ Controller::Flags flags = dynamic_cast<Controller*>(controller)->GetFlags();
+
+ Controller::Flags::const_iterator iter, end = flags.end();
+
+ for(iter = flags.begin(); iter != end; ++ iter) OnStatusChangedNoLocked(iter->first);
+
+ delete controller;
+ }
+
+ void Service::OnStatusChangedNoLocked(const lemon::uuid_t & id)
+ {
+ lemon_dtrace_flag flags;
+
+ {
+ Controllers::const_iterator iter,end = _controllers.end();
+
+ for(iter = _controllers.begin(); iter != end; ++ iter)
+ {
+ flags |= (*iter)->GetFlag(id);
+ }
+ }
+
+ lemon::mutex_t::scope_lock lock(_providerMutex);
- LEMON_USER_ERROR(errorCode,LEMON_SYS_NOT_IMPLEMENT);
+ Providers::iterator iter = _providers.find(id);
- throw errorCode;
+ if(iter != _providers.end())
+ {
+ iter->second->OnFlagsChanged(flags);
+ }
}
}}
30 dtrace/local/service.hpp
View
@@ -8,7 +8,8 @@
*/
#ifndef LEMON_DTRACE_SERVICE_HPP
#define LEMON_DTRACE_SERVICE_HPP
-
+#include <map>
+#include <set>
#include <lemon/dtrace/object.hpp>
namespace lemon{namespace dtrace{
@@ -16,6 +17,10 @@ namespace lemon{namespace dtrace{
class Service : public IService
{
public:
+
+ typedef std::map<lemon::uuid_t,IProvider*> Providers;
+
+ typedef std::set<IController*> Controllers;
IProvider * CreateProvider(const LemonUuid * provider);
@@ -24,6 +29,29 @@ namespace lemon{namespace dtrace{
IController * CreateController();
void CloseController(IController * controller);
+
+ public:
+
+ void OnStatusChanged(const lemon::uuid_t & id)
+ {
+ lemon::mutex_t::scope_lock lock(_controllerMutex);
+
+ OnStatusChangedNoLocked(id);
+ }
+
+ private:
+
+ void OnStatusChangedNoLocked(const lemon::uuid_t & id);
+
+ private:
+
+ Providers _providers;
+
+ Controllers _controllers;
+
+ lemon::mutex_t _providerMutex;
+
+ lemon::mutex_t _controllerMutex;
};
}}
6 dtrace/object.cpp
View
@@ -8,15 +8,17 @@ namespace lemon{namespace dtrace{
IService * Create(const char * url)
{
+ if(url == NULL) return new Service();
+
std::string val = string_toupper(url);
if(val == "LOCAL")
{
return new Service();
}
- else if(val.find("LISTEN"))
+ else if(val.find("LISTEN") != std::string::npos)
{
- val = val.substr(val.find_first_not_of("://"));
+ val = val.substr(val.find("://") + 3);
size_t pos = val.find(":");
20 dtrace/object.hpp
View
@@ -49,14 +49,18 @@ namespace lemon{namespace dtrace{
virtual Message * CreateMessage(lemon_dtrace_flag flag) = 0;
virtual void CommitMessage(Message * msg) = 0;
+
+ virtual const lemon::uuid_t & Uuid() const = 0;
+
+ virtual void OnFlagsChanged(lemon_dtrace_flag flag) = 0;
};
class IController : private lemon::nocopyable
{
public:
-
- virtual ~IController() {}
+ IController(IService * service):_service(service){}
+
virtual Consumer * CreateConsumer(LemonDTraceConsumerCallback callback,void * userdata) = 0;
virtual void CloseConsumer(Consumer * consumer) = 0;
@@ -64,6 +68,18 @@ namespace lemon{namespace dtrace{
virtual void OpenTrace(const LemonUuid * provider,lemon_dtrace_flag flags) = 0;
virtual void CloseTrace(const LemonUuid * provider,lemon_dtrace_flag flags) = 0;
+
+ virtual lemon_dtrace_flag GetFlag(const lemon::uuid_t & id) const = 0;
+
+ public:
+
+ void Release() { _service->CloseController(this); }
+
+ virtual ~IController() {}
+
+ private:
+
+ IService *_service;
};
class Consumer : private lemon::nocopyable
Please sign in to comment.
Something went wrong with that request. Please try again.