plugin_thread.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: plugin_thread.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:44:33 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: plugin_thread.cpp,v 1000.1 2004/06/01 20:44:33 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include "plugin_thread.hpp"
- #include <gui/plugin/PluginReply.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/obj_convert.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- CPluginTask::CPluginTask(CPluginHandle& handle, CPluginMessage& msg)
- : m_Handle(handle)
- , m_Message(&msg)
- {
- #if 0 //def NCBI_THREADS
- m_Thread.Reset(new CPluginThread(m_Handle, *m_Message));
- m_Thread->Run(CThread::fRunAllowST);
- #else
- m_Handle.Execute(*m_Message);
- #endif
- }
- bool CPluginTask::IsCompleted(void) const
- {
- return m_Thread ? m_Thread->IsCompleted() : true;
- }
- void CPluginTask::Finalize(void)
- {
- if ( !m_Message ) {
- return;
- }
- if (m_Thread) {
- m_Thread->Join();
- }
- // process the replies
- CPluginReply& reply = m_Message->SetReply();
- if (reply.CanGetFormatted()) {
- // favor caller's preference and fit the raw objects into
- // the caller's preformatted args
- CPluginUtils::FillArgs(reply.SetFormatted(), reply.GetRaw());
- } else if (reply.CanGetAction()) {
- //
- // default action processing
- //
- x_ProcessReply(reply);
- }
- switch (reply.GetStatus()) {
- case eMessageStatus_failed:
- LOG_POST(Error << "Failed to execute plugin");
- break;
- default:
- break;
- }
- // reset our data so we're empty
- LOG_POST(Info << "finalized message: " << m_Message->ToString());
- m_Thread.Reset();
- m_Message.Reset();
- }
- void CPluginTask::x_ProcessReply(const CPluginReply& reply) const
- {
- ITERATE (CPluginReply::TAction, act_iter, reply.GetAction()) {
- const CPluginReplyAction& act = **act_iter;
- switch (act.Which()) {
- case CPluginReplyAction::e_Add_to_document:
- //
- // add the object to the current document
- //
- ITERATE (CPluginReply::TRaw, raw_iter, reply.GetRaw()) {
- const CPluginValue& val = **raw_iter;
- if ( !val.IsObject() ) {
- // we only do this with values of type Object
- continue;
- }
- //
- // generically convert everything to a seq-entry
- //
- IDocument* doc =
- const_cast<IDocument*>(val.GetDocument());
- CObjectConverter::TObjList objs;
- CObjectConverter::Convert(doc->GetScope(),
- *val.GetObject(),
- CSeq_entry::GetTypeInfo(), objs);
- ITERATE (CObjectConverter::TObjList, obj_iter, objs) {
- const CSeq_entry* entry =
- dynamic_cast<const CSeq_entry*>
- (obj_iter->GetPointer());
- if ( !entry ) {
- continue;
- }
- doc->GetScope()
- .AddTopLevelSeqEntry(const_cast<CSeq_entry&>(*entry));
- }
- doc->UpdateAllViews();
- LOG_POST(Error << "unhandled object in plugin reply");
- }
- break;
- case CPluginReplyAction::e_New_view:
- break;
- default:
- break;
- }
- }
- }
- CPluginThread::CPluginThread(CPluginHandle& handle, CPluginMessage& msg)
- : m_Handle(handle)
- , m_Message(&msg)
- , m_Completed(false)
- {
- }
- void* CPluginThread::Main()
- {
- m_Handle.Execute(*m_Message);
- m_Completed = true;
- return NULL;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: plugin_thread.cpp,v $
- * Revision 1000.1 2004/06/01 20:44:33 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- *
- * Revision 1.4 2004/05/21 22:27:40 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.3 2004/01/21 12:38:18 dicuccio
- * redesigned CObjectCOnverter API to eliminate temporary object creation
- *
- * Revision 1.2 2003/12/22 19:20:41 dicuccio
- * Added implementation of plugin tasks (initial revision; not currently used)
- *
- * Revision 1.1 2003/12/09 15:51:19 dicuccio
- * Deprecated Fl_Toggle_Tree - replaced with Flu_Tree_Browser. Added CTreeBrowser
- * as a standard tree interface
- *
- * ===========================================================================
- */