Skip to content

Commit

Permalink
Add:
Browse files Browse the repository at this point in the history
Plugins: TcpClientFactory,TcpServerFactory,HttpSessionFactory 可使用 Plugins 機制載入.
IoManager: 儲存設定, 檢查Sch.
  • Loading branch information
fonwin committed Oct 18, 2018
1 parent 0331921 commit abb7dbf
Show file tree
Hide file tree
Showing 47 changed files with 1,950 additions and 197 deletions.
12 changes: 12 additions & 0 deletions Overview/Misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@

## 設定檔載入工具
* [`fon9/ConfigLoader.hpp`](../fon9/ConfigLoader.hpp)

## 載入模組
### 定義執行入口
* [`fon9/seed/Plugins.hpp`](../fon9/seed/Plugins.hpp)
* `fon9::seed::PluginsDesc`
* `fon9::seed::PluginsPark`
* 範例:
* [TcpClient factory](../fon9/framework/IoFactoryTcpClient.cpp)
* [TcpServer factory](../fon9/framework/IoFactoryTcpServer.cpp)
* [Http session](../fon9/web/HttpPlugins.cpp)
### 載入管理員
* [`fon9/seed/PluginsMgr.hpp`](../fon9/seed/PluginsMgr.hpp)
14 changes: 6 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ libfon9 TODO list
* InnSyncFileList: 同步匯入檔, 可能包含來源 HostId, 定時掃描全部的來源檔.
---------------------------------------
## 系統管理工具
* 盡量從 [非侵入式] 方向思考:
* 例如: 已有一個 `商品資料表`,則現有程式碼不變,
只要設計一個: 連接 `root``商品資料表``entry`,就可以透過該 entry 管理 `商品資料表`


* seed: 資料異動 的 訂閱機制(MaPlugins, MaIo)
* 記錄最後異動(及Submit)的人: User+From;


* WebUI
* TabFlag::NeedsApply:
* 主管確認機制。
Expand Down Expand Up @@ -53,8 +56,6 @@ libfon9 TODO list
* 滑鼠操作:
* double click: Start edit, or [@KeyColumn: Move to sapling].
* 路徑列: 切換路徑 or 輸入路徑
* MaDll
* 如果 Fon9Co 使用 static library, 如何載入執行檔中的動態模組?
* Fon9Co
* Linux: to daemon.
* Windows: install to service.
Expand All @@ -64,13 +65,10 @@ libfon9 TODO list
## 通訊基礎建設
* IoManager/SessionFactory/DeviceFactory
* 提供 IoManager 的使用說明.
* Sch 設定排程時間.
* 註冊 Factory 異動事件, 讓稍晚註冊的 Factory 可以建立 Device.
* NeedsApply
* ip白名單、黑名單?
* Http
* 限制訊息最大長度.
* 如何找到要提供給 HttpHandler,HttpSession 的參數?
* Http SASL: [標準還在草稿階段](https://tools.ietf.org/id/draft-vanrein-httpauth-sasl-00.html)
看起來還有很遠的路要走,所以只好先用 js 頂著。
* HttpMessage 提供可將 chunk data 移除的功能, 避免 chunk data 一直長大.
Expand Down
18 changes: 18 additions & 0 deletions build/vs2015/libfon9/libfon9.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@
<ClInclude Include="..\..\..\fon9\CharAry.hpp" />
<ClInclude Include="..\..\..\fon9\CharVector.hpp" />
<ClInclude Include="..\..\..\fon9\CmdArgs.hpp" />
<ClInclude Include="..\..\..\fon9\ConfigFileBinder.hpp" />
<ClInclude Include="..\..\..\fon9\ConfigLoader.hpp" />
<ClInclude Include="..\..\..\fon9\ConfigParser.hpp" />
<ClInclude Include="..\..\..\fon9\ConfigUtils.hpp" />
<ClInclude Include="..\..\..\fon9\ConsoleIO.hpp" />
<ClInclude Include="..\..\..\fon9\crypto\CryptoTools.hpp" />
<ClInclude Include="..\..\..\fon9\crypto\Sha1.hpp" />
<ClInclude Include="..\..\..\fon9\crypto\Sha256.hpp" />
<ClInclude Include="..\..\..\fon9\DllHandle.hpp" />
<ClInclude Include="..\..\..\fon9\DyObj.hpp" />
<ClInclude Include="..\..\..\fon9\Endian.hpp" />
<ClInclude Include="..\..\..\fon9\ErrC.hpp" />
Expand All @@ -131,6 +134,7 @@
<ClInclude Include="..\..\..\fon9\framework\Framework.hpp" />
<ClInclude Include="..\..\..\fon9\framework\IoFactory.hpp" />
<ClInclude Include="..\..\..\fon9\framework\IoManager.hpp" />
<ClInclude Include="..\..\..\fon9\framework\NamedIoManager.hpp" />
<ClInclude Include="..\..\..\fon9\framework\SeedSession.hpp" />
<ClInclude Include="..\..\..\fon9\HostId.hpp" />
<ClInclude Include="..\..\..\fon9\InnDbf.hpp" />
Expand Down Expand Up @@ -194,7 +198,11 @@
<ClInclude Include="..\..\..\fon9\intrusive_ref_counter.hpp" />
<ClInclude Include="..\..\..\fon9\MustLock.hpp" />
<ClInclude Include="..\..\..\fon9\SchTask.hpp" />
<ClInclude Include="..\..\..\fon9\seed\ConfigGridView.hpp" />
<ClInclude Include="..\..\..\fon9\seed\FieldSchCfgStr.hpp" />
<ClInclude Include="..\..\..\fon9\seed\NamedPark.hpp" />
<ClInclude Include="..\..\..\fon9\seed\Plugins.hpp" />
<ClInclude Include="..\..\..\fon9\seed\PluginsMgr.hpp" />
<ClInclude Include="..\..\..\fon9\seed\SeedFairy.hpp" />
<ClInclude Include="..\..\..\fon9\seed\MaTree.hpp" />
<ClInclude Include="..\..\..\fon9\seed\PodOp.hpp" />
Expand Down Expand Up @@ -223,6 +231,7 @@
<ClInclude Include="..\..\..\fon9\seed\Tree.hpp" />
<ClInclude Include="..\..\..\fon9\seed\TreeLockContainerT.hpp" />
<ClInclude Include="..\..\..\fon9\seed\TreeOp.hpp" />
<ClInclude Include="..\..\..\fon9\SimpleFactory.hpp" />
<ClInclude Include="..\..\..\fon9\SleepPolicy.hpp" />
<ClInclude Include="..\..\..\fon9\SortedVector.hpp" />
<ClInclude Include="..\..\..\fon9\SpinMutex.hpp" />
Expand Down Expand Up @@ -302,20 +311,24 @@
<ClCompile Include="..\..\..\fon9\buffer\MemBlock.cpp" />
<ClCompile Include="..\..\..\fon9\ByteVector.cpp" />
<ClCompile Include="..\..\..\fon9\CmdArgs.cpp" />
<ClCompile Include="..\..\..\fon9\ConfigFileBinder.cpp" />
<ClCompile Include="..\..\..\fon9\ConfigLoader.cpp" />
<ClCompile Include="..\..\..\fon9\ConfigParser.cpp" />
<ClCompile Include="..\..\..\fon9\ConsoleIO.cpp" />
<ClCompile Include="..\..\..\fon9\crypto\Sha1.cpp" />
<ClCompile Include="..\..\..\fon9\crypto\Sha256.cpp" />
<ClCompile Include="..\..\..\fon9\DllHandle.cpp" />
<ClCompile Include="..\..\..\fon9\ErrC.cpp" />
<ClCompile Include="..\..\..\fon9\FdrNotify.cpp" />
<ClCompile Include="..\..\..\fon9\File.cpp" />
<ClCompile Include="..\..\..\fon9\FileAppender.cpp" />
<ClCompile Include="..\..\..\fon9\FilePath.cpp" />
<ClCompile Include="..\..\..\fon9\framework\Framework.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoFactory.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoFactoryTcpClient.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoFactoryTcpServer.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoManager.cpp" />
<ClCompile Include="..\..\..\fon9\framework\NamedIoManager.cpp" />
<ClCompile Include="..\..\..\fon9\framework\SeedSession.cpp" />
<ClCompile Include="..\..\..\fon9\HostId.cpp" />
<ClCompile Include="..\..\..\fon9\InnFile.cpp" />
Expand Down Expand Up @@ -358,7 +371,11 @@
<ClCompile Include="..\..\..\fon9\DecBase.cpp" />
<ClCompile Include="..\..\..\fon9\FmtDef.cpp" />
<ClCompile Include="..\..\..\fon9\SchTask.cpp" />
<ClCompile Include="..\..\..\fon9\seed\ConfigGridView.cpp" />
<ClCompile Include="..\..\..\fon9\seed\FieldSchCfgStr.cpp" />
<ClCompile Include="..\..\..\fon9\seed\NamedPark.cpp" />
<ClCompile Include="..\..\..\fon9\seed\Plugins.cpp" />
<ClCompile Include="..\..\..\fon9\seed\PluginsMgr.cpp" />
<ClCompile Include="..\..\..\fon9\seed\SeedFairy.cpp" />
<ClCompile Include="..\..\..\fon9\seed\MaTree.cpp" />
<ClCompile Include="..\..\..\fon9\seed\PodOp.cpp" />
Expand Down Expand Up @@ -396,6 +413,7 @@
<ClCompile Include="..\..\..\fon9\web\HttpParser.cpp" />
<ClCompile Include="..\..\..\fon9\web\HttpHandler.cpp" />
<ClCompile Include="..\..\..\fon9\web\HttpSession.cpp" />
<ClCompile Include="..\..\..\fon9\web\HttpPlugins.cpp" />
<ClCompile Include="..\..\..\fon9\web\UrlCodec.cpp" />
<ClCompile Include="..\..\..\fon9\web\WebSocket.cpp" />
<ClCompile Include="..\..\..\fon9\web\WebSocketAuther.cpp" />
Expand Down
54 changes: 54 additions & 0 deletions build/vs2015/libfon9/libfon9.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,33 @@
<ClInclude Include="..\..\..\fon9\StrVref.hpp">
<Filter>Header Files\_base\_AlNum / StrTools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\DllHandle.hpp">
<Filter>Header Files\_base\_Tools / Utility</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\seed\Plugins.hpp">
<Filter>Header Files\seed\_tools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\seed\PluginsMgr.hpp">
<Filter>Header Files\seed\_tools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\ConfigUtils.hpp">
<Filter>Header Files\_base\_Tools / Utility</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\ConfigFileBinder.hpp">
<Filter>Header Files\_base\_File</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\framework\NamedIoManager.hpp">
<Filter>Header Files\framework</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\seed\ConfigGridView.hpp">
<Filter>Header Files\seed\_tools</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\seed\FieldSchCfgStr.hpp">
<Filter>Header Files\seed\_fields</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\SimpleFactory.hpp">
<Filter>Header Files\_base\_Tools / Utility</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\README.md" />
Expand Down Expand Up @@ -1114,5 +1141,32 @@
<ClCompile Include="..\..\..\fon9\seed\TabTreeOp.cpp">
<Filter>Source Files\seed\_tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\DllHandle.cpp">
<Filter>Source Files\_base\_Tools / Utility</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\seed\Plugins.cpp">
<Filter>Source Files\seed\_tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\seed\PluginsMgr.cpp">
<Filter>Source Files\seed\_tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\ConfigFileBinder.cpp">
<Filter>Source Files\_base\_File</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\framework\NamedIoManager.cpp">
<Filter>Source Files\framework</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\framework\IoFactory.cpp">
<Filter>Source Files\framework</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\web\HttpPlugins.cpp">
<Filter>Source Files\web</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\seed\ConfigGridView.cpp">
<Filter>Source Files\seed\_tools</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\seed\FieldSchCfgStr.cpp">
<Filter>Source Files\seed\_fields</Filter>
</ClCompile>
</ItemGroup>
</Project>
8 changes: 7 additions & 1 deletion fon9/AQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ fon9_WARN_DISABLE_PADDING;
/// struct TaskInvoker {
/// /// - 把 this->TakeCall 加入 work thread.
/// /// - 須確保在 this->TakeCall() 執行前 AQueue 不能被解構.
/// void MakeCallForWork();
/// template <class WorkLocker>
/// void MakeCallForWork(WorkLocker& worker);
/// /// - 執行 task.
/// void Invoke(Task& task);
/// };
Expand Down Expand Up @@ -285,6 +286,11 @@ class AQueue {
}
}

bool InTakingCallThread() {
WorkLocker worker{this->WorkController_};
return worker->InTakingCallThread();
}

private:
void AfterAddTask(WorkLocker& worker) {
if (worker->WorkingTaskKind_ == AQueueTaskKind::Empty)
Expand Down
10 changes: 9 additions & 1 deletion fon9/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(fon9src
CmdArgs.cpp
ConfigLoader.cpp
ConfigParser.cpp
DllHandle.cpp

File.cpp
FilePath.cpp
Expand All @@ -40,6 +41,7 @@ set(fon9src
FileAppender.cpp
LogFile.cpp
FdrNotify.cpp
ConfigFileBinder.cpp

InnFile.cpp
InnSyncer.cpp
Expand Down Expand Up @@ -102,13 +104,17 @@ set(fon9src
seed/FieldBytes.cpp
seed/FieldChars.cpp
seed/FieldDyBlob.cpp
seed/FieldSchCfgStr.cpp
seed/SeedSearcher.cpp
seed/SeedAcl.cpp
seed/SeedFairy.cpp
seed/SeedVisitor.cpp
seed/SysEnv.cpp
seed/CloneTree.cpp
seed/TabTreeOp.cpp
seed/Plugins.cpp
seed/PluginsMgr.cpp
seed/ConfigGridView.cpp

crypto/Sha1.cpp
crypto/Sha256.cpp
Expand All @@ -128,11 +134,13 @@ set(fon9src
framework/Framework.cpp
framework/SeedSession.cpp
framework/IoManager.cpp
framework/NamedIoManager.cpp
framework/IoFactory.cpp
framework/IoFactoryTcpClient.cpp
framework/IoFactoryTcpServer.cpp
)
add_library(fon9_s STATIC ${fon9src})
target_link_libraries(fon9_s pthread rt)
target_link_libraries(fon9_s pthread rt dl)

add_library(fon9 SHARED ${fon9src})
target_link_libraries(fon9 pthread rt dl)
Expand Down
63 changes: 63 additions & 0 deletions fon9/ConfigFileBinder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// \file fon9/ConfigFileBinder.cpp
// \author [email protected]
#include "fon9/ConfigFileBinder.hpp"
#include "fon9/File.hpp"
#include "fon9/Log.hpp"

namespace fon9 {

static std::string MakeErr(StrView logHeader, StrView func, File::Result fres, File& fd) {
std::string errstr = RevPrintTo<std::string>("func=", func, '|', fres, "|file=", fd.GetOpenName());
if (logHeader.begin() != nullptr)
fon9_LOG_ERROR(logHeader, '|', errstr);
return errstr;
}
static std::string CheckRW(StrView logHeader, StrView func, File::Result fres, File::SizeType expected, File& fd) {
if (!fres)
return MakeErr(logHeader, func, fres, fd);
if (fres.GetResult() == expected)
return std::string{};
std::string errstr = RevPrintTo<std::string>("func=", func,
"|err.size=", fres.GetResult(),
"|expected=", expected,
"|file=", fd.GetOpenName());
if (logHeader.begin() != nullptr)
fon9_LOG_ERROR(logHeader, '|', errstr);
return errstr;
}

std::string ConfigFileBinder::OpenRead(StrView logHeader, std::string cfgfn) {
this->FileName_ = cfgfn;
File fd;
auto fres = fd.Open(std::move(cfgfn), FileMode::Read);
if (!fres)
return MakeErr(logHeader, "Open", fres, fd);
fres = fd.GetFileSize();
if (!fres)
return MakeErr(logHeader, "GetFileSize", fres, fd);
this->ConfigStr_.resize(fres.GetResult());
if (this->ConfigStr_.size() <= 0)
return std::string{};
fres = fd.Read(0, &*this->ConfigStr_.begin(), this->ConfigStr_.size());
return CheckRW(logHeader, "Read", fres, this->ConfigStr_.size(), fd);
}
std::string ConfigFileBinder::Write(StrView logHeader, std::string cfgstr) {
if (this->ConfigStr_ == cfgstr)
return std::string{};
if (this->FileName_.empty()) {
this->ConfigStr_ = std::move(cfgstr);
return std::string{};
}
File fd;
auto fres = fd.Open(this->FileName_, FileMode::Write | FileMode::CreatePath | FileMode::Trunc);
if (!fres)
return MakeErr(logHeader, "Open", fres, fd);
fres = fd.Write(0, &*cfgstr.begin(), cfgstr.size());
std::string errmsg = CheckRW(logHeader, "Write", fres, cfgstr.size(), fd);
if (errmsg.empty())
this->ConfigStr_ = std::move(cfgstr);
return errmsg;
}

} // namespace

41 changes: 41 additions & 0 deletions fon9/ConfigFileBinder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// \file fon9/ConfigFileBinder.cpp
// \author [email protected]
#ifndef __fon9_ConfigFileBinder_hpp__
#define __fon9_ConfigFileBinder_hpp__
#include "fon9/StrView.hpp"

namespace fon9 {

/// \ingroup Misc
/// - 透過檔案讀/寫設定.
/// - 僅負責讀寫, 不解釋設定內容.
class fon9_API ConfigFileBinder {
std::string FileName_;
std::string ConfigStr_;
public:
bool HasBinding() const {
return !this->FileName_.empty();
}

/// 開啟設定檔, 載入內容, 若有失敗則傳回錯誤訊息.
/// - retval.empty() 表示成功, 可透過 GetConfigStr() 取得載入的內容.
/// - 若有失敗, 除了傳回錯誤訊息外, 如果 logHeader != nullptr 則還會透過 log 記錄錯誤訊息.
std::string OpenRead(StrView logHeader, std::string cfgfn);

/// OpenRead() 成功之後, 透過這裡取得檔案(設定)內容.
/// 僅完整德將檔案內容讀入, 不解釋其內容.
const std::string& GetConfigStr() const {
return this->ConfigStr_;
}

/// 寫設定有變動時, 將新的設定寫回設定檔.
/// - 設定檔為當初透過 OpenRead() 的 cfgfn;
/// 若 cfgfn.empty() 或沒有呼叫過 OpenRead(); 則只會更新 GetConfigStr();
/// - 若 cfgstr 與當初讀入的一樣, 則不會有寫入的動作.
/// - 若有失敗, 除了傳回錯誤訊息外, 如果 logHeader != nullptr 則還會透過 log 記錄錯誤訊息.
std::string Write(StrView logHeader, std::string cfgstr);
};

} // namespace

#endif//__fon9_ConfigFileBinder_hpp__
Loading

0 comments on commit abb7dbf

Please sign in to comment.