Commit 85e3a72c authored by Vincent Carrubba's avatar Vincent Carrubba

Intermediate commit just for save

parent 646bd6a0
......@@ -25,3 +25,5 @@
-rajouter un getter pour savoir un out/inslot est connecte
-rajouter un getter pour recuper l'InSlot/OutSlot auquel l'OutSlot/InSlot est connecte
-rajoute la deconnection a la destruction
-rajouter le using dans le template pour forcer le type sur lequel on template a posseder
la methode get default value
// #include "EffectsEngine.h"
// #include "GenericEffect.h"
// #include "PouetEffect.h"
/*****************************************************************************
* OutSlot.hpp: OutSlot is for outing data to an InSlot for inter-effects
* communication
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Vincent Carrubba <cyberbouba@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef OUTSLOT_HPP_
#define OUTSLOT_HPP_
struct Pixel
#include "InSlot.hpp"
#include <QtDebug>
template<typename T>
class OutSlot
{
enum
{
NbComposantes = 3
};
quint8 Red;
quint8 Green;
quint8 Blue;
friend class InSlot<T>;
public:
// CTOR & DTOR
OutSlot();
OutSlot(OutSlot const &);
OutSlot& operator=(OutSlot const &);
~OutSlot();
// STREAMING
OutSlot& operator<<( T const & );
OutSlot& operator=( T const & );
// CONNECTION & DISCONNECTION
bool connect( InSlot<T>& );
bool disconnect( void );
void setType( typename InSlot<T>::OUTTYPE type );
private:
// OTHERS
typename InSlot<T>::OUTTYPE getType( void ) const;
void setPipe( T* shared );
void resetPipe( void );
void setInSlotPtr( InSlot<T>* );
void resetInSlotPtr( void );
private:
typename InSlot<T>::OUTTYPE m_type;
InSlot<T>* m_connectedTo;
T m_junk;
T* m_pipe;
};
union RawVideoFrame
/////////////////////////
//// PUBLICS METHODS ////
/////////////////////////
// CTOR & DTOR
template<typename T>
OutSlot<T>::OutSlot() : m_type( InSlot<T>::NORMAL ), m_connectedTo( NULL ), m_pipe( &m_junk )
{
Pixel* pixels;
quint8* octets;
};
}
struct VideoFrame : public QSharedData
template<typename T>
OutSlot<T>::OutSlot(OutSlot<T> const & tocopy) : m_type( tocopy.m_type ),
m_connectedTo( NULL ),
m_pipe( &m_junk )
{
~VideoFrame()
{
if ( this->frame.octets != NULL )
delete [] frame.octets;
};
}
VideoFrame()
{
this->frame.octets = NULL;
this->nboctets = 0;
this->nbpixels = 0;
}
template<typename T>
OutSlot<T>& OutSlot<T>::operator=(OutSlot<T> const & tocopy)
{
m_type = tocopy.m_type;
m_connectedTo = NULL;
m_pipe = &m_junk;
}
VideoFrame(VideoFrame const & tocopy) : QSharedData( tocopy )
{
if ( tocopy.frame.octets != NULL )
{
quint32 i;
nboctets = tocopy.nboctets;
nbpixels = tocopy.nboctets / Pixel::NbComposantes;
frame.octets = new quint8[tocopy.nboctets];
for ( i = 0; i < nboctets; ++i )
frame.octets[i] = tocopy.frame.octets[i];
}
else
template<typename T>
OutSlot<T>::~OutSlot()
{
}
// WRITING METHODS
template<typename T>
OutSlot<T>& OutSlot<T>::operator=( T const & val )
{
(*m_pipe) = val;
return ( *this );
}
template<typename T>
OutSlot<T>& OutSlot<T>::operator<<( T const & val )
{
(*m_pipe) = val;
return (*this);
}
// CONNECTION METHODS
template<typename T>
bool OutSlot<T>::connect( InSlot<T>& toconnect )
{
if ( m_connectedTo != NULL )
return ( false );
if ( toconnect.connect( (*this) ) == false)
{
nboctets = 0;
nbpixels = 0;
frame.octets = NULL;
return ( false );
}
}
return ( true );
}
RawVideoFrame frame;
quint32 nbpixels;
quint32 nboctets;
};
template<typename T>
bool OutSlot<T>::disconnect( void )
{
if ( m_connectedTo == NULL)
return ( false );
if ( m_connectedTo->disconnect( (*this) ) == false)
return ( false );
return ( true );
}
template<typename T>
void OutSlot<T>::setType( typename InSlot<T>::OUTTYPE type )
{
m_type = type;
return ;
}
//////////////////////////
//// PRIVATES METHODS ////
//////////////////////////
// OTHERS
template<typename T>
typename InSlot<T>::OUTTYPE OutSlot<T>::getType( void ) const
{
return ( m_type );
}
template<typename T>
void OutSlot<T>::setPipe( T* shared )
{
m_pipe = shared;
return ;
}
template<typename T>
void OutSlot<T>::resetPipe( void )
{
m_pipe = &m_junk;
return ;
}
template<typename T>
void OutSlot<T>::setInSlotPtr( InSlot<T>* ptr )
{
m_connectedTo = ptr;
return ;
}
class LightVideoFrame
template<typename T>
void OutSlot<T>::resetInSlotPtr( void )
{
m_connectedTo = NULL;
return ;
}
#endif // OUTSLOT_HPP_
/*****************************************************************************
* InSlot.hpp: InSlot is for getting entering data from OutSlot for
* inter-effects communication
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Vincent Carrubba <cyberbouba@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef INSLOT_HPP_
#define INSLOT_HPP_
#include <cstdlib>
template<typename T> class OutSlot;
template<typename T>
class InSlot
{
friend class OutSlot<T>;
public:
LightVideoFrame()
{
m_videoFrame = new VideoFrame;
};
// CTOR & DTOR
LightVideoFrame(LightVideoFrame const & tocopy) : m_videoFrame(tocopy.m_videoFrame)
{
};
InSlot();
InSlot(InSlot const & tocopy);
InSlot& operator=(InSlot const & tocopy);
~InSlot();
// STREAMING
InSlot<T>& operator>>( T & );
operator T const & () const;
// GETTING INFOS
LightVideoFrame& operator=(LightVideoFrame const & tocopy)
{
if ( m_videoFrame->frame.octets == NULL )
{
if ( tocopy.m_videoFrame->frame.octets != NULL )
{
m_videoFrame->frame.octets = new quint8[tocopy.m_videoFrame->nboctets];
m_videoFrame->nboctets = tocopy.m_videoFrame->nboctets;
m_videoFrame->nbpixels = tocopy.m_videoFrame->nboctets / Pixel::NbComposantes;
quint32 i;
for ( i = 0; i < m_videoFrame->nboctets; ++i )
m_videoFrame->frame.octets[i] = tocopy.m_videoFrame->frame.octets[i];
}
}
else
{
if ( tocopy.m_videoFrame->frame.octets != NULL )
{
if ( m_videoFrame->nboctets != tocopy.m_videoFrame->nboctets )
{
qDebug() << __LINE__ << "\n"
<< "this pixels = " << m_videoFrame->nbpixels
<< "tocopy.m_videoFrame pixels = " << tocopy.m_videoFrame->nbpixels;
delete [] m_videoFrame->frame.octets;
m_videoFrame->frame.octets = new quint8[tocopy.m_videoFrame->nboctets];
m_videoFrame->nboctets = tocopy.m_videoFrame->nboctets;
m_videoFrame->nbpixels = tocopy.m_videoFrame->nboctets / Pixel::NbComposantes;
}
quint32 i;
for ( i = 0; i < m_videoFrame->nboctets; ++i )
m_videoFrame->frame.octets[i] = tocopy.m_videoFrame->frame.octets[i];
}
else
{
delete [] m_videoFrame->frame.octets;
m_videoFrame->frame.octets = NULL;
m_videoFrame->nboctets = 0;
m_videoFrame->nbpixels = 0;
}
}
return ( *this );
};
LightVideoFrame(quint32 nboctets)
{
m_videoFrame = new VideoFrame;
m_videoFrame->nboctets = nboctets;
m_videoFrame->nbpixels = nboctets / Pixel::NbComposantes;
m_videoFrame->frame.octets = new quint8[nboctets];
};
LightVideoFrame(quint8 const * tocopy, quint32 nboctets)
{
quint32 i;
m_videoFrame = new VideoFrame;
m_videoFrame->nboctets = nboctets;
m_videoFrame->nbpixels = nboctets / Pixel::NbComposantes;
m_videoFrame->frame.octets = new quint8[nboctets];
for ( i = 0; i < m_videoFrame->nboctets; ++i )
m_videoFrame->frame.octets[i] = tocopy[i];
};
~LightVideoFrame()
{
};
VideoFrame const * operator->(void) const
{
return ( m_videoFrame.data() );
};
VideoFrame const & operator*(void) const
{
return ( *m_videoFrame );
};
VideoFrame* operator->(void)
{
return ( m_videoFrame.data() );
};
VideoFrame& operator*(void)
{
return ( *m_videoFrame );
};
private:
QSharedDataPointer<VideoFrame> m_videoFrame;
// CONNECTION & DISCONNECTION
bool connect( OutSlot<T>& );
bool disconnect( OutSlot<T>& );
private:
static T m_defaultValue;
T m_shared;
T* m_currentShared;
};
int main(void)
/////////////////////////
//// PUBLICS METHODS ////
/////////////////////////
// CTOR & DTOR
template<typename T>
InSlot<T>::InSlot() : m_currentShared( &m_defaultValue )
{
}
template<typename T>
InSlot<T>::~InSlot()
{
}
// READING METHODS
template<typename T>
InSlot<T>& InSlot<T>::operator>>( T& val )
{
val = m_shared[m_currentShared];
return ( (*this) );
}
template<typename T>
InSlot<T>::operator T const & () const
{
return ( m_shared[m_currentShared] );
}
//////////////////////////
//// PRIVATES METHODS ////
//////////////////////////
// CONNECTION METHODS
// An OutSlot can be connected only if :
// -The number of OutSlot of the same type isn't at the maximum
// -The OutSlot isn't already connected --> verified in the method void OutSlot<T>::connect( InSlot<T>& T )
// So, the OutSlot can be connected and the m_currentShared must be updated
template<typename T>
bool InSlot<T>::connect( OutSlot<T>& toconnect )
{
OUTTYPE type;
type = toconnect.getType();
if ( m_outNbLimits[type] != InSlot<T>::INFINITE)
if ( m_nbOutByType[type] >= m_outNbLimits[type] )
return ( false );
++(m_nbOutByType[type]);
toconnect.setPipe( &m_shared[type] );
toconnect.setInSlotPtr( this );
switchCurrentShared();
return ( true );
}
// An OutSlot can be disconnected only if :
// -The OutSlot is connected on this InSlot --> this is implicit because this method is call only by
// bool OutSlot<T>::disconnect( ), and this method call the first method with the InSlot<T> pointer saved at connection
// So, the OutSlot can be connected and the m_currentShared must be updated
template<typename T>
bool InSlot<T>::disconnect( OutSlot<T>& todisconnect )
{
LightVideoFrame vf((const quint8*)("JAIMELESPONEYS"), 15);
OUTTYPE type;
type = todisconnect.getType();
--(m_nbOutByType[type]);
std::cout << (const char*)vf->frame.octets << '\n'
<< vf->nbpixels << std::endl;
todisconnect.resetPipe();
todisconnect.resetInSlotPtr();
switchCurrentShared();
return ( true );
}
template<typename T>
void InSlot<T>::switchCurrentShared( void )
{
unsigned int priority;
for ( priority = InSlot<T>::HIGHER; priority > InSlot<T>::LOWER; --priority )
{
if ( m_nbOutByType[priority] )
break;
}
m_currentShared = static_cast< typename InSlot<T>::OUTTYPE >( priority );
m_shared[m_currentShared] = m_shared[DEFAULT];
return ;
}
#endif // INSLOT_HPP_
int main(void)
{
return (0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment