Skip to content

Commit

Permalink
Add IoManager, HttpParser.
Browse files Browse the repository at this point in the history
  • Loading branch information
fonwin committed Aug 23, 2018
1 parent 7738951 commit 3b2f825
Show file tree
Hide file tree
Showing 42 changed files with 1,567 additions and 139 deletions.
5 changes: 5 additions & 0 deletions Overview/Manage.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 51,11 @@
---------------------------------------

## 通訊管理
* IoManager
* 那些東西有記錄 log?
* DeviceState/dtor: 使用 TRACE 紀錄.
* SessionState: 使用 INFO 紀錄.
* Id 可為任意 ASCII 字串.

---------------------------------------

Expand Down
13 changes: 12 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,8 @@ libfon9 TODO list
## 演算法/容器
---------------------------------------
## 雜項
* DefaultThreadPoolArgs: ThreadCount_, CpuAffinity_;

---------------------------------------
## 檔案/儲存/載入
* Serialize/Deserialize
Expand All @@ -23,12 25,21 @@ libfon9 TODO list
* Fon9Co
* Linux: to daemon.
* Windows: install to service.
* 啟動時參數指定預設的 LogLevel.
* SeedSession/SeedFairy/SeedSearcher: 還需要再整理其中的關連(並重新命名).

---------------------------------------
## 通訊基礎建設
* IoManager/SessionFactory/DeviceFactory/FactoryPark
* IoManager/SessionFactory/DeviceFactory
* 提供 IoManager 的使用說明.
* Sch 設定排程時間.
* 註冊 Factory 異動事件, 讓稍晚註冊的 Factory 可以建立 Device.
* NeedsApply
* HttpMan: ip白名單、黑名單?
* UDP/Multicast
* FileDevice
* TLS
* Device.DeviceCommand() 傳回值: success message or fail message.
* DeviceId 拿掉開頭的 '|' 字元.
---------------------------------------
## Simple FIX engine
4 changes: 4 additions & 0 deletions build/vs2015/Fon9Co/Fon9Co.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 80,10 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\fon9\framework\Fon9Co.cpp" />
<ClCompile Include="..\..\..\fon9\framework\HttpManSession.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\fon9\framework\HttpManSession.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
8 changes: 8 additions & 0 deletions build/vs2015/Fon9Co/Fon9Co.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 17,13 @@
<ClCompile Include="..\..\..\fon9\framework\Fon9Co.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\framework\HttpManSession.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\fon9\framework\HttpManSession.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions build/vs2015/libfon9/libfon9.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 128,8 @@
<ClInclude Include="..\..\..\fon9\FileAppender.hpp" />
<ClInclude Include="..\..\..\fon9\FilePath.hpp" />
<ClInclude Include="..\..\..\fon9\framework\Framework.hpp" />
<ClInclude Include="..\..\..\fon9\framework\IoFactory.hpp" />
<ClInclude Include="..\..\..\fon9\framework\IoManager.hpp" />
<ClInclude Include="..\..\..\fon9\framework\SeedSession.hpp" />
<ClInclude Include="..\..\..\fon9\HostId.hpp" />
<ClInclude Include="..\..\..\fon9\InnDbf.hpp" />
Expand Down Expand Up @@ -246,6 248,7 @@
<ClInclude Include="..\..\..\fon9\Unaligned.hpp" />
<ClInclude Include="..\..\..\fon9\Utility.hpp" />
<ClInclude Include="..\..\..\fon9\WaitPolicy.hpp" />
<ClInclude Include="..\..\..\fon9\web\HttpParser.hpp" />
<ClInclude Include="..\..\..\fon9\Worker.hpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -294,6 297,9 @@
<ClCompile Include="..\..\..\fon9\FileAppender.cpp" />
<ClCompile Include="..\..\..\fon9\FilePath.cpp" />
<ClCompile Include="..\..\..\fon9\framework\Framework.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoFactoryTcpClient.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoFactoryTcpServer.cpp" />
<ClCompile Include="..\..\..\fon9\framework\IoManager.cpp" />
<ClCompile Include="..\..\..\fon9\framework\SeedSession.cpp" />
<ClCompile Include="..\..\..\fon9\HostId.cpp" />
<ClCompile Include="..\..\..\fon9\InnFile.cpp" />
Expand Down Expand Up @@ -365,6 371,7 @@
<ClCompile Include="..\..\..\fon9\TimeStamp.cpp" />
<ClCompile Include="..\..\..\fon9\ToStr.cpp" />
<ClCompile Include="..\..\..\fon9\ToStrFmt.cpp" />
<ClCompile Include="..\..\..\fon9\web\HttpParser.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
27 changes: 27 additions & 0 deletions build/vs2015/libfon9/libfon9.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 144,12 @@
<Filter Include="Source Files\seed\_tools">
<UniqueIdentifier>{b380d7de-1187-4b29-9910-0a3993f8b45e}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\web">
<UniqueIdentifier>{8aec7ba0-b31e-415b-9e7a-d7573ca64ba3}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\web">
<UniqueIdentifier>{e3920260-e31f-4599-9e20-53816d652f0f}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\fon9\sys\Config.h">
Expand Down Expand Up @@ -665,6 671,15 @@
<ClInclude Include="..\..\..\fon9\ConfigParser.hpp">
<Filter>Header Files\_base\_Tools / Utility</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\framework\IoFactory.hpp">
<Filter>Header Files\framework</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\framework\IoManager.hpp">
<Filter>Header Files\framework</Filter>
</ClInclude>
<ClInclude Include="..\..\..\fon9\web\HttpParser.hpp">
<Filter>Header Files\web</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\README.md" />
Expand Down Expand Up @@ -1003,5 1018,17 @@
<ClCompile Include="..\..\..\fon9\ConfigParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\framework\IoFactoryTcpClient.cpp">
<Filter>Source Files\framework</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\framework\IoFactoryTcpServer.cpp">
<Filter>Source Files\framework</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\framework\IoManager.cpp">
<Filter>Source Files\framework</Filter>
</ClCompile>
<ClCompile Include="..\..\..\fon9\web\HttpParser.cpp">
<Filter>Source Files\web</Filter>
</ClCompile>
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion fon9/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 77,8 @@ set(fon9src
io/FdrTcpClient.cpp
io/FdrTcpServer.cpp

web/HttpParser.cpp

seed/SeedBase.cpp
seed/Tab.cpp
seed/Layout.cpp
Expand Down Expand Up @@ -112,14 114,17 @@ set(fon9src

framework/Framework.cpp
framework/SeedSession.cpp
framework/IoManager.cpp
framework/IoFactoryTcpClient.cpp
framework/IoFactoryTcpServer.cpp
)
add_library(fon9_s STATIC ${fon9src})
target_link_libraries(fon9_s pthread rt)

add_library(fon9 SHARED ${fon9src})
target_link_libraries(fon9 pthread rt dl)

add_executable(Fon9Co framework/Fon9Co.cpp)
add_executable(Fon9Co framework/Fon9Co.cpp framework/HttpManSession.cpp)
target_link_libraries(Fon9Co pthread fon9)

# unit tests: Tools / Utility
Expand Down
2 changes: 1 addition & 1 deletion fon9/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 55,7 @@ fon9_API void RevPrint(RevBuffer& rbuf, const ConfigParser::ErrorEventArgs& e) {
}

bool ConfigParserMsg::OnErrorBreak(ErrorEventArgs& e) {
RevPrint(this->RBuf_, "err=", e, '\n');
RevPrint(this->RBuf_, "|err=", e);
return false;
}

Expand Down
12 changes: 10 additions & 2 deletions fon9/ConsoleIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 4,23 @@
#include <stdio.h>
#include <ctype.h>

#ifndef fon9_WINDOWS
#ifdef fon9_WINDOWS
fon9_BEFORE_INCLUDE_STD
#include <io.h>
fon9_AFTER_INCLUDE_STD
#else
#include <unistd.h>
#include <termios.h>
#include <string.h>
#endif

namespace fon9 {

#ifndef fon9_WINDOWS
#ifdef fon9_WINDOWS
fon9_API int getch() {
return _isatty(_fileno(stdin)) ? _getch() : fgetc(stdin);
}
#else
fon9_API int getch() {
struct termios cur;
memset(&cur, 0, sizeof(cur));
Expand Down
6 changes: 0 additions & 6 deletions fon9/ConsoleIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 12,7 @@

namespace fon9 {

#ifdef fon9_WINDOWS
inline int getch() {
return ::_getch();
}
#else
extern fon9_API int getch();
#endif

/// \ingroup Misc
/// 要求使用者從 console 輸入密碼.
Expand Down
32 changes: 32 additions & 0 deletions fon9/StrTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 55,38 @@ const char Digs0099[] =

//--------------------------------------------------------------------------//

fon9_API bool iequals(StrView a, StrView r) {
auto sz = a.size();
if (sz != r.size())
return false;
const char* p = r.begin();
for (char ch : a) {
if (tolower(ch) != tolower(*p ))
return false;
}
return true;
}
fon9_API int icompare(const char* a, const char* b, size_t sz) {
while (sz) {
if (int c = tolower(*a ) - tolower(*b ))
return c;
--sz;
}
return 0;
}
fon9_API int icompare(StrView a, StrView r) {
const size_t lhsSize = a.size();
const size_t rhsSize = r.size();
const size_t minSize = (lhsSize < rhsSize ? lhsSize : rhsSize);
if (const int retval = icompare(a.begin(), r.begin(), minSize))
return retval;
return (lhsSize < rhsSize ? -1
: lhsSize > rhsSize ? 1
: 0);
}

//--------------------------------------------------------------------------//

fon9_API StrView StrView_TruncUTF8(StrView utf8str, size_t expectLen) {
if (utf8str.size() <= expectLen)
return utf8str;
Expand Down
7 changes: 7 additions & 0 deletions fon9/StrTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 79,9 @@ inline char* Put2Digs(char* pout, uint8_t i00_99) {

//--------------------------------------------------------------------------//

constexpr int toupper(int ch) { return 'a' <= ch && ch <= 'z' ? (ch - 'a' 'A') : ch; }
constexpr int tolower(int ch) { return 'A' <= ch && ch <= 'Z' ? (ch - 'A' 'a') : ch; }

constexpr bool iscntrl(int ch) { return static_cast<unsigned>(ch) <= '\x1f' || ch == '\x7f'; }
constexpr bool isprint(int ch) { return '\x20' <= ch && ch <= '\x7e'; }
constexpr bool isspace(int ch) { return '\x20' == ch || ('\x9' <= ch && ch <= '\xd'); }
Expand All @@ -101,6 104,10 @@ constexpr bool isnotlower(int ch) { return !islower(ch); }
constexpr bool isnotalpha(int ch) { return !isalpha(ch); }
constexpr bool isnotdigit(int ch) { return !isdigit(ch); }

fon9_API bool iequals(StrView a, StrView r);
fon9_API int icompare(const char* a, const char* b, size_t sz);
fon9_API int icompare(StrView a, StrView r);

//--------------------------------------------------------------------------//

/// \ingroup AlNum
Expand Down
8 changes: 4 additions & 4 deletions fon9/auth/PolicyMaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 167,7 @@ class DetailPolicyTreeTable : public DetailPolicyTree {
TreeOp(DetailPolicyTree& tree) : base(tree) {
}

virtual void GridView(const seed::GridViewRequest& req, seed::FnGridViewOp fnCallback) {
void GridView(const seed::GridViewRequest& req, seed::FnGridViewOp fnCallback) override {
seed::GridViewResult res{this->Tree_, req.Tab_};
{
DetailTableLocker map{static_cast<DetailPolicyTreeTable*>(&this->Tree_)->DetailTable_};
Expand All @@ -183,7 183,7 @@ class DetailPolicyTreeTable : public DetailPolicyTree {
if (op.IsModified_ || isForceWrite)
static_cast<DetailPolicyTree*>(&this->Tree_)->WriteUpdated(lockedMap);
}
virtual void Get(StrView strKeyText, seed::FnPodOp fnCallback) override {
void Get(StrView strKeyText, seed::FnPodOp fnCallback) override {
{
DetailTableLocker lockedMap{static_cast<DetailPolicyTreeTable*>(&this->Tree_)->DetailTable_};
auto ifind = this->GetIteratorForPod(*lockedMap, strKeyText);
Expand All @@ -194,7 194,7 @@ class DetailPolicyTreeTable : public DetailPolicyTree {
} // unlock.
fnCallback(seed::PodOpResult{this->Tree_, seed::OpResult::not_found_key, strKeyText}, nullptr);
}
virtual void Add(StrView strKeyText, seed::FnPodOp fnCallback) override {
void Add(StrView strKeyText, seed::FnPodOp fnCallback) override {
if (this->IsTextBegin(strKeyText) || this->IsTextEnd(strKeyText)) {
fnCallback(seed::PodOpResult{this->Tree_, seed::OpResult::not_found_key, strKeyText}, nullptr);
return;
Expand All @@ -210,7 210,7 @@ class DetailPolicyTreeTable : public DetailPolicyTree {
}
this->OnPodOp(lockedMap, strKeyText, *ifind, std::move(fnCallback), isForceWrite);
}
virtual void Remove(StrView strKeyText, seed::Tab* tab, seed::FnPodRemoved fnCallback) override {
void Remove(StrView strKeyText, seed::Tab* tab, seed::FnPodRemoved fnCallback) override {
seed::PodRemoveResult res{this->Tree_, seed::OpResult::not_found_key, strKeyText, tab};
PodKey key{KeyMaker::StrToKey(strKeyText)};
{
Expand Down
1 change: 0 additions & 1 deletion fon9/auth/PolicyTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,6 @@ struct fon9_API PolicyMapsImpl {

void WriteUpdated(PolicyItem& rec);
};

using PolicyMaps = MustLock<PolicyMapsImpl>;

//--------------------------------------------------------------------------//
Expand Down
8 changes: 4 additions & 4 deletions fon9/auth/PolicyTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 62,7 @@ struct PolicyTree::TreeOp : public seed::TreeOp {
FieldsCellRevPrint(tab->Fields_, seed::SimpleRawRd{**ivalue}, rbuf, seed::GridViewResult::kCellSplitter);
RevPrint(rbuf, (*ivalue)->PolicyId_);
}
virtual void GridView(const seed::GridViewRequest& req, seed::FnGridViewOp fnCallback) {
void GridView(const seed::GridViewRequest& req, seed::FnGridViewOp fnCallback) override {
seed::GridViewResult res{this->Tree_, req.Tab_};
{
PolicyMaps::Locker maps{static_cast<PolicyTree*>(&this->Tree_)->PolicyMaps_};
Expand All @@ -80,7 80,7 @@ struct PolicyTree::TreeOp : public seed::TreeOp {
maps->WriteUpdated(rec);
}
}
virtual void Get(StrView strKeyText, seed::FnPodOp fnCallback) override {
void Get(StrView strKeyText, seed::FnPodOp fnCallback) override {
{
PolicyMaps::Locker maps{static_cast<PolicyTree*>(&this->Tree_)->PolicyMaps_};
auto ifind = this->GetIteratorForPod(maps->ItemMap_, strKeyText);
Expand All @@ -91,7 91,7 @@ struct PolicyTree::TreeOp : public seed::TreeOp {
} // unlock.
fnCallback(seed::PodOpResult{this->Tree_, seed::OpResult::not_found_key, strKeyText}, nullptr);
}
virtual void Add(StrView strKeyText, seed::FnPodOp fnCallback) override {
void Add(StrView strKeyText, seed::FnPodOp fnCallback) override {
if (this->IsTextBegin(strKeyText) || this->IsTextEnd(strKeyText)) {
fnCallback(seed::PodOpResult{this->Tree_, seed::OpResult::not_found_key, strKeyText}, nullptr);
return;
Expand All @@ -106,7 106,7 @@ struct PolicyTree::TreeOp : public seed::TreeOp {
}
this->OnPodOp(maps, **ifind, std::move(fnCallback), isForceWrite);
}
virtual void Remove(StrView strKeyText, seed::Tab* tab, seed::FnPodRemoved fnCallback) override {
void Remove(StrView strKeyText, seed::Tab* tab, seed::FnPodRemoved fnCallback) override {
seed::PodRemoveResult res{this->Tree_, seed::OpResult::not_found_key, strKeyText, tab};
if (static_cast<PolicyTree*>(&this->Tree_)->Delete(strKeyText))
res.OpResult_ = seed::OpResult::removed_pod;
Expand Down
Loading

0 comments on commit 3b2f825

Please sign in to comment.