Example #1
0
void db_multi_key_data::clear() {
    int rc = 0;
    char* szErrMsg = 0;
    {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if (need_mutex_) local_lock_.lock();
        rc = sqlite3_exec(
                 db_,
                 "DROP TABLE IF EXISTS data_header",
                 NULL,
                 0,
                 &szErrMsg);
        if (rc != SQLITE_OK) {
            std::stringstream ss("");
            ss << "SQL error in DROP table : ";
            ss << szErrMsg;
            sqlite3_free(szErrMsg);
            local_lock_.unlock();
            throw std::runtime_error(ss.str());
        }
    }
    {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if (need_mutex_) local_lock_.lock();
        rc = sqlite3_exec(
                 db_,
                 "DROP TABLE IF EXISTS data_time",
                 NULL,
                 0,
                 &szErrMsg);
        if (rc != SQLITE_OK) {
            std::stringstream ss("");
            ss << "SQL error in DROP table : ";
            ss << szErrMsg;
            sqlite3_free(szErrMsg);
            local_lock_.unlock();
            throw std::runtime_error(ss.str());
        }
    }
    {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if (need_mutex_) local_lock_.lock();
        rc = sqlite3_exec(
                 db_,
                 "DROP TABLE IF EXISTS data_item",
                 NULL,
                 0,
                 &szErrMsg);
        if (rc != SQLITE_OK) {
            std::stringstream ss("");
            ss << "SQL error in DROP table : ";
            ss << szErrMsg;
            sqlite3_free(szErrMsg);
            local_lock_.unlock();
            throw std::runtime_error(ss.str());
        }
    }
    create_table();
}
Example #2
0
int try_lock(BW *bw,B *b)
{
	/* First time we modify the file */
	/* If we're a plain file, acquire lock */
	if (!nolocks && plain_file(b)) {
		unsigned char bf1[256];
		unsigned char bf[300];
		int x;
		/* It's a plain file- try to lock it */
		if (lock_it(b->name,bf1)) {
			for(x=0;bf1[x] && bf1[x]!=':';++x);
			bf1[x]=0;
			if(bf1[0])
				joe_snprintf_1(bf,sizeof(bf),joe_gettext(LOCKMSG1),bf1);
			else
				joe_snprintf_0(bf, sizeof(bf), joe_gettext(LOCKMSG2));
			if (mkqw(bw->parent, sz(bf), steal_lock, NULL, b, NULL)) {
				uquery(bw);
				if (!b->locked)
					return 0;
			} else
				return 0;
		} else {
			/* Remember to unlock it */
			b->locked = 1;
		}
	}
	return 1;
}
Example #3
0
//
// NonDelegatingQueryInterface
//
// This function is overwritten to expose IMediaPosition and IMediaSelection
// Note that only one output stream can be allowed to expose this to avoid
// conflicts, the other pins will just return E_NOINTERFACE and therefore
// appear as non seekable streams. We have a LONG value that if exchanged to
// produce a TRUE means that we have the honor. If it exchanges to FALSE then
// someone is already in. If we do get it and error occurs then we reset it
// to TRUE so someone else can get it.
//
STDMETHODIMP
CTeeOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
    CheckPointer(ppv,E_POINTER);
    ASSERT(ppv);

    *ppv = NULL;
    HRESULT hr = NOERROR;

    // See what interface the caller is interested in.
    if(riid == IID_IMediaPosition || riid == IID_IMediaSeeking)
    {
        if(m_pPosition)
        {
            if(m_bHoldsSeek == FALSE)
                return E_NOINTERFACE;
            return m_pPosition->QueryInterface(riid, ppv);
        }
    }
    else
    {
        return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv);
    }

    CAutoLock lock_it(m_pLock);
    ASSERT(m_pPosition == NULL);
    IUnknown *pMediaPosition = NULL;

    // Try to create a seeking implementation
    if(InterlockedExchange(&m_pTee->m_lCanSeek, FALSE) == FALSE)
        return E_NOINTERFACE;

    // Create implementation of this dynamically as sometimes we may never
    // try and seek. The helper object implements IMediaPosition and also
    // the IMediaSelection control interface and simply takes the calls
    // normally from the downstream filter and passes them upstream

    hr = CreatePosPassThru(GetOwner(),
                           FALSE,
                           (IPin *)&m_pTee->m_Input,
                           &pMediaPosition);

    if(pMediaPosition == NULL)
    {
        InterlockedExchange(&m_pTee->m_lCanSeek, TRUE);
        return E_OUTOFMEMORY;
    }

    if(FAILED(hr))
    {
        InterlockedExchange(&m_pTee->m_lCanSeek, TRUE);
        pMediaPosition->Release();
        return hr;
    }

    m_pPosition = pMediaPosition;
    m_bHoldsSeek = TRUE;
    return NonDelegatingQueryInterface(riid, ppv);

} // NonDelegatingQueryInterface
Example #4
0
void db_key_value::list(std::map<std::string, std::string>& mm) {
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    int rc = 0;
    char** result;
    int nrow, ncol;
    char* szMsg;
    rc = sqlite3_get_table(
             db_,
             "SELECT * FROM contacts",
             &result,
             &nrow,
             &ncol,
             &szMsg);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT * : ";
        ss << szMsg;
        sqlite3_free(szMsg);
        sqlite3_free_table(result);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    if (ncol != 2) return;
    for (int i = 2; i < (ncol * (nrow + 1)); i+= 2) {
        mm.insert(
            std::make_pair<std::string, std::string>(
                result[i],
                result[i + 1]));
    }
    sqlite3_free_table(result);
}
Example #5
0
size_t db_multi_key_data::size() {
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    int rc = 0;
    char** result;
    int nrow, ncol;
    char* szMsg;
    rc = sqlite3_get_table(
             db_,
             "SELECT Count(*) FROM data_header",
             &result,
             &nrow,
             &ncol,
             &szMsg);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT Count(*) : ";
        ss << szMsg;
        sqlite3_free(szMsg);
        sqlite3_free_table(result);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    if (ncol != 1) return 0;
    if (nrow != 1) return 0;
    return (size_t)atoi(result[1]);
}
Example #6
0
void db_key_value::insert(
    const std::string& key,
    const std::string& value)
{
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    std::stringstream ss("");
    ss << "INSERT INTO contacts VALUES('";
    ss << key << "', '";
    ss << value << "')";
    int rc = 0;
    char* szMsg;
    rc = sqlite3_exec(
             db_,
             ss.str().c_str(),
             NULL,
             0,
             &szMsg);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in INSERT table : ";
        ss << szMsg;
        sqlite3_free(szMsg);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
}
Example #7
0
void db_multi_key_data::remove(
    const std::string& key,
    const std::string& title)
{
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if(need_mutex_) local_lock_.lock();
    int rc = 0;
    char* szMsg;
    {   // data header search and clean
        std::stringstream ss("");
        ss << "DELETE FROM data_header WHERE key = '";
        ss << key << "' AND title = '";
        ss << title << "'";
        rc = sqlite3_exec(
                 db_,
                 ss.str().c_str(),
                 NULL,
                 0,
                 &szMsg);
    }
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in DELETE : ";
        ss << szMsg;
        sqlite3_free(szMsg);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
}
Example #8
0
std::string db_key_value::find(const std::string& key) {
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    std::stringstream ss("");
    ss << "SELECT value FROM contacts WHERE key = '";
    ss << key << "'";
    int rc = 0;
    char** result;
    int nrow, ncol;
    char* szMsg;
    rc = sqlite3_get_table(
             db_,
             ss.str().c_str(),
             &result,
             &nrow,
             &ncol,
             &szMsg);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT value : ";
        ss << szMsg;
        sqlite3_free(szMsg);
        sqlite3_free_table(result);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    std::string ret = "";
    if (ncol != 1) return ret;
    if (nrow == 1) ret = result[1];
    sqlite3_free_table(result);
    return ret;
}
Example #9
0
void CloseGMapDemuxFilters_Lock(map<HANDLE,RegIDPID>& map_hFilter_ReqIDPID, MutexT & mutex)
{
	map<HANDLE,RegIDPID> tmp;
	map<HANDLE,RegIDPID>::iterator it;

	//关闭已有的filters 列表
	{
		AutoLockT lock_it(mutex);
		tmp = map_hFilter_ReqIDPID;
		for(it=map_hFilter_ReqIDPID.begin(); it!=map_hFilter_ReqIDPID.end();it++)
		{
			if(it->second.wPid !=0x10)
			{
//				tsdemux_delSectionFilter(it->first,NULL);
				map_hFilter_ReqIDPID.erase(it);
			}
		}
	}
	for(it=tmp.begin(); it!=tmp.end();it++)
	{
		if(it->second.wPid !=0x10)
		{
			tsdemux_delSectionFilter(it->first,NULL);
		}
	}
//	map_hFilter_ReqIDPID.clear();
}
Example #10
0
void async_task_queue_submit(async_task_queue_t *task_queue, void(*callback)(void *userdata), void* userdata)
{
    struct async_task *task;

    if (NULL == task_queue || NULL == callback)
    {
        log_error("async_task_queue_submit: bad task_queue(%p) or bad callback(%p)", task_queue, callback);
        return;
    }

    task = (struct async_task*)malloc(sizeof(*task));
    memset(task, 0, sizeof(*task));

    task->callback = callback;
    task->userdata = userdata;
    task->next = NULL;

    lock_it(&task_queue->task_lock);
    if (NULL == task_queue->async_task)
    {
        task_queue->async_task = task;
        task_queue->async_task_end = task;
    }
    else
    {
        task_queue->async_task_end->next = task;
        task_queue->async_task_end = task;
    }
    unlock_it(&task_queue->task_lock);

    send(task_queue->fds[1], (const char*)&task, sizeof(task), 0);

    return;
}
Example #11
0
HRESULT CTeeInputPin::NewSegment(REFERENCE_TIME tStart,
                                 REFERENCE_TIME tStop,
                                 double dRate)
{
    CAutoLock lock_it(m_pLock);
    ASSERT(m_pTee->m_NumOutputPins);
    HRESULT hr = NOERROR;

    // Walk through the output pins list, sending the message downstream

    int n = m_pTee->m_NumOutputPins;
    POSITION pos = m_pTee->m_OutputPinsList.GetHeadPosition();

    while(n)
    {
        CTeeOutputPin *pOutputPin = m_pTee->m_OutputPinsList.GetNext(pos);
        if(pOutputPin != NULL)
        {
            hr = pOutputPin->DeliverNewSegment(tStart, tStop, dRate);
            if(FAILED(hr))
                return hr;
        }
        else
        {
            // We should have as many pins as the count says we have
            ASSERT(FALSE);
        }
        n--;
    }

    return CBaseInputPin::NewSegment(tStart, tStop, dRate);

} // NewSegment
Example #12
0
//
// EndOfStream
//
HRESULT CTeeInputPin::EndOfStream()
{
    CAutoLock lock_it(m_pLock);
    ASSERT(m_pTee->m_NumOutputPins);
    HRESULT hr = NOERROR;

    // Walk through the output pins list, sending the message downstream

    int n = m_pTee->m_NumOutputPins;
    POSITION pos = m_pTee->m_OutputPinsList.GetHeadPosition();

    while(n)
    {
        CTeeOutputPin *pOutputPin = m_pTee->m_OutputPinsList.GetNext(pos);
        if (pOutputPin != NULL)
        {
            hr = pOutputPin->DeliverEndOfStream();
            if (FAILED(hr))
                return hr;
        }
        else
        {
            // We should have as many pins as the count says we have
            ASSERT(FALSE);
        }
        n--;
    }
    return(NOERROR);

} // EndOfStream
Example #13
0
void db_key_value::list_value(std::list<std::string>& l) {
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    int rc = 0;
    char** result;
    int nrow, ncol;
    char* szMsg;
    rc = sqlite3_get_table(
             db_,
             "SELECT value FROM contacts",
             &result,
             &nrow,
             &ncol,
             &szMsg);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT value : ";
        ss << szMsg;
        sqlite3_free(szMsg);
        sqlite3_free_table(result);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    if (ncol != 1) return;
    for (int i = 1; i < (nrow + 1); ++i)
        l.push_back(result[i]);
    sqlite3_free_table(result);
}
Example #14
0
//
// Active
//
// This is called when we start running or go paused. We create the
// output queue object to send data to our associated peer pin
//
HRESULT CTeeOutputPin::Active()
{
    CAutoLock lock_it(m_pLock);
    HRESULT hr = NOERROR;

    // Make sure that the pin is connected
    if(m_Connected == NULL)
        return NOERROR;

    // Create the output queue if we have to
    if(m_pOutputQueue == NULL)
    {
        m_pOutputQueue = new COutputQueue(m_Connected, &hr, TRUE, FALSE);
        if(m_pOutputQueue == NULL)
            return E_OUTOFMEMORY;

        // Make sure that the constructor did not return any error
        if(FAILED(hr))
        {
            delete m_pOutputQueue;
            m_pOutputQueue = NULL;
            return hr;
        }
    }

    // Pass the call on to the base class
    CBaseOutputPin::Active();
    return NOERROR;

} // Active
Example #15
0
//
// CheckMediaType
//
HRESULT CTeeInputPin::CheckMediaType(const CMediaType *pmt)
{
    CAutoLock lock_it(m_pLock);

    // If we are already inside checkmedia type for this pin, return NOERROR
    // It is possble to hookup two of the tee filters and some other filter
    // like the video effects sample to get into this situation. If we don't
    // detect this situation, we will carry on looping till we blow the stack

    if (m_bInsideCheckMediaType == TRUE)
        return NOERROR;

    m_bInsideCheckMediaType = TRUE;
    HRESULT hr = NOERROR;

#ifdef DEBUG
    // Display the type of the media for debugging perposes
    DisplayMediaType(TEXT("Input Pin Checking"), pmt);
#endif

    // The media types that we can support are entirely dependent on the
    // downstream connections. If we have downstream connections, we should
    // check with them - walk through the list calling each output pin

    int n = m_pTee->m_NumOutputPins;
    POSITION pos = m_pTee->m_OutputPinsList.GetHeadPosition();

    while(n)
    {
        CTeeOutputPin *pOutputPin = m_pTee->m_OutputPinsList.GetNext(pos);

        if (pOutputPin != NULL)
        {
            if (pOutputPin->m_Connected != NULL)
            {
                // The pin is connected, check its peer
                hr = pOutputPin->m_Connected->QueryAccept(pmt);
                if (hr != NOERROR)
                {
                    m_bInsideCheckMediaType = FALSE;
                    return VFW_E_TYPE_NOT_ACCEPTED;
                }
            }
        }
        else
        {
            // We should have as many pins as the count says we have
            ASSERT(FALSE);
        }

        n--;
    }

    // Either all the downstream pins have accepted or there are none.
    m_bInsideCheckMediaType = FALSE;
    return NOERROR;

} // CheckMediaType
Example #16
0
void db_multi_key_data::find_no_blob(
    const std::string& key,
    std::list<data_item_proto>& out)
{
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    int rc = 0;
    sqlite3_stmt* stmt = NULL;
    {   // for ss I m lazy
        std::stringstream ss("");
        ss << "SELECT ";
        ss << "data_time.time, data_time.ttl, data_header.title ";
        ss << "FROM data_header, data_time, data_item ";
        ss << "WHERE data_header.id IN ( ";
        ss << "SELECT data_header.id ";
        ss << "FROM data_header ";
        ss << "WHERE key = '" << key << "') ";
        ss << "AND data_time.time_id IN ( ";
        ss << "SELECT data_time.time_id ";
        ss << "FROM data_header, data_time ";
        ss << "WHERE data_header.key = '" << key << "' ";
        ss << "AND data_header.id = data_time.time_id)";
        rc = sqlite3_prepare_v2(
                 db_,
                 ss.str().c_str(),
                 -1,
                 &stmt,
                 NULL);
    }
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT [...] : ";
        ss << sqlite3_errmsg(db_);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    // for each row
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        // for each column
        data_item_proto di;
        for (int i = 0; i < sqlite3_column_count(stmt); ++i) {
            std::string column_name = sqlite3_column_name(stmt, i);
            if (column_name == std::string("time"))
                di.set_time(sqlite3_column_int64(stmt, i));
            if (column_name == std::string("ttl"))
                di.set_ttl(sqlite3_column_int64(stmt, i));
            if (column_name == std::string("title"))
                di.set_title((const char*)sqlite3_column_text(stmt, i));
        }
        out.push_back(di);
    }
    rc = sqlite3_finalize(stmt);
    if (rc != SQLITE_OK) {
        local_lock_.unlock();
        throw std::runtime_error("SQL error finalize in SELECT * !");
    }
}
Example #17
0
void BaseSearchMgr::SetSection(DVBSection *pSection)
{
	AutoLockT lock_it(m_dequeMutex);
	if(NULL != pSection)
	{
		m_dequePacket.push_back(pSection);
		NotifyDataArrived();
	}
}
Example #18
0
db_multi_key_data::~db_multi_key_data() {
    try {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if(need_mutex_) local_lock_.lock();
        sqlite3_close(db_);
        db_ = NULL;
    } catch (std::exception& ex) {
        local_lock_.unlock();
        throw ex;
    }
}
Example #19
0
DVBSection* BaseSearchMgr::GetSection()
{
	AutoLockT lock_it(m_dequeMutex);
	DVBSection *pSection = NULL;
	if(!m_dequePacket.empty())
	{
		pSection = m_dequePacket.front();
		m_dequePacket.pop_front();
	}
	return pSection ; 
}
Example #20
0
void BaseSearchMgr::RemoveSection(U16 pid, U8 tableID)
{
	AutoLockT lock_it(m_dequeMutex);
	
	DVBSection *pSection = NULL;
	for(U32 iCount = 0 ; iCount < m_dequePacket.size();iCount++)
	{
		pSection = m_dequePacket[iCount];
		FreeSection(pSection);
		m_dequePacket.erase(m_dequePacket.begin()+iCount);
	}
}
Example #21
0
// 清除队列
void BaseSearchMgr::ClearSectionDeque()
{
	AutoLockT lock_it(m_dequeMutex);
	
	DVBSection *pSection = NULL;
	for(U32 iCount = 0 ; iCount < m_dequePacket.size();iCount++)
	{
		pSection = m_dequePacket[iCount];
		FreeSection(pSection);
	}
	m_dequePacket.clear();
}
Example #22
0
void db_multi_key_data::list(
    std::multimap<std::string, data_item_proto>& out)
{
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    int rc = 0;
    sqlite3_stmt* stmt = NULL;
    rc = sqlite3_prepare_v2(
             db_,
             "SELECT data_time.time, data_time.ttl, "\
             "data_header.title, data_item.data "\
             "FROM data_header, data_time, data_item "\
             "WHERE data_header.id = data_time.time_id "\
             "AND data_header.id = data_item.item_id",
             -1,
             &stmt,
             NULL);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT * : ";
        ss << sqlite3_errmsg(db_);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    // for each row
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        // for each column
        data_item_proto di;
        std::string key = "";
        for (int i = 0; i < sqlite3_column_count(stmt); ++i) {
            std::string column_name = sqlite3_column_name(stmt, i);
            if (column_name == std::string("key"))
                key = (const char*)sqlite3_column_text(stmt, i);
            if (column_name == std::string("time"))
                di.set_time(sqlite3_column_int64(stmt, i));
            if (column_name == std::string("ttl"))
                di.set_ttl(sqlite3_column_int64(stmt, i));
            if (column_name == std::string("title"))
                di.set_title((const char*)sqlite3_column_text(stmt, i));
            if (column_name == std::string("data")) {
                size_t data_size = sqlite3_column_bytes(stmt, i);
                di.set_data(sqlite3_column_blob(stmt, i), data_size);
            }
        }
        out.insert(std::make_pair<std::string, data_item_proto>(key, di));
    }
    rc = sqlite3_finalize(stmt);
    if (rc != SQLITE_OK) {
        local_lock_.unlock();
        throw std::runtime_error("SQL error finalize in SELECT * !");
    }
}
Example #23
0
//
// EnumMediaTypes
//
STDMETHODIMP CTeeOutputPin::EnumMediaTypes(IEnumMediaTypes **ppEnum)
{
    CAutoLock lock_it(m_pLock);
    ASSERT(ppEnum);

    // Make sure that we are connected
    if(m_pTee->m_Input.m_Connected == NULL)
        return VFW_E_NOT_CONNECTED;

    // We will simply return the enumerator of our input pin's peer
    return m_pTee->m_Input.m_Connected->EnumMediaTypes(ppEnum);

} // EnumMediaTypes
Example #24
0
//
// SetMediaType
//
HRESULT CTeeInputPin::SetMediaType(const CMediaType *pmt)
{
    CAutoLock lock_it(m_pLock);
    HRESULT hr = NOERROR;

    // Make sure that the base class likes it
    hr = CBaseInputPin::SetMediaType(pmt);
    if (FAILED(hr))
        return hr;

    ASSERT(m_Connected != NULL);
    return NOERROR;

} // SetMediaType
Example #25
0
//
// Inactive
//
// This is called when we stop streaming
// We delete the output queue at this time
//
HRESULT CTeeOutputPin::Inactive()
{
    CAutoLock lock_it(m_pLock);

    // Delete the output queus associated with the pin.
    if(m_pOutputQueue)
    {
        delete m_pOutputQueue;
        m_pOutputQueue = NULL;
    }

    CBaseOutputPin::Inactive();
    return NOERROR;

} // Inactive
Example #26
0
//
// NonDelegatingRelease
//
// CTeeOutputPin overrides this class so that we can take the pin out of our
// output pins list and delete it when its reference count drops to 1 and there
// is atleast two free pins.
//
// Note that CreateNextOutputPin holds a reference count on the pin so that
// when the count drops to 1, we know that no one else has the pin.
//
// Moreover, the pin that we are about to delete must be a free pin(or else
// the reference would not have dropped to 1, and we must have atleast one
// other free pin(as the filter always wants to have one more free pin)
//
// Also, since CBasePin::NonDelegatingAddRef passes the call to the owning
// filter, we will have to call Release on the owning filter as well.
//
// Also, note that we maintain our own reference count m_cOurRef as the m_cRef
// variable maintained by CBasePin is debug only.
//
STDMETHODIMP_(ULONG) CTeeOutputPin::NonDelegatingRelease()
{
    CAutoLock lock_it(m_pLock);

#ifdef DEBUG
    // Update the debug only variable in CBasePin
    m_cRef--;
    ASSERT(m_cRef >= 0);
#endif

    // Now update our reference count
    m_cOurRef--;
    ASSERT(m_cOurRef >= 0);

    // if the reference count on the object has gone to one, remove
    // the pin from our output pins list and physically delete it
    // provided there are atealst two free pins in the list(including
    // this one)

    // Also, when the ref count drops to 0, it really means that our
    // filter that is holding one ref count has released it so we
    // should delete the pin as well.

    if(m_cOurRef <= 1)
    {
        int n = 2;                     // default forces pin deletion
        if(m_cOurRef == 1)
        {
            // Walk the list of pins, looking for count of free pins
            n = m_pTee->GetNumFreePins();
        }

        // If there are two free pins, delete this one.
        // NOTE: normall
        if(n >= 2)
        {
            m_cOurRef = 0;
#ifdef DEBUG
            m_cRef = 0;
#endif
            m_pTee->DeleteOutputPin(this);
            return(ULONG) 0;
        }
    }

    return(ULONG) m_cOurRef;

} // NonDelegatingRelease
Example #27
0
//
// NonDelegatingAddRef
//
// We need override this method so that we can do proper reference counting
// on our output pin. The base class CBasePin does not do any reference
// counting on the pin in RETAIL.
//
// Please refer to the comments for the NonDelegatingRelease method for more
// info on why we need to do this.
//
STDMETHODIMP_(ULONG) CTeeOutputPin::NonDelegatingAddRef()
{
    CAutoLock lock_it(m_pLock);

#ifdef DEBUG
    // Update the debug only variable maintained by the base class
    m_cRef++;
    ASSERT(m_cRef > 0);
#endif

    // Now update our reference count
    m_cOurRef++;
    ASSERT(m_cOurRef > 0);
    return m_cOurRef;

} // NonDelegatingAddRef
Example #28
0
//
// CompleteConnect
//
HRESULT CTeeOutputPin::CompleteConnect(IPin *pReceivePin)
{
    CAutoLock lock_it(m_pLock);
    ASSERT(m_Connected == pReceivePin);
    HRESULT hr = NOERROR;

    hr = CBaseOutputPin::CompleteConnect(pReceivePin);
    if(FAILED(hr))
        return hr;

    // If the type is not the same as that stored for the input
    // pin then force the input pins peer to be reconnected

    if(m_mt != m_pTee->m_Input.m_mt)
    {
        hr = m_pTee->ReconnectPin(m_pTee->m_Input.m_Connected, &m_mt);
        if(FAILED(hr))
        {
            return hr;
        }
    }

    // Since this pin has been connected up, create another output pin. We
    // will do this only if there are no unconnected pins on us. However
    // CompleteConnect will get called for the same pin during reconnection

    int n = m_pTee->GetNumFreePins();
    ASSERT(n <= 1);
    if(n == 1 || m_pTee->m_NumOutputPins == INFTEE_MAX_PINS)
        return NOERROR;

    // No unconnected pins left so spawn a new one

    CTeeOutputPin *pOutputPin = m_pTee->CreateNextOutputPin(m_pTee);
    if(pOutputPin != NULL)
    {
        m_pTee->m_NumOutputPins++;
        m_pTee->m_OutputPinsList.AddTail(pOutputPin);
        m_pTee->IncrementPinVersion();
    }

    // At this point we should be able to send some
    // notification that we have sprung a new pin

    return NOERROR;

} // CompleteConnect
Example #29
0
void db_multi_key_data::list_headers(std::list<data_item_header_t>& out) {
    boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
    if (need_mutex_) local_lock_.lock();
    int rc = 0;
    sqlite3_stmt* stmt = NULL;
    rc = sqlite3_prepare_v2(
             db_,
             "SELECT data_header.key, data_time.time, "\
             "data_time.ttl, data_header.title "\
             "FROM data_header, data_time, data_item "\
             "WHERE data_header.id = data_time.time_id "\
             "AND data_header.id = data_item.item_id",
             -1,
             &stmt,
             NULL);
    if (rc != SQLITE_OK) {
        std::stringstream ss("");
        ss << "SQL error in SELECT key, time, ttl, title : ";
        ss << sqlite3_errmsg(db_);
        local_lock_.unlock();
        throw std::runtime_error(ss.str());
    }
    // for each row
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        // for each column
        data_item_header_t dh;
        std::string key = "";
        for (int i = 0; i < sqlite3_column_count(stmt); ++i) {
            std::string column_name = sqlite3_column_name(stmt, i);
            if (column_name == std::string("key"))
                dh.key = (const char*)sqlite3_column_text(stmt, i);
            if (column_name == std::string("time"))
                dh.time = sqlite3_column_int64(stmt, i);
            if (column_name == std::string("ttl"))
                dh.ttl = sqlite3_column_int64(stmt, i);
            if (column_name == std::string("title"))
                dh.title = (const char*)sqlite3_column_text(stmt, i);
        }
        out.push_back(dh);
    }
    rc = sqlite3_finalize(stmt);
    if (rc != SQLITE_OK) {
        local_lock_.unlock();
        throw std::runtime_error(
            "SQL error finalize in SELECT key, time, ttl, title !");
    }
}
Example #30
0
bool SickS300::close(Errors& error) {
    // Bouml preserved body begin 00020F67
    stopThread = true;

    threads.join_all();

    {
        boost::mutex::scoped_lock lock_it(mutexSickS300);
        if (sickS300 != NULL) {
            LOG(trace) << "connection to Sick S300 closed";
            delete sickS300;
            sickS300 = NULL;
        }
        this->isConnected = false;
    }
    return true;
    // Bouml preserved body end 00020F67
}