Skip to content

Commit

Permalink
插件接口调整;修正一处崩溃的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Sep 4, 2021
1 parent 509818e commit 9f00e95
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions PluginDemo/PluginDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const wchar_t* CPluginDemo::GetInfo(PluginInfoIndex index)
return L"";
}

ITMPlugin::OptionReturn CPluginDemo::ShowOptionsDialog(HWND hParent)
ITMPlugin::OptionReturn CPluginDemo::ShowOptionsDialog(void* hParent)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
COptionsDlg dlg(CWnd::FromHandle(hParent));
COptionsDlg dlg(CWnd::FromHandle((HWND)hParent));
dlg.m_data = CDataManager::Instance().m_setting_data;
if (dlg.DoModal() == IDOK)
{
Expand Down
2 changes: 1 addition & 1 deletion PluginDemo/PluginDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CPluginDemo : public ITMPlugin
virtual IPluginItem* GetItem(int index) override;
virtual void DataRequired() override;
virtual const wchar_t* GetInfo(PluginInfoIndex index) override;
virtual OptionReturn ShowOptionsDialog(HWND hParent) override;
virtual OptionReturn ShowOptionsDialog(void* hParent) override;

private:
CPluginSystemDate m_system_date;
Expand Down
10 changes: 5 additions & 5 deletions TrafficMonitor/PluginInfoDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ void CPluginInfoDlg::ShowInfo()
if (m_cur_index >= 0 && m_cur_index < static_cast<int>(theApp.m_plugins.GetPlugins().size()))
{
auto& plugin_info = theApp.m_plugins.GetPlugins()[m_cur_index];
m_info_list.SetItemText(RI_NAME, 1, plugin_info.properties.at(ITMPlugin::TMI_NAME).c_str());
m_info_list.SetItemText(RI_DESCRIPTION, 1, plugin_info.properties.at(ITMPlugin::TMI_DESCRIPTION).c_str());
m_info_list.SetItemText(RI_NAME, 1, plugin_info.Property(ITMPlugin::TMI_NAME).c_str());
m_info_list.SetItemText(RI_DESCRIPTION, 1, plugin_info.Property(ITMPlugin::TMI_DESCRIPTION).c_str());
m_info_list.SetItemText(RI_FILE_NAME, 1, CFilePathHelper(plugin_info.file_path).GetFileName().c_str());
m_info_list.SetItemText(RI_FILE_PATH, 1, plugin_info.file_path.c_str());
m_info_list.SetItemText(RI_ITEM_NUM, 1, std::to_wstring(plugin_info.plugin_items.size()).c_str());
Expand All @@ -54,9 +54,9 @@ void CPluginInfoDlg::ShowInfo()
}
m_info_list.SetItemText(RI_ITEM_NAMES, 1, item_names.c_str());
m_info_list.SetItemText(RI_ITEM_ID, 1, item_id.c_str());
m_info_list.SetItemText(RI_AUTHOR, 1, plugin_info.properties.at(ITMPlugin::TMI_AUTHOR).c_str());
m_info_list.SetItemText(RI_COPYRIGHT, 1, plugin_info.properties.at(ITMPlugin::TMI_COPYRIGHT).c_str());
m_info_list.SetItemText(RI_VERSION, 1, plugin_info.properties.at(ITMPlugin::TMI_VERSION).c_str());
m_info_list.SetItemText(RI_AUTHOR, 1, plugin_info.Property(ITMPlugin::TMI_AUTHOR).c_str());
m_info_list.SetItemText(RI_COPYRIGHT, 1, plugin_info.Property(ITMPlugin::TMI_COPYRIGHT).c_str());
m_info_list.SetItemText(RI_VERSION, 1, plugin_info.Property(ITMPlugin::TMI_VERSION).c_str());
if (plugin_info.plugin != nullptr)
m_info_list.SetItemText(RI_API_VERSION, 1, std::to_wstring(plugin_info.plugin->GetAPIVersion()).c_str());
}
Expand Down
8 changes: 8 additions & 0 deletions TrafficMonitor/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,11 @@ int CPluginManager::GetItemIndex(IPluginItem* item) const
}
return -1;
}

std::wstring CPluginManager::PluginInfo::Property(ITMPlugin::PluginInfoIndex index) const
{
auto iter = properties.find(index);
if (iter != properties.end())
return iter->second;
return wstring();
}
1 change: 1 addition & 0 deletions TrafficMonitor/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CPluginManager
PluginState state{}; //插件的状态
DWORD error_code{}; //错误代码(GetLastError的返回值)
std::map<ITMPlugin::PluginInfoIndex, std::wstring> properties; //插件属性
std::wstring Property(ITMPlugin::PluginInfoIndex) const;
};

CPluginManager();
Expand Down
2 changes: 1 addition & 1 deletion TrafficMonitor/PluginManagerDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ BOOL CPluginManagerDlg::OnInitDialog()
}
int index = m_list_ctrl.GetItemCount();
m_list_ctrl.InsertItem(index, file_name.c_str());
m_list_ctrl.SetItemText(index, 1, plugin.properties.at(ITMPlugin::TMI_NAME).c_str());
m_list_ctrl.SetItemText(index, 1, plugin.Property(ITMPlugin::TMI_NAME).c_str());
m_list_ctrl.SetItemText(index, 2, status);
}

Expand Down
2 changes: 1 addition & 1 deletion include/PluginInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ITMPlugin
* 此函数不一定要重写。如果插件提供了选项设置界面,则应该重写此函数,并在最后返回OR_OPTION_CHANGED或OR_OPTION_UNCHANGED。
* 返回值为OR_OPTION_NOT_PRVIDED则认为插件不提供选项设置对话框。
*/
virtual OptionReturn ShowOptionsDialog(HWND hParent) { return OR_OPTION_NOT_PROVIDED; };
virtual OptionReturn ShowOptionsDialog(void* hParent) { return OR_OPTION_NOT_PROVIDED; };

//插件信息的索引
enum PluginInfoIndex
Expand Down

0 comments on commit 9f00e95

Please sign in to comment.