156 lines
2.2 KiB
C++
Executable File
156 lines
2.2 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "plugindata.h"
|
|
#include "plugin.h"
|
|
#include "log.h"
|
|
#include "session.h"
|
|
|
|
|
|
|
|
|
|
PluginData::PluginData()
|
|
{
|
|
session = 0;
|
|
}
|
|
|
|
|
|
|
|
PluginData::PluginData(const PluginData & p)
|
|
{
|
|
operator=(p);
|
|
}
|
|
|
|
|
|
|
|
PluginData & PluginData::operator=(const PluginData & p)
|
|
{
|
|
// we don't copy all pointers - only resize the table
|
|
// pointers will be set to zero
|
|
Resize(p.Size());
|
|
session = 0;
|
|
|
|
return *this;
|
|
}
|
|
|
|
|
|
|
|
PluginData::~PluginData()
|
|
{
|
|
DeleteAll();
|
|
}
|
|
|
|
|
|
void PluginData::SetSession(Session * ses)
|
|
{
|
|
session = ses;
|
|
}
|
|
|
|
|
|
|
|
void PluginData::Assign(size_t index, PluginDataBase * data)
|
|
{
|
|
if( index >= table.size() )
|
|
Resize(index+1);
|
|
|
|
table[index] = data;
|
|
}
|
|
|
|
|
|
void PluginData::Assign(PluginDataBase * data)
|
|
{
|
|
if( plugin.current_plugin == -1 )
|
|
{
|
|
log << log1 << "PD: Assign(PluginDataBase*) should be called only from plugins" << logend;
|
|
return;
|
|
}
|
|
|
|
Assign(plugin.current_plugin, data);
|
|
}
|
|
|
|
|
|
|
|
PluginDataBase * PluginData::Get(size_t index)
|
|
{
|
|
if( index >= table.size() )
|
|
Resize(index+1);
|
|
|
|
return table[index];
|
|
}
|
|
|
|
|
|
PluginDataBase * PluginData::Get()
|
|
{
|
|
if( plugin.current_plugin == -1 )
|
|
{
|
|
log << log1 << "PD: Get() should be called only from plugins" << logend;
|
|
return 0;
|
|
}
|
|
|
|
return Get(plugin.current_plugin);
|
|
}
|
|
|
|
|
|
|
|
|
|
void PluginData::DeleteAll()
|
|
{
|
|
bool all_null = true;
|
|
|
|
/*
|
|
when we copy a session's object (and this object then)
|
|
we resize the table and there are only null pointers there
|
|
consequently if all pointers are null there is no sens
|
|
to send WINIX_PLUGIN_SESSION_DATA_REMOVE
|
|
*/
|
|
|
|
for(size_t i=0 ; i<table.size() ; ++i)
|
|
{
|
|
if( table[i] != 0 )
|
|
{
|
|
all_null = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*
|
|
in the future this message may be removed
|
|
and we directly 'delete' the pointers
|
|
*/
|
|
|
|
if( !all_null )
|
|
plugin.Call(session, WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
|
|
|
table.clear();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t PluginData::Size() const
|
|
{
|
|
return table.size();
|
|
}
|
|
|
|
|
|
|
|
void PluginData::Resize(size_t new_size)
|
|
{
|
|
size_t old_size = table.size();
|
|
|
|
if( old_size == new_size )
|
|
return;
|
|
|
|
table.resize(new_size);
|
|
|
|
for(size_t i = old_size ; i<new_size ; ++i)
|
|
table[i] = 0;
|
|
}
|