コード例 #1
0
    inline saga::task
    dispatch_sync (run_mode     mode, 
                   char const * name,
                   TR1::shared_ptr<v1_0::cpi> cpi_instance,
                   void       (Base::*sync ) (RetVal &, BOOST_PP_ENUM_PARAMS (K, FuncArg)),
                   saga::task (Base::*async) (          BOOST_PP_ENUM_PARAMS (K, FuncArg)),
                   BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg))
    {
        TR1::shared_ptr<Base> c = TR1::static_pointer_cast<Base>(cpi_instance);

        switch (mode) {
        case Sync_Sync:
            return sync_sync(c, sync, BOOST_PP_ENUM_PARAMS(K, arg));

        case Sync_Async:
            return sync_async(c, async, BOOST_PP_ENUM_PARAMS(K, arg));

        case Async_Sync:
        case Async_Async:
            BOOST_ASSERT(false);
            break;

        default:
            break;
        }

        // no adaptor found  (Invalid mode)!
        SAGA_THROW_VERBATIM(cpi_instance.get(),
            std::string ("No adaptor implements method: ") + name,
            adaptors::NoAdaptor);

        return saga::task(saga::task_base::Done);
    }
コード例 #2
0
ファイル: ConsoleHandler.cpp プロジェクト: ciriarte/console
void ConsoleHandler::SendConsoleText(HANDLE hStdIn, const tr1::shared_ptr<wchar_t>& textBuffer)
{
	wchar_t*	pszText	= textBuffer.get();
	size_t		textLen = wcslen(pszText);
	size_t		partLen	= 512;
	size_t		parts	= textLen/partLen;
	size_t		offset	= 0;

	for (size_t part = 0; part < parts+1; ++part)
	{
		size_t	keyEventCount = 0;
		
		if (part == parts)
		{
			// last part, modify part size
			partLen = textLen - parts*partLen;
		}

		scoped_array<INPUT_RECORD> pKeyEvents(new INPUT_RECORD[partLen]);
		::ZeroMemory(pKeyEvents.get(), sizeof(INPUT_RECORD)*partLen);

		for (size_t i = 0; (i < partLen) && (offset < textLen); ++i, ++offset, ++keyEventCount)
		{
			if ((pszText[offset] == L'\r') || (pszText[offset] == L'\n'))
			{
				if ((pszText[offset] == L'\r') && (pszText[offset+1] == L'\n')) ++offset;

				if (keyEventCount > 0)
				{
					DWORD dwTextWritten = 0;
					::WriteConsoleInput(hStdIn, pKeyEvents.get(), static_cast<DWORD>(keyEventCount), &dwTextWritten);
				}

				::PostMessage(m_consoleParams->hwndConsoleWindow, WM_KEYDOWN, VK_RETURN, 0x001C0001);
				::PostMessage(m_consoleParams->hwndConsoleWindow, WM_KEYUP, VK_RETURN, 0xC01C0001);

				keyEventCount = static_cast<size_t>(-1);
				partLen -= i;
				i = static_cast<size_t>(-1);
			}
			else
			{
				pKeyEvents[i].EventType							= KEY_EVENT;
				pKeyEvents[i].Event.KeyEvent.bKeyDown			= TRUE;
				pKeyEvents[i].Event.KeyEvent.wRepeatCount		= 1;
				pKeyEvents[i].Event.KeyEvent.wVirtualKeyCode	= LOBYTE(::VkKeyScan(pszText[offset]));
				pKeyEvents[i].Event.KeyEvent.wVirtualScanCode	= 0;
				pKeyEvents[i].Event.KeyEvent.uChar.UnicodeChar	= pszText[offset];
				pKeyEvents[i].Event.KeyEvent.dwControlKeyState	= 0;
			}
		}

		if (keyEventCount > 0)
		{
			DWORD dwTextWritten = 0;
			::WriteConsoleInput(hStdIn, pKeyEvents.get(), static_cast<DWORD>(keyEventCount), &dwTextWritten);
		}
	}
}
コード例 #3
0
 inline saga::task
 sync_async (TR1::shared_ptr <Cpi> cpi,
             saga::task (Base::*async)(BOOST_PP_ENUM_PARAMS (K, FuncArg)),
             BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg))
 {
     return saga::detail::run_wait(
         (cpi.get()->*async)(BOOST_PP_ENUM_PARAMS(K, arg)));
 }
コード例 #4
0
 inline saga::task
 sync_sync (TR1::shared_ptr <Cpi> cpi,
            void (Base::*sync) (RetVal &, BOOST_PP_ENUM_PARAMS (K, FuncArg)),
            BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg))
 {
     saga::task t(saga::task::Done);
     (cpi.get()->*sync)(
         t.get_result<RetVal>(), BOOST_PP_ENUM_PARAMS (K, arg));
     return t;
 }
コード例 #5
0
 inline saga::task
 async_async (TR1::shared_ptr <Cpi> cpi,
              TR1::shared_ptr <adaptor_selector_state> state,
              saga::task (Base::*async) (BOOST_PP_ENUM_PARAMS (K, FuncArg)),
              BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg))
 {
     saga::task t ((cpi.get()->*async)(BOOST_PP_ENUM_PARAMS(K, arg)));
     detail::set_selector_state(t, state);
     return t;
 }
コード例 #6
0
    inline saga::task
    sync_sync (TR1::shared_ptr <Cpi> cpi,
               void (Base::*sync) (saga::impl::void_t &, BOOST_PP_ENUM_PARAMS (K, FuncArg)),
               BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const& arg))
    {
        saga::task t (saga::task::Done);
        saga::impl::void_t void_result;

        (cpi.get()->*sync)(void_result, BOOST_PP_ENUM_PARAMS (K, arg));

        return t;
    }
コード例 #7
0
    inline saga::task
    dispatch_async (proxy * prxy, 
                    TR1::shared_ptr <adaptor_selector_state> state,
                    void       (Base::*sync_)  (RetVal &, BOOST_PP_ENUM_PARAMS (K, FuncArg)),
                    saga::task (Base::*async_) (          BOOST_PP_ENUM_PARAMS (K, FuncArg)),
                    BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg),
                    bool       (Base::*prep_)  (RetVal &, BOOST_PP_ENUM_PARAMS(K, FuncArg), saga::uuid) = NULL)
    {
        typedef void       (Base::*sync_func )(RetVal&, BOOST_PP_ENUM_PARAMS(K, FuncArg));
        typedef saga::task (Base::*async_func)(         BOOST_PP_ENUM_PARAMS(K, FuncArg));
        typedef bool       (Base::*prep_func )(RetVal&, BOOST_PP_ENUM_PARAMS(K, FuncArg), saga::uuid);

        void       (Base::*sync )() = NULL;
        saga::task (Base::*async)() = NULL;
        bool       (Base::*prep )() = NULL;

        run_mode mode = Unknown;
        TR1::shared_ptr<Base> c (
            state->get_next_cpi (mode, &sync, &async, &prep));

//      BOOST_ASSERT(NULL == sync  || (sync_func)  sync  == sync_ );
//      BOOST_ASSERT(NULL == async || (async_func) async == async_);
//      BOOST_ASSERT(NULL == prep  || (prep_func)  prep  == prep_ );

        switch (mode) {
        case Async_Sync:
            BOOST_ASSERT(sync);
            return async_sync(prxy, c, state, (sync_func)sync, 
                BOOST_PP_ENUM_PARAMS(K, arg), (prep_func)prep);

        case Async_Async:
            BOOST_ASSERT(async);
            return async_async(c, state, (async_func)async, 
                BOOST_PP_ENUM_PARAMS(K, arg));

        case Sync_Sync:
        case Sync_Async:
            BOOST_ASSERT(false);
            break;

        default:
            break;
        }

        // no adaptor found  (Invalid mode)!
        SAGA_THROW_VERBATIM(c.get(),
                            std::string ("No adaptor implements method: ") + state->get_op_name(),
                            adaptors::NoAdaptor);

        // this makes some compilers happy, but will never be called in fact
        // (didn't you see the throw above?)
        return saga::task(saga::task_base::Done);
    }