196 lines
4.1 KiB
C++
Executable File
196 lines
4.1 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "tdb.h"
|
|
#include "reply.h"
|
|
#include "funthread.h"
|
|
#include "createthread.h"
|
|
#include "showthreads.h"
|
|
#include "core/log.h"
|
|
#include "core/plugin.h"
|
|
#include "pluginmsg.h"
|
|
#include "templates.h"
|
|
|
|
|
|
|
|
extern "C" void Init(PluginInfo &);
|
|
|
|
|
|
|
|
|
|
namespace Thread
|
|
{
|
|
const wchar_t plugin_name[] = L"thread";
|
|
|
|
TDb tdb;
|
|
ThreadInfo thread_info;
|
|
|
|
Reply fun_reply;
|
|
FunThread fun_thread;
|
|
CreateThread fun_create_thread;
|
|
ShowThreads fun_show_threads;
|
|
|
|
|
|
|
|
void AddFunctions(PluginInfo & info)
|
|
{
|
|
info.functions->Add(fun_reply);
|
|
info.functions->Add(fun_thread);
|
|
info.functions->Add(fun_create_thread);
|
|
info.functions->Add(fun_show_threads);
|
|
}
|
|
|
|
|
|
void SelectDefaultFunction(PluginInfo & info)
|
|
{
|
|
if( info.system->mounts.pmount->type == thread_info.mount_type_thread )
|
|
{
|
|
if( info.cur->request->is_item )
|
|
info.cur->request->function = &fun_thread;
|
|
else
|
|
info.cur->request->function = &fun_show_threads;
|
|
}
|
|
}
|
|
|
|
|
|
void AddMounts(PluginInfo & info)
|
|
{
|
|
Mounts & m = info.system->mounts;
|
|
|
|
thread_info.mount_type_thread = m.AddMountType(L"thread");
|
|
thread_info.mount_par_thread = m.AddMountPar(L"thread");
|
|
thread_info.mount_par_thread_dir = m.AddMountPar(L"thread_dir");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RemoveThread(PluginInfo & i)
|
|
{
|
|
thread_info.RemoveThread(i.l1);
|
|
thread_info.RemoveThreadAnswer(i.l1);
|
|
}
|
|
|
|
|
|
|
|
|
|
void AddNotifyTemplate(PluginInfo & info)
|
|
{
|
|
thread_info.template_index = info.system->notify.AddTemplate(L"notify_email_thread.txt");
|
|
}
|
|
|
|
|
|
void SetSortTab(PluginInfo & info)
|
|
{
|
|
if( !info.p1 )
|
|
{
|
|
log << log1 << "Thread: sort_tab pointer is not set" << logend;
|
|
return;
|
|
}
|
|
|
|
typedef std::vector<Item*> SortTab;
|
|
SortTab * psort_tab = reinterpret_cast<SortTab*>(info.p1);
|
|
|
|
// !! dodac jakies czyszczenie tej tablicy wskaznikow na koncu przetwarzania requestu
|
|
// aby kiedys przypadkowo nie odwolac sie do nie istniejacego obiektu
|
|
// poprzez bezposrednie uzycie jakiejs funkcji z ezc
|
|
thread_info.item_sort_tab = *psort_tab;
|
|
}
|
|
|
|
|
|
void ReadThreads(PluginInfo & info)
|
|
{
|
|
fun_show_threads.ReadThreads();
|
|
}
|
|
|
|
|
|
void SetSortTabIndex(PluginInfo & info)
|
|
{
|
|
thread_sort_tab(info.l1);
|
|
}
|
|
|
|
|
|
void PrepareThread(PluginInfo & info)
|
|
{
|
|
fun_thread.PrepareThread(info.l1);
|
|
}
|
|
|
|
|
|
void EndRequest(PluginInfo & info)
|
|
{
|
|
thread_info.Clear();
|
|
}
|
|
|
|
|
|
// !! temporarily
|
|
void Rescan(PluginInfo & info)
|
|
{
|
|
if( info.config->Bool(L"thread_rescan", false) == true )
|
|
{
|
|
log << log1 << "---------- rescanning thread db ------------- " << logend;
|
|
thread_info.Repair();
|
|
log << log1 << "---------- thread db rescanning is finished ------------- " << logend;
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
void Init(PluginInfo & info)
|
|
{
|
|
using namespace Thread;
|
|
|
|
plugin.Assign(WINIX_CREATE_FUNCTIONS, AddFunctions);
|
|
plugin.Assign(WINIX_SELECT_DEFAULT_FUNCTION, SelectDefaultFunction);
|
|
plugin.Assign(WINIX_ADD_MOUNTS, AddMounts);
|
|
plugin.Assign(WINIX_FILE_REMOVED, RemoveThread);
|
|
plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate);
|
|
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
|
|
plugin.Assign(WINIX_END_REQUEST, EndRequest);
|
|
|
|
// for other plugins
|
|
plugin.Assign(WINIX_PL_THREAD_SET_SORTTAB, SetSortTab);
|
|
plugin.Assign(WINIX_PL_THREAD_READ_THREADS, ReadThreads);
|
|
plugin.Assign(WINIX_PL_THREAD_SET_SORTTAB_INDEX, SetSortTabIndex);
|
|
plugin.Assign(WINIX_PL_THREAD_PREPARE_THREAD, PrepareThread);
|
|
|
|
// temporarily
|
|
plugin.Assign(WINIX_PLUGIN_INIT, Rescan);
|
|
|
|
tdb.SetConn(info.db->GetConn());
|
|
tdb.LogQueries(info.config->log_db_query);
|
|
|
|
// thread_info and fun_show_threads are used in 'ticket' plugins too
|
|
thread_info.SetDb(info.db);
|
|
thread_info.SetTDb(&tdb);
|
|
thread_info.SetSystem(info.system);
|
|
thread_info.plugin_id = info.plugin_id;
|
|
|
|
fun_reply.SetTDb(&tdb);
|
|
fun_reply.SetThreadInfo(&thread_info);
|
|
|
|
fun_thread.SetTDb(&tdb);
|
|
fun_thread.SetThreadInfo(&thread_info);
|
|
|
|
fun_create_thread.SetTDb(&tdb);
|
|
fun_create_thread.SetThreadInfo(&thread_info);
|
|
|
|
fun_show_threads.SetTDb(&tdb);
|
|
fun_show_threads.SetThreadInfo(&thread_info);
|
|
|
|
info.p1 = (void*)(plugin_name);
|
|
}
|
|
|
|
|