Example #1
0
  static axiom_node_t * AXIS2_CALL Axis2Service_on_fault(
    axis2_svc_skeleton_t*,
    const axutil_env_t* pEnv,
    axiom_node_t* /*pNode*/)
  {
    staff::ScopedLock tLock(m_tFaultDetailsMutex);

    std::map<unsigned long, std::string>::iterator itFault =
        m_mFaultDetails.find(staff::Thread::GetCurrentId());

    axiom_node_t* pErrorNode = NULL;
    axiom_element_t* pErrorElement = axiom_element_create(pEnv, NULL, "Exception", NULL, &pErrorNode);

    if (itFault != m_mFaultDetails.end())
    {
      axiom_element_set_text(pErrorElement, pEnv, itFault->second.c_str(), pErrorNode);
      m_mFaultDetails.erase(itFault);
    }
    else
    {
      axiom_element_set_text(pErrorElement, pEnv, "No fault details", pErrorNode);
    }

    return pErrorNode;
  }
/**********************************************************
Pauses of restarts RX activity.
Restart is immediate, pause may be delayed until
NDIS returns all the indicated NBL

Parameters:
    context
    bPause 1/0 - pause or restart
    ONPAUSECOMPLETEPROC Callback to be called when PAUSE finished
Return value:
    SUCCESS if finished synchronously
    PENDING if not, then callback will be called
***********************************************************/
NDIS_STATUS ParaNdis6_ReceivePauseRestart(
    PARANDIS_ADAPTER *pContext,
    BOOLEAN bPause,
    ONPAUSECOMPLETEPROC Callback
    )
{
    NDIS_STATUS status = NDIS_STATUS_SUCCESS;

    if (bPause)
    {
        CNdisPassiveWriteAutoLock tLock(pContext->m_PauseLock);

        ParaNdis_DebugHistory(pContext, hopInternalReceivePause, NULL, 1, 0, 0);
        if (pContext->m_rxPacketsOutsideRing != 0)
        {
            pContext->ReceiveState = srsPausing;
            pContext->ReceivePauseCompletionProc = Callback;
            status = NDIS_STATUS_PENDING;
        }
        else
        {
            ParaNdis_DebugHistory(pContext, hopInternalReceivePause, NULL, 0, 0, 0);
            pContext->ReceiveState = srsDisabled;
        }
    }
    else
    {
        ParaNdis_DebugHistory(pContext, hopInternalReceiveResume, NULL, 0, 0, 0);
        pContext->ReceiveState = srsEnabled;
    }
    return status;
}
Example #3
0
	//任务分发
	void dispatch()
	{
		while (mRunning.load()) {
			std::unique_lock<std::mutex> tLock(mMutex);
			mCondition.wait(tLock, [this]() { return !mTasks.Empty(); });
			Task task{std::move(mTasks.Front())};
			mTasks.Pop(); //删掉队列的头元素
			task();
		}
	}
/**********************************************************
Pauses of restarts TX activity.
Restart is immediate, pause may be delayed until
we return all the NBLs to NDIS

Parameters:
    context
    bPause 1/0 - pause or restart
    ONPAUSECOMPLETEPROC Callback to be called when PAUSE finished
Return value:
    SUCCESS if finished synchronously
    PENDING if not, then callback will be called later
***********************************************************/
NDIS_STATUS ParaNdis6_SendPauseRestart(
    PARANDIS_ADAPTER *pContext,
    BOOLEAN bPause,
    ONPAUSECOMPLETEPROC Callback
)
{
    NDIS_STATUS status = NDIS_STATUS_SUCCESS;
    DEBUG_ENTRY(4);
    if (bPause)
    {
        ParaNdis_DebugHistory(pContext, hopInternalSendPause, NULL, 1, 0, 0);
        if (pContext->SendState == srsEnabled)
        {
            {
                CNdisPassiveWriteAutoLock tLock(pContext->m_PauseLock);

                pContext->SendState = srsPausing;
                pContext->SendPauseCompletionProc = Callback;
            }

            for (UINT i = 0; i < pContext->nPathBundles; i++)
            {
                if (!pContext->pPathBundles[i].txPath.Pause())
                {
                    status = NDIS_STATUS_PENDING;
                }
            }

            if (status == NDIS_STATUS_SUCCESS)
            {
                pContext->SendState = srsDisabled;
            }
        }
        if (status == NDIS_STATUS_SUCCESS)
        {
            ParaNdis_DebugHistory(pContext, hopInternalSendPause, NULL, 0, 0, 0);
        }
    }
    else
    {
        pContext->SendState = srsEnabled;
        ParaNdis_DebugHistory(pContext, hopInternalSendResume, NULL, 0, 0, 0);
    }
    return status;
}
Example #5
0
  /*
  * This method invokes the target service method 
  */
  static axiom_node_t* AXIS2_CALL
    Axis2Service_invoke(axis2_svc_skeleton_t* /*pServiceSkeleton*/,
    const axutil_env_t* pEnv,
    axiom_node_t* pAxiomNode,
    axis2_msg_ctx_t* pMsgCtx)
  {
    if (pAxiomNode == NULL)
    {
      staff::LogError() << "AxiOM node is NULL\n";
      return NULL;
    }

    if (axiom_node_get_node_type(pAxiomNode, pEnv) != AXIOM_ELEMENT)
    {
      staff::LogError() << "Can't get AxiOM node type";
      return NULL;
    }

    axiom_element_t* pAxiomElement = (axiom_element_t*)axiom_node_get_data_element(pAxiomNode, pEnv);
    if (pAxiomElement == NULL)
    {
      staff::LogError() << "Can't get AxiOM node element\n";
      return NULL;
    }

    const axis2_char_t* szServiceName = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "ServiceName"));
#ifndef WITHOUT_SECURITY
    const axis2_char_t* szSessionId = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "SessionId"));
    const axis2_char_t* szInstanceId = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "InstanceId"));
#endif

    if (szServiceName == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get service name.";
      return NULL;
    }

#ifndef WITHOUT_SECURITY
    if (szSessionId == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get session id.";
      return NULL;
    }

    if (szInstanceId == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get instance id.";
      return NULL;
    }
#endif

#ifdef _DEBUG
    staff::LogDebug1() << "Service name: [" << szServiceName << "]";
#ifndef WITHOUT_SECURITY
    staff::LogDebug1() << "Session id: [" << szSessionId << "]";
    staff::LogDebug1() << "Instance id: [" << szInstanceId << "]";
#endif

    {
      axiom_node_t* panBody = axiom_node_get_parent(pAxiomNode, pEnv);
      axiom_node_t* panEnv = axiom_node_get_parent(panBody, pEnv);

      staff::LogDebug2() << "request SOAP Envelope: \n" << staff::ColorTextBlue
                  << staff::DataObject(panEnv).ToString() << "\n" << staff::ColorDefault;
    }
#endif

    staff::Operation tOperation;
    staff::MessageContext tMessageContext(pEnv, pMsgCtx);

    std::string sServiceName(szServiceName);
#ifndef WITHOUT_SECURITY
    std::string sSessionId(szSessionId);
    std::string sInstanceId(szInstanceId);
#else
    static std::string sSessionId;
    static std::string sInstanceId;
#endif

    try
    {
      tOperation.SetRequest(pAxiomNode);
      tOperation.SetMessageContext(tMessageContext);

      if (axis2_msg_ctx_get_doing_rest(pMsgCtx, pEnv))
      {
        const axis2_char_t* szOperation = reinterpret_cast<const axis2_char_t*>
            (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "Operation"));
        if (szOperation != NULL)
        {
          tOperation.SetName(szOperation);
        }
      }

      if (sServiceName == "StaffService")
      {
        staff::ServiceDispatcher::Inst().InvokeSelf(tOperation);
      }
      else
      {
        staff::ServiceWrapper* pServiceWrapper =
            staff::SharedContext::Inst().GetService(sServiceName);
        STAFF_ASSERT(pServiceWrapper, "Service [" + sServiceName + "] is not found: ");
        pServiceWrapper->Invoke(tOperation, sSessionId, sInstanceId);
      }
    }
    catch (const staff::SoapUserFaultException& rEx)
    {
      try
      {
        staff::DataObject tdoFault;
        tdoFault.FromString(rEx.GetFault());
        tOperation.SetUserFault(tdoFault);
      }
      catch (...)
      {
        tOperation.SetFault("server", "Invalid format of user soap fault",
                            "Failed to invoke service " + sServiceName
                            + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                            + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                            );
      }
    }
    catch (const staff::SoapFaultException& rEx)
    {
      tOperation.SetFault(rEx.GetCode(), rEx.GetString(), rEx.GetDetail());
    }
    catch (const std::exception& rEx)
    {
      tOperation.SetFault("server", rEx.what(), "Failed to invoke service " + sServiceName
                          + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                          + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                          );
    }
    catch (...)
    {
      tOperation.SetFault("server", "Unknown exception", "Failed to invoke service " + sServiceName
                          + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                          + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                          );
    }

    if (tOperation.IsFault())
    {
      staff::ScopedLock tLock(m_tFaultDetailsMutex);

      m_mFaultDetails[staff::Thread::GetCurrentId()] = tOperation.GetFaultDetail();
      staff::LogWarning() << "Fault: \n" << tOperation.GetFaultDescr() << "\n";
      AXIS2_ERROR_SET_MESSAGE(pEnv->error, static_cast<axis2_char_t*>(axutil_strdup(pEnv, tOperation.GetFaultString().c_str())));
      AXIS2_ERROR_SET_ERROR_NUMBER(pEnv->error, static_cast<axutil_error_codes_t>(AXUTIL_ERROR_MAX + 1));
      AXIS2_ERROR_SET_STATUS_CODE(pEnv->error, AXIS2_FAILURE);
      if (!m_bHttp200OnFault)
        return NULL;
    }

    if(!IsNeedReply(pMsgCtx, pEnv))
    {
      return NULL;
    }

    tOperation.PrepareResult();
    staff::DataObject& rResponse = tOperation.GetResponse();
    rResponse.SetOwner(false);

#ifdef _DEBUG
    staff::LogDebug2() << "Sending Response: \n" <<  staff::ColorTextBlue << rResponse.ToString() << "\n" << staff::ColorDefault;
#endif

    return rResponse;
  }
void processTransactions(const std::string& name, std::ifstream& in) {
    Transaction t;
    while(in >> t) {
        if(t.operation() == Operation::Deposit) {
            // Deposit routine.
            if(t.account() == AccountType::Checking) {
                std::lock_guard l(checkingLock);
                checking += t.amount();
                std::cout << name << " deposited $" << t.amount() << ". New "
                          << t.account() << " balance: $" << checking << std::endl;
            } else if(t.account() == AccountType::Savings) {
                std::lock_guard l(savingsLock);
                savings += t.amount();
                std::cout << name << " deposited $" << t.amount() << ". New "
                          << t.account() << " balance: $" << savings << std::endl;
            }
        } else if(t.operation() == Operation::Withdrawal) {
            // Withdraw routine.
            // Lock whichever account is being accessed.
            if(t.account() == AccountType::Checking) {
                std::lock_guard l(checkingLock);
                if(t.amount() > checking) {
                    // Lock both accounts if transfering.
                    std::lock_guard transferL(transferLock);
                    std::lock_guard savingsL(savingsLock);
                    if(savings > 0) {
                        savings += checking;
                        checking = 0;
                        savings -= t.amount();
                        std::cout << name << " withdrew $" << t.amount() << "." << std::endl;
                        printBalances();
                    } else {
                        std::cout << name << " cannot withdraw $" << t.amount()
                                  << ". Insufficient funds." << std::endl;
                    }
                } else {
                    checking -= t.amount();
                    std::cout << name << " withdrew $" << t.amount() << ". New "
                              << t.account() << " balance: $" << checking << std::endl;
                }
            } else if(t.account() == AccountType::Savings) {
                std::lock_guard l(savingsLock);
                if(savings > 0) {
                    savings -= t.amount();
                    std::cout << name << " withdrew $" << t.amount() << ". New"
                              << t.account() << " balance: $" << savings << std::endl;
                } else {
                    std::cout << name << " cannot withdraw $" << t.amount()
                              << ". Insufficient funds." << std::endl;
                }
            }
        } else if(t.operation() == Operation::Transfer) {
            // Transfer routine.
            // Lock both accounts when transfering.
            std::lock_guard tLock(transferLock);
            std::lock_guard cLock(checkingLock);
            std::lock_guard sLock(savingsLock);
            if(t.account() == AccountType::Checking) {
                if(savings > 0) {
                    checking += t.amount();
                    savings -= t.amount();
                    std::cout << name << " transferred $" << t.amount()
                              << " from savings to checking." << std::endl;
                    printBalances();
                } else {
                    std::cout << name << " cannot transfer $" << t.amount()
                              << ". Insufficient funds." << std::endl;
                }
            } else if(t.account() == AccountType::Savings) {
                if(checking > 0) {
                    checking -= t.amount();
                    savings += t.amount();
                    std::cout << name << " transferred $" << t.amount()
                              << " from checking to savings." << std::endl;
                    printBalances();
                } else {
                    std::cout << name << " cannot transfer $" << t.amount()
                              << ". Insufficient funds." << std::endl;
                }
            }
        }
    }
    return;
}