Skip to content

Commit

Permalink
added GetError method to adapter API
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed May 14, 2017
1 parent f84cc7c commit ce9f381
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
7 changes: 7 additions & 0 deletions far/changelog
@@ -1,3 +1,10 @@
drkns 14.05.2017 20:09:37 +0000 - build 4959

1. Расширим немного Adapter API:
BOOL WINAPI GetError(ErrorInfo* info)
- Far вызывает эту функцию после каждого обращения к адаптеру чтобы узнать, всё ли там хорошо.
Если не всё - будет показано сообщение с текстом ошибки.

drkns 13.05.2017 20:07:39 +0000 - build 4958

1. Поправим погнутую сортировку.
Expand Down
38 changes: 34 additions & 4 deletions far/plclass.cpp
Expand Up @@ -1222,7 +1222,7 @@ class custom_plugin_factory: public plugin_factory
Info.Author && *Info.Author)
{
m_Success = CheckVersion(&FAR_VERSION, &Info.MinFarVersion) != FALSE;

ProcessError(L"Initialize");
// TODO: store info, show message if version is bad
}
}
Expand All @@ -1234,13 +1234,16 @@ class custom_plugin_factory: public plugin_factory

ExitInfo Info = { sizeof(Info) };
m_Imports.pFree(&Info);
ProcessError(L"Free");
}

bool Success() const { return m_Success; }

virtual bool IsPlugin(const string& Filename) const override
{
return m_Imports.pIsPlugin(Filename.data()) != FALSE;
const auto Result = m_Imports.pIsPlugin(Filename.data()) != FALSE;
ProcessError(L"IsPlugin");
return Result;
}

virtual plugin_module_ptr Create(const string& Filename) override
Expand All @@ -1251,19 +1254,44 @@ class custom_plugin_factory: public plugin_factory
Global->CatchError();
Module.reset();
}
ProcessError(L"Create");
return Module;
}

virtual bool Destroy(plugin_module_ptr& Module) override
{
const auto Result = m_Imports.pDestroyInstance(static_cast<custom_plugin_module*>(Module.get())->get_opaque()) != FALSE;
Module.reset();
ProcessError(L"Destroy");
return Result;
}

virtual function_address GetFunction(const plugin_module_ptr& Instance, const export_name& Name) override
{
return *Name.UName? m_Imports.pGetFunctionAddress(static_cast<custom_plugin_module*>(Instance.get())->get_opaque(), Name.UName) : nullptr;
if (!*Name.UName)
return nullptr;
const auto Result = m_Imports.pGetFunctionAddress(static_cast<custom_plugin_module*>(Instance.get())->get_opaque(), Name.UName);
ProcessError(L"GetFunction");
return Result;
}

virtual void ProcessError(const wchar_t* Function) const override
{
if (!m_Imports.pGetError)
return;

ErrorInfo Info = { sizeof(Info) };
if (!m_Imports.pGetError(&Info))
return;

std::vector<string> MessageLines;
string Summary = Info.Summary, Description = Info.Description;
const auto Enumerator = enum_tokens(Description, L"\n");
std::transform(ALL_CONST_RANGE(Enumerator), std::back_inserter(MessageLines), [](const string_view& View) { return make_string(View); });
Message(MSG_WARNING | MSG_LEFTALIGN,
Summary,
MessageLines,
{ lng::MOk });
}

private:
Expand All @@ -1274,6 +1302,7 @@ class custom_plugin_factory: public plugin_factory
os::rtdl::function_pointer<BOOL(WINAPI*)(const wchar_t* filename)> pIsPlugin;
os::rtdl::function_pointer<HANDLE(WINAPI*)(const wchar_t* filename)> pCreateInstance;
os::rtdl::function_pointer<void*(WINAPI*)(HANDLE Instance, const wchar_t* functionname)> pGetFunctionAddress;
os::rtdl::function_pointer<BOOL (WINAPI*)(ErrorInfo* info)> pGetError;
os::rtdl::function_pointer<BOOL(WINAPI*)(HANDLE Instance)> pDestroyInstance;
os::rtdl::function_pointer<void (WINAPI*)(const ExitInfo* info)> pFree;

Expand All @@ -1283,10 +1312,11 @@ class custom_plugin_factory: public plugin_factory
INIT_IMPORT(IsPlugin),
INIT_IMPORT(CreateInstance),
INIT_IMPORT(GetFunctionAddress),
INIT_IMPORT(GetError),
INIT_IMPORT(DestroyInstance),
INIT_IMPORT(Free),
#undef INIT_IMPORT
m_IsValid(pInitialize && pIsPlugin && pCreateInstance && pGetFunctionAddress && pDestroyInstance && pFree)
m_IsValid(pInitialize && pIsPlugin && pCreateInstance && pGetFunctionAddress && pGetError && pDestroyInstance && pFree)
{
}

Expand Down
3 changes: 3 additions & 0 deletions far/plclass.hpp
Expand Up @@ -128,6 +128,8 @@ class plugin_factory
virtual bool Destroy(plugin_module_ptr& module) = 0;
virtual function_address GetFunction(const plugin_module_ptr& Instance, const export_name& Name) = 0;

virtual void ProcessError(const wchar_t* Function) const {}

auto GetOwner() const { return m_owner; }
const auto& ExportsNames() const { return m_ExportsNames; }

Expand Down Expand Up @@ -306,6 +308,7 @@ class Plugin: noncopyable
{
detail::ExecuteFunctionImpl(es, reinterpret_cast<prototype_t<T::export_id::value, T::native::value>>(Exports[T::export_id::value].first), std::forward<args>(Args)...);
RethrowIfNeeded(GlobalExceptionPtr());
m_Factory->ProcessError(m_Factory->ExportsNames()[T::export_id::value].UName);
}
catch (const std::exception& e)
{
Expand Down
7 changes: 7 additions & 0 deletions far/plugin.hpp
Expand Up @@ -2989,6 +2989,13 @@ struct GetContentDataInfo
void* Instance;
};

struct ErrorInfo
{
size_t StructSize;
const wchar_t* Summary;
const wchar_t* Description;
};

#ifdef FAR_USE_INTERNALS
#else // ELSE FAR_USE_INTERNALS
static const GUID FarGuid =
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4958)m4_dnl
m4_define(BUILD,4959)m4_dnl

0 comments on commit ce9f381

Please sign in to comment.