Example #1
0
    // implemented from callback interface
    // =============================================================================================
    void SubscriptionFactory::dataChange(
            OpcUa_UInt32                clientSubscriptionHandle,
            const UaDataNotifications&  dataNotifications,
            const UaDiagnosticInfos &   diagnosticInfos)
    {
        logger_->debug("New data change event for subscription %d", clientSubscriptionHandle);


        // acquire the subscription for which the event was meant:
        Subscription* subscription = 0;
        Status acquireStatus = acquireExistingSubscription(clientSubscriptionHandle, subscription);

        if (acquireStatus.isGood())
        {
            // update the session state
            subscription->dataChange(dataNotifications, diagnosticInfos);

            // release the acquired session
            releaseSubscription(subscription);
        }
        else
        {
            logger_->warning("Unknown ClientSubscriptionHandle, discarding notification!");
        }

    }
Example #2
0
DArray<uint16> * LocalNodeInfo::getSubscribingClients (Message *pMsg)
{
    DArray<uint16> *pSubscribingClients = NULL;
    uint16 j = 0;
     _m.lock (314);
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        PtrLList<Subscription> *pSubscriptions = i.getValue()->getSubscriptionWild (pMsg->getMessageHeader()->getGroupName());
        // Get every subscribed group that matches with the message's group
        if (pSubscriptions != NULL) {
            for (Subscription *pSub = pSubscriptions->getFirst(); pSub != NULL; pSub = pSubscriptions->getNext()) {
                if ((pSub->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) || pSub->matches(pMsg)) {
                    if (pSubscribingClients == NULL) {
                        pSubscribingClients = new DArray<uint16>();
                    }
                    bool bFound = false;
                    for (unsigned int k = 0; k < pSubscribingClients->size(); k++) {
                        if ((*pSubscribingClients)[k] == i.getKey()) {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound) {
                        (*pSubscribingClients)[j] = i.getKey();
                        j++;
                    }
                }
            }
            delete pSubscriptions;
            pSubscriptions = NULL;
        }
    }
    _m.unlock (314);
    return pSubscribingClients;
}
Example #3
0
    // implemented from callback interface
    // =============================================================================================
    void SubscriptionFactory::notificationsMissing(
            OpcUa_UInt32 clientSubscriptionHandle,
            OpcUa_UInt32 previousSequenceNumber,
            OpcUa_UInt32 newSequenceNumber)
    {
        logger_->debug("Notifications are missing for subscription %d! (%d + 1 != %d)",
                clientSubscriptionHandle,
                previousSequenceNumber,
                newSequenceNumber);

        // acquire the subscription:
        Subscription* subscription = 0;
        Status acquireStatus = acquireExistingSubscription(clientSubscriptionHandle, subscription);
        SubscriptionInformation info;

        if (acquireStatus.isGood())
        {
            // get the updated subscription info
            info = subscription->subscriptionInformation();

            // release the acquired session
            releaseSubscription(subscription);
        }
        else
        {
            logger_->warning("Unknown ClientSubscriptionHandle, discarding notification!");
        }

        // call the callback interface
        clientInterface_->notificationsMissing(info, previousSequenceNumber, newSequenceNumber);
    }
Example #4
0
void
Event_Channel::subscription_event (ACE_Message_Block *data)
{
  Event *event = (Event *) data->rd_ptr ();

  ACE_DEBUG ((LM_DEBUG,
              "(%t) received a subscription with %d bytes from connection id %d\n",
              event->header_.len_,
              event->header_.connection_id_));
  Subscription *subscription = (Subscription *) event->data_;
  // Convert the subscription into host byte order so that we can
  // access it directly without having to repeatedly muck with it...
  subscription->decode ();

  ACE_DEBUG ((LM_DEBUG,
              "(%t) connection_id_ = %d, total_consumers_ = %d\n",
              subscription->connection_id_,
              subscription->total_consumers_));

  for (ACE_INT32 i = 0;
       i < subscription->total_consumers_;
       i++)
    ACE_DEBUG ((LM_DEBUG,
                "(%t) consumers_[%d] = %d\n",
                i,
                subscription->consumers_[i]));

}
Example #5
0
void Receiver::execute(AsyncSession& session, bool /*isRetry*/)
{
    SubscriptionManager subs(session);
    subscription = subs.subscribe(*this, queue, settings);
    subs.run();
    if (settings.autoAck) {
        subscription.accept(subscription.getUnaccepted());
    }
}
Example #6
0
void LocalNodeInfo::recomputeConsolidateSubsciptionList (void)
{
    // TODO CHECK: I don't think the includes applies anymore, so I commented it
    // In fact, even if the includes returns true,
    // I still need to merge subscriptions in terms of priority, reliability, sequenced, etc

    CRC * pCRC = new CRC();
    pCRC->init();
    for (StringHashtable<Subscription>::Iterator iterator = _consolidatedSubscriptions.getIterator(); !iterator.end(); iterator.nextElement()) {
        pCRC->update ((const char *)iterator.getKey());
        pCRC->update32 (iterator.getValue());
    }
    uint16 oldCRC = pCRC->getChecksum();

    // Delete the current Consolidate Subscription List and compute a new one
    _consolidatedSubscriptions.clear();

    // For each client
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        SubscriptionList *pSL = i.getValue();
        if (pSL != NULL) {
            // Get all its subscriptions
            PtrLList<String> *pSubgroups = pSL->getAllSubscribedGroups();
            for (String *pSubGroupName = pSubgroups->getFirst(); pSubGroupName != NULL; pSubGroupName = pSubgroups->getNext()) {
                // For each group, get the subscription the client has
                const char *pszGroupName = pSubGroupName->c_str();
                Subscription *pClientSub = pSL->getSubscription (pszGroupName);
                // And the subscription in the consolidate subscription list if any
                Subscription *pSubInConsolidateList = _consolidatedSubscriptions.getSubscription (pszGroupName);
                if (pSubInConsolidateList == NULL) {
                    _consolidatedSubscriptions.addSubscription (pszGroupName, pClientSub->clone());
                }
                else {
                    /*if (pClientSub->includes (pSubInConsolidateList)) {
                        _consolidatedSubscriptions.removeGroup (pszGroupName);
                        _consolidatedSubscriptions.addSubscription (pszGroupName, pClientSub->clone());
                    }
                    else {*/
                        pClientSub->merge (pSubInConsolidateList);
                    /*}*/
                }
            }
        }
    }

    pCRC->reset();
    for (StringHashtable<Subscription>::Iterator iterator = _consolidatedSubscriptions.getIterator(); !iterator.end(); iterator.nextElement()) {
        pCRC->update ((const char *) iterator.getKey());
        pCRC->update32 (iterator.getValue());
    }
    uint16 newCRC = pCRC->getChecksum();
    if (oldCRC != newCRC) {
        ui32SubscriptionStateSeqID++;
        GroupSubscription *pSubscription = new GroupSubscription(); // Void subscription to respect method interface
        _notifier.modifiedSubscriptionForPeer (_pszId, pSubscription);
    }
}
int TopologyWorldState::updateSubscriptionState (StringHashtable<SubscriptionList> *pSubscriptionsTable, StringHashtable<uint32> *pNodesTable)
{
    // Updates the remote subscriptions with the pSubscriptionsTable and pNodesTable info
    _m.lock (131);
    for (StringHashtable<uint32>::Iterator iterator = pNodesTable->getAllElements(); !iterator.end(); iterator.nextElement()) {
        if (0 != stricmp (_pDisService->getNodeId(), iterator.getKey())) {
            RemoteNodeInfo * pRNI = (RemoteNodeInfo*) retrieveNodeInfo (iterator.getKey());
            if (pRNI) {
                uint32 *pui32RemoteSeqId = iterator.getValue();
                uint32 *pui32LocalSeqId = _subscriptionStateTable.get (iterator.getKey());
                if (!pui32LocalSeqId) {
                    pui32LocalSeqId = new uint32();
                }
                if ((*pui32RemoteSeqId) > (*pui32LocalSeqId)) {
                    pRNI->unsubscribeAll();
                    (*pui32LocalSeqId) = (*pui32RemoteSeqId);
                    _subscriptionStateTable.put (iterator.getKey(), pui32LocalSeqId);
                    continue;
                }
            }
        }
        pNodesTable->remove (iterator.getKey());
    }
    // Update _ui16SubscriptionStateCRC
    _crc.reset();
    for (StringHashtable<uint32>::Iterator iterator = _subscriptionStateTable.getAllElements(); !iterator.end(); iterator.nextElement()) {
        _crc.update ((const char *) iterator.getKey());
        _crc.update32 (iterator.getValue());
    }
    _ui16SubscriptionStateCRC = _crc.getChecksum();
    for (StringHashtable<SubscriptionList>::Iterator subIterator = pSubscriptionsTable->getAllElements(); !subIterator.end(); subIterator.nextElement()) {
        const char * nodeId = subIterator.getKey();
        if (pNodesTable->get (nodeId) != NULL) {
            SubscriptionList *pSubs = subIterator.getValue();
            RemoteNodeInfo * pRNI = (RemoteNodeInfo*) retrieveNodeInfo (nodeId);
            if (pRNI == NULL) {
                _m.unlock (131);
                return 0;
            }
            // Add subscriptions to pRNI
            for (StringHashtable<Subscription>::Iterator i = pSubs->getIterator(); !i.end(); i.nextElement()) {
                Subscription *pSub = i.getValue();
                Subscription *pSubAux = pSub->clone();
                pRNI->subscribe(i.getKey(), pSubAux);
            }
            SubscriptionList *pSubscriptions =  pRNI->getRemoteSubscriptionsCopy();
            sendSubscriptionStateMsg (pSubscriptions, nodeId, pNodesTable->get (nodeId));
        }
    }
    delete pSubscriptionsTable;
    pSubscriptionsTable = NULL;
    delete pNodesTable;
    pNodesTable = NULL;
    _m.unlock (131);
    return 0;
}
int TopologyWorldState::printWorldStateInfo (void) 
{
    // Prints information about local node, like subscriptions, alive neighbors, dead peers, etc
    _m.lock (141);
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "=========================================================================\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     PRINT WORLD STATE INFO\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     Node id: %s\n", _pDisService->getNodeId());
    if ((_pLocalNodeInfo->getConsolidatedSubscriptions())->getCount() == 0) {
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     No subscribed groups\n");
    } else {
        _pLocalNodeInfo->printAllSubscribedGroups();
        // Print subscribing clients
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUBSCRIBING CLIENTS:\n");
        DArray<uint16> *pSubClients = _pLocalNodeInfo->getAllSubscribingClients();
        for (int j = 0; j <= pSubClients->getHighestIndex(); j++) {
            checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUB CLIENT N.%d:\n", (*pSubClients)[j]);
            SubscriptionList *pSubsForClient = _pLocalNodeInfo->getSubscriptionListForClient ((*pSubClients)[j]);
            _pLocalNodeInfo->releaseLocalNodeInfo();
            if (pSubsForClient && pSubsForClient->getCount() != 0) {
                for (StringHashtable<Subscription>::Iterator i = pSubsForClient->getIterator(); !i.end(); i.nextElement()) {
                    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUBSCRIPTION:\n");
                    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     groupname %s\n", i.getKey());
                    Subscription *pS = i.getValue();
                    pS->printInfo();                
                }
            }
        }
        // Print local consolidated subscriptions
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     LOCAL CONSOLIDATED SUBSCRIPTIONS:\n");
        SubscriptionList *pSubscriptions = _pLocalNodeInfo->getConsolidatedSubscriptions();
        for (StringHashtable<Subscription>::Iterator i = pSubscriptions->getIterator(); !i.end(); i.nextElement()) {
            checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     SUBSCRIPTION:\n");
            checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     groupname %s\n", i.getKey());
            Subscription *pS = i.getValue();
            pS->printInfo();   
        }
    }
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     %d ACTIVE NEIGHBORS\n", _pLocalNodeInfo->getCount());
    for (StringHashtable<Thing>::Iterator iNeighbors = _pLocalNodeInfo->getAllElements(); !iNeighbors.end(); iNeighbors.nextElement()) {
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
        RemoteNodeInfo *pRNI = (RemoteNodeInfo *) iNeighbors.getValue();
        pRNI->printRemoteNodeInfo();
    }
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "     %d DEAD PEERS\n", _deadPeers.getCount());
    for (StringHashtable<RemoteNodeInfo>::Iterator iDead = _deadPeers.getAllElements(); !iDead.end(); iDead.nextElement()) {
        checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n");
        RemoteNodeInfo *pRNI = (RemoteNodeInfo *) iDead.getValue();
        pRNI->printRemoteNodeInfo();
    }
    checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "=========================================================================\n");
    _m.unlock (141);
    return 0;
}
Example #9
0
int LocalNodeInfo::addHistoryInternal (uint16 ui16ClientId, const char *pszGroupName, History *pHistory)
{
    Subscription *pSubscription = getSubscriptionForClient (ui16ClientId, pszGroupName);
    if (pSubscription == NULL) {
        return -1;
    }
    if (pSubscription->getSubscriptionType() != Subscription::GROUP_SUBSCRIPTION) {
        return -2;
    }
   return pSubscription->addHistory (pHistory);
}
Example #10
0
int main(int argc, char* argv[])
{
    SetupNames();
    try
    {
        Environment::Initialize(Environment::Events);

        Connection con("db", "usr", "pwd");
        con.SetAutoCommit(true);

        Statement st(con);
        st.Execute("create table table1(code number)");
        st.Execute("create table table2(str varchar2(10))");

        Subscription sub;
        sub.Register(con, "sub-00", Subscription::AllChanges, EventHandler, 5468, 0);
        sub.Watch("select * from table1");
        sub.Watch("select * from table2");

        st.Execute("alter table table1 add price number");
        WaitForEvents();

        st.Execute("insert into table1 values(1, 10.5)");
        st.Execute("insert into table2 values('shoes')");
        WaitForEvents();

        st.Execute("update table1 set price = 13.5 where code = 1");
        st.Execute("delete from table2 ");
        WaitForEvents();

        st.Execute("drop table table1");
        st.Execute("drop table table2");
        WaitForEvents();

        con.Close();

        /* start remote instance */
        Environment::StartDatabase("db", "sys_usr", "sys_pwd", Environment::StartForce, Environment::StartFull);

        /* shutdown remote instance */
        Environment::ShutdownDatabase("db", "sys_usr", "sys_pwd", Environment::ShutdownAbort, Environment::ShutdownFull);
        WaitForDatabase();

        sub.Unregister();

    }
    catch (std::exception &ex)
    {
        std::cout << ex.what() << std::endl;
    }

    Environment::Cleanup();
}
void usubRequest::operator()(const SubscriptionLib::UsubRequest& req){
	  UserConnection * user = Users::getInstance()->getUser(req.getLogin());
	  Subscription * subs = SubList::getInstance()->getSubscription(req.getSubId());
	  if(user!=NULL && subs!=NULL &&socket_==user->getsocket() && user->isContainsSubject(subs)){
	      		user->removeSubject(subs);
	      		subs->removeObserver(user);
	      		SubscriptionLib::UsubResponse response(0, std::string("USubs operation was succeed"));
	      		MsgSender::deliver(response, user->getsocket());
	  }else{;
		  SubscriptionLib::UsubResponse response(1, std::string("User is not authorized |subscription with specified id is not exist | user is not subscribe this subscription"));
		  MsgSender::deliver(response, socket_);
	  }
}
Example #12
0
int LocalNodeInfo::unsubscribe (uint16 ui16ClientId, const char *pszGroupName, uint16 ui16Tag)
{
    char *pszOnDemandDataGroupName = getOnDemandDataGroupName (pszGroupName);
    if (pszOnDemandDataGroupName == NULL) {
        // The on-demand subscription group name could not be generated
        return -1;
    }
    _m.lock (306);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    int rc = 0;
    if (pSL == NULL) {
        rc = -2;
    }
    else {
        Subscription *pSub = pSL->getSubscription (pszGroupName);
        if (pSub == NULL) {
            rc = -3;
        }
        else {
            uint8 ui8SubscriptionType = pSub->getSubscriptionType();
            if ((ui8SubscriptionType == Subscription::GROUP_SUBSCRIPTION) && (ui16Tag == 0)) {
                if (pSL->removeGroup (pszGroupName)) {
                    rc = -4;
                }
                else {
                    if (pSL->removeGroup (pszOnDemandDataGroupName)) {
                        rc = -5;
                    }
                }
            }
            else if ((ui8SubscriptionType == Subscription::GROUP_TAG_SUBSCRIPTION) && (ui16Tag != 0)) {
                if (pSL->removeGroupTag (pszGroupName, ui16Tag)) {
                    rc = -6;
                }
                else {
                    if (pSL->removeGroupTag (pszOnDemandDataGroupName, ui16Tag)) {
                        rc = -7;
                    }
                }
            }
        }
    }
    if (rc == 0) {
        recomputeConsolidateSubsciptionList ();
    }
    free (pszOnDemandDataGroupName);
    _m.unlock (306);
    return rc;
}
Example #13
0
  void RosterManager::handleSubscription( const Subscription& s10n )
  {
    if( !m_rosterListener )
      return;

    switch( s10n.subtype() )
    {
      case Subscription::Subscribe:
      {
        bool answer = m_rosterListener->handleSubscriptionRequest( s10n.from(), s10n.status() );
        if( m_syncSubscribeReq )
        {
          ackSubscriptionRequest( s10n.from(), answer );
        }
        break;
      }
      case Subscription::Subscribed:
      {
//         Subscription p( Subscription::Subscribe, s10n.from().bareJID() );
//         m_parent->send( p );

        m_rosterListener->handleItemSubscribed( s10n.from() );
        break;
      }

      case Subscription::Unsubscribe:
      {
        Subscription p( Subscription::Unsubscribed, s10n.from().bareJID() );
        m_parent->send( p );

        bool answer = m_rosterListener->handleUnsubscriptionRequest( s10n.from(), s10n.status() );
        if( m_syncSubscribeReq && answer )
          remove( s10n.from().bare() );
        break;
      }

      case Subscription::Unsubscribed:
      {
//         Subscription p( Subscription::Unsubscribe, s10n.from().bareJID() );
//         m_parent->send( p );

        m_rosterListener->handleItemUnsubscribed( s10n.from() );
        break;
      }

      default:
        break;
    }
  }
Example #14
0
bool LocalNodeInfo::isInHistory (uint16 ui16ClientId, Message *pMsg, uint32 ui32LatestMsgRcvdPerSender)
{
    _m.lock (312);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL != NULL) {
        Subscription *pS = pSL->getSubscription (pMsg->getMessageInfo()->getGroupName());
        if (pS) {
            bool bRet = pS->isInHistory (pMsg, ui32LatestMsgRcvdPerSender);
            _m.unlock (312);
            return bRet;
        }
    }
    _m.unlock (312);
    return false;
}
Example #15
0
int SubscribeDB::getMaxVersion(const UtlString& uri) const
{
    mongo::BSONObj query = BSON(Subscription::uri_fld() << uri.str());
    mongo::ScopedDbConnection conn(_info.getConnectionString());
    auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query);
    unsigned int value = 0;
    while (pCursor.get() && pCursor->more())
    {
        Subscription row = pCursor->next();
        if (value < row.version())
            value = row.version();
    }
    conn.done();
    return value;
}
Example #16
0
int LocalNodeInfo::addHistory (uint16 ui16ClientId, const char *pszGroupName, uint8 ui8PredicateType, const char *pszPredicate, History *pHistory)
{
    _m.lock (309);
    Subscription *pSubscription = getSubscriptionForClient (ui16ClientId, pszGroupName);
    if (pSubscription == NULL) {
        _m.unlock (309);
        return -1;
    }
    if (pSubscription->getSubscriptionType() != Subscription::GROUP_PREDICATE_SUBSCRIPTION) {
        _m.unlock (309);
        return -2;
    }
    int rc = pSubscription->addHistory (pHistory);
    _m.unlock (309);
    return rc;
}
Example #17
0
    // Get information about the subscription
    // =============================================================================================
    Status SubscriptionFactory::subscriptionInformation(
            ClientSubscriptionHandle    clientSubscriptionHandle,
            SubscriptionInformation&    subscriptionInformation)
    {
        Status ret;

        Subscription* subscription = 0;
        ret = acquireExistingSubscription(clientSubscriptionHandle, subscription);

        if (ret.isGood())
        {
            subscriptionInformation = subscription->subscriptionInformation();
            releaseSubscription(subscription);
        }

        return ret;
    }
Example #18
0
void Receiver::received(Message& message)
{
    if (!(skipDups && isDuplicate(message))) {
        bool eos = message.getData() == EOS;
        if (!eos) std::cout << message.getData() << std::endl;
        if (eos || ++processed == count) subscription.cancel();
    }
}
Example #19
0
int LocalNodeInfo::addFilter (uint16 ui16ClientId, const char *pszGroupName, uint16 ui16Tag)
{
    _m.lock (301);
    SubscriptionList *pSL = _localSubscriptions.get (ui16ClientId);
    if (pSL == NULL) {
        _m.unlock (301);
        return -1;
    }
    if (pSL->addFilterToGroup (pszGroupName, ui16Tag) != 0) {
        _m.unlock (301);
        return -2;
    }
    bool bAddFilter = true;

    // I can add the filter to the ConsolidatedSubscriptions only if every client subscribing that group has the filter too
    for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) {
        SubscriptionList *pSL = i.getValue();
        Subscription *pS = pSL->getSubscription(pszGroupName);
        switch (pS->getSubscriptionType()) {
            case Subscription::GROUP_SUBSCRIPTION: {
                if (!((GroupSubscription *)pS)->hasFilter(ui16Tag)) {
                    bAddFilter = false;
                    break;
                }
                break;
            }
            case Subscription::GROUP_TAG_SUBSCRIPTION: {
                if (((GroupTagSubscription *)pS)->hasTag(ui16Tag)) {
                    bAddFilter = false;
                    break;
                }
                break;
            }
            case Subscription::GROUP_PREDICATE_SUBSCRIPTION :
                 bAddFilter = false;
                 break;
        }
    }
    if (bAddFilter) {
        _consolidatedSubscriptions.addFilterToGroup (pszGroupName, ui16Tag);
    }

    _m.unlock (301);
    return 0;
}
std::vector<unsigned char> aggregator_solver::makeSubscribeReqMsg(Subscription& rules) {
  //The total length starts out at one for the message type field.
  //Each rule will add additional length.
  uint32_t total_length = 1;

  std::vector<unsigned char> buff;

  buff.push_back(0);
  buff.push_back(0);
  buff.push_back(0);
  buff.push_back(0);
  buff.push_back((unsigned char)subscription_request);

  //Push back the rules
  {
    //First push the number of rules onto the buffer
    uint32_t num_rules = rules.size();
    total_length += pushBackVal(num_rules, buff);

    //For each rule push back the physical layer, the number of
    //tx rules and the tx rules, the number of boxes and the boxes,
    //and the number of FSM/TR rules and the FSM/TR rules.
    for (auto rule = rules.begin(); rule != rules.end(); ++rule) {
      //Push the physical layer
      total_length += pushBackVal(rule->physical_layer, buff);

      //Push the transmitter information
      uint32_t num_txers = rule->txers.size();
      total_length += pushBackVal(num_txers, buff);
      //Each transmitter is made of an ID and a MASK
      for (auto txer = rule->txers.begin(); txer != rule->txers.end(); ++txer) {
        total_length += pushBackVal(txer->base_id, buff);
        total_length += pushBackVal(txer->mask, buff);
      }

      //Finish the rule with the update interval
      total_length += pushBackVal(rule->update_interval, buff);
    }
  }

  //Store the message length in the first four bytes
  pushBackVal<uint32_t>(total_length, buff, 0);

  return buff;
}
Example #21
0
bool RemoteNodeInfo::isNodeInterested (DisServiceDataMsg *pDSDMsg)
{
    // Returns true if the node is interested in pDSDMsg
    bool bFound = false;
    const char * pszMsgGroupName = pDSDMsg->getMessageHeader()->getGroupName();
    if (_pRemoteSubscriptions) {
        for (StringHashtable<Subscription>::Iterator i = _pRemoteSubscriptions->getIterator(); !i.end(); i.nextElement()) {
            const char *pszSubGroupName = i.getKey();
            if (0 == stricmp (pszSubGroupName, pszMsgGroupName)) {
                Subscription *pSub = i.getValue();
                if ((pSub->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) || pSub->matches(pDSDMsg->getMessage())) {
                    bFound = true;
                }
            }
        }
    }
    return bFound;
}
Example #22
0
 void receivedFromControl(Message& message)
 {
     if (message.getData() == "transfer") {
         source = message.getHeaders().getAsString("src");
         destination = message.getHeaders().getAsString("dest");
         expected = message.getHeaders().getAsInt("count");
         transfered = 0;
         QPID_LOG(info, "received transfer request: " << expected << " messages to be shifted from " <<
                  source << " to " << destination);
         subscribeToSource(controlSubscription.getSubscriptionManager());
     } else if (message.getData() == "quit") {
         QPID_LOG(info, "received quit request");
         controlSubscription.cancel();
     } else {
         std::cerr << "Rejecting invalid message: " << message.getData() << std::endl;
         controlSubscription.getSession().messageReject(SequenceSet(message.getId()));
     }
 }
Example #23
0
void Listener::received(Message & message)
{
    if (message.getData() == "That's all, folks!")
    {
        done = true;
        if(verbosity > 0 )
        {
            cout << "Shutting down listener for "
                      << message.getDestination() << endl;

            cout << "Listener received "
                      << count
                      << " messages ("
                      << received_twice.size()
                      << " received_twice)"
                      << endl;
            
        }
        subscription.cancel();
        if ( verbosity > 0 )
          cout << "LISTENER COMPLETED\n";
        
        if ( ! gaps ) {
          cout << "no gaps were detected\n";
          cout << received_twice.size() << " messages were received twice.\n";
        }
        else {
            cout << "gaps detected\n";
            for ( unsigned int i = 0; i < received_twice.size(); ++ i )
              cout << "received_twice "
                        << received_twice[i]
                        << endl;
        }
    } else {
        uint sn = message.getHeaders().getAsInt("sn");
        if (lastSn < sn) {
            if (sn - lastSn > 1) {
                cerr << "Error: gap in sequence between " << lastSn << " and " << sn << endl;
                gaps = true;
            }
            lastSn = sn;
            ++count;
            if ( ! ( count % reportFrequency ) ) {
                if ( verbosity > 0 )
                    cout << "Listener has received "
                              << count
                              << " messages on queue "
                              << queueName
                              << endl;
            }
        } else {
            received_twice.push_back ( sn );
        }
    }
}
Example #24
0
bool LocalNodeInfo::requireSequentiality (const char *pszGroupName, uint16 ui16Tag)
{
    _m.lock (321);
    PtrLList<Subscription> *pSubscriptions = _consolidatedSubscriptions.getSubscriptionWild(pszGroupName);
    if (pSubscriptions != NULL) {
        for (Subscription *pSub = pSubscriptions->getFirst(); pSub != NULL; pSub = pSubscriptions->getNext()) {
            if (pSub->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION) {
                GroupSubscription *pGS = (GroupSubscription *) pSub;
                if (pGS->isSequenced()) {
                    delete pSubscriptions;
                    pSubscriptions = NULL;
                    _m.unlock (321);
                    return true;
                }
            }
            else if (pSub->getSubscriptionType() == Subscription::GROUP_TAG_SUBSCRIPTION) {
                GroupTagSubscription *pGTS = (GroupTagSubscription *) pSub;
                if (pGTS->isSequenced(ui16Tag)) {
                    delete pSubscriptions;
                    pSubscriptions = NULL;
                    _m.unlock (321);
                    return true;
                }
            }
            else if (pSub->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) {
                GroupPredicateSubscription *pGPS = (GroupPredicateSubscription *) pSub;
                if (pGPS->isSequenced()) {
                    delete pSubscriptions;
                    pSubscriptions = NULL;
                    _m.unlock (321);
                    return true;
                }
            }
        }

        delete pSubscriptions;
        pSubscriptions = NULL;
    }

    _m.unlock (321);
    return false;
}
Example #25
0
    // implemented from callback interface
    // =============================================================================================
    void SubscriptionFactory::subscriptionStatusChanged(
                    OpcUa_UInt32    clientSubscriptionHandle,
                    const UaStatus& uaStatus)
    {
        logger_->debug("Subscription status for clientSubscriptionHandle %d has changed: %s",
                clientSubscriptionHandle, uaStatus.toString().toUtf8());

        // acquire the subscription for which the event was meant:
        Subscription* subscription = 0;
        Status acquireStatus = acquireExistingSubscription(clientSubscriptionHandle, subscription);

        if (acquireStatus.isGood())
        {
            // update the session state
            subscription->setSubscriptionState(uaf::subscriptionstates::toUaf(uaStatus));

            // release the acquired session
            releaseSubscription(subscription);
        }
    }
Example #26
0
bool SubscribeDB::findFromAndTo(
   const UtlString& callid,
   const UtlString& fromtag,
   const UtlString& totag,
   UtlString& from,
   UtlString& to) const
{
    mongo::BSONObj query = BSON(Subscription::callId_fld() << callid.str());
    mongo::ScopedDbConnection conn(_info.getConnectionString());
    auto_ptr<mongo::DBClientCursor> pCursor = conn->query(_info.getNS(), query);
    while (pCursor.get() && pCursor->more())
    {
        Subscription row = pCursor->next();
        UtlBoolean r;
        UtlString seen_tag;

        // Get the tag on the URI in the "from" column.
        Url fromUri(row.fromUri().c_str(), FALSE);
        r = fromUri.getFieldParameter("tag", seen_tag);

        // If it matches...
        if (r && seen_tag.compareTo(fromtag) == 0)
        {
           // Get the tag on the URI in the "to" column.
           Url toUri(row.toUri().c_str(), FALSE);
           r = toUri.getFieldParameter("tag", seen_tag);

           // If it matches...
           if (r && seen_tag.compareTo(totag) == 0)
           {
              // We have found a match.  Record the full URIs.
              from = row.fromUri().c_str();
              to = row.toUri().c_str();
              conn.done();
              return true;
           }
        }
    }
    conn.done();
    return false;
}
Example #27
0
    // implemented from callback interface
    // =============================================================================================
    void SubscriptionFactory::keepAlive(OpcUa_UInt32 clientSubscriptionHandle)
    {
        logger_->debug("Subscription %d received a keep alive message", clientSubscriptionHandle);

        // acquire the subscription for which the event was meant:
        Subscription* subscription = 0;
        Status acquireStatus = acquireExistingSubscription(clientSubscriptionHandle, subscription);

        if (acquireStatus.isGood())
        {
            // update the session state
            subscription->keepAlive();

            // release the acquired session
            releaseSubscription(subscription);
        }
        else
        {
            logger_->warning("Unknown ClientSubscriptionHandle, discarding notification!");
        }
    }
Example #28
0
    // Manual unsubscription
    //==============================================================================================
    Status SubscriptionFactory::manuallyUnsubscribe(
            ClientSubscriptionHandle clientSubscriptionHandle)
    {
        Status ret;
        Subscription* subscription = 0;

        ret = acquireExistingSubscription(clientSubscriptionHandle, subscription);

        if (ret.isGood())
        {
            ret = subscription->deleteSubscription();
            releaseSubscription(subscription);
        }
        else
        {
            ret.addDiagnostic("Could not manually unsubscribe");
            logger_->error(ret);
        }

        return ret;
    }
Example #29
0
void LocalNodeInfo::addAddFiltersToConsolidateList (const char *pszGroupName)
{
    _m.lock (328);
    // Get all the client subscribing the group
    DArray<uint16> *pSubClients = NULL;//getSubscribingClients (pszGroupName);
    Subscription *pSCons = _consolidatedSubscriptions.getSubscription (pszGroupName);
    if ((pSubClients == NULL) ||  (!((pSCons != NULL) && (pSCons->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION)))) {
        _m.unlock (328);
        return;
    }
    GroupSubscription *pGSCons = (GroupSubscription *) pSCons;

    // Look for the first subscribing client which subscribes by a GROUP_SUBSCRIPTION
    uint16 ui16ClientId;
    Subscription *pS = NULL;
    for (int i = 0; i <= pSubClients->getHighestIndex(); i++) {
        ui16ClientId = (*pSubClients)[i];
        SubscriptionList *pSL = NULL;
        if (((pSL = _localSubscriptions.get(ui16ClientId)) != NULL) && ((pS = pSL->getSubscription(pszGroupName)) != NULL)) {
            if (pS->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION) {
                break;
            }
            if (pS->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) {
                // I want every tag - remove them and return
                pGSCons->removeAllFilters();
                _m.unlock (328);
                return;
            }
        }
    }

    // match every filter against every other subscribing client's tag list.
    // Add it iff:
    // 1) Every other GROUP_SUBSCRIPTION has the same filter
    // 2) No one of the other GROUP_TAG_SUBSCRIPTION subscribe the tag
    // 3) There is not any GROUP_PREDICATE_SUBSCRIPTION for the group
    GroupSubscription *pGS = (GroupSubscription*) pS;
    DArray<uint16> *pTags = pGS->getAllFilters();

    for (int i = 0; i <= pTags->getHighestIndex(); i++) {
        bool bAddFilter = true;
        int16 ui16Tag = (*pTags)[i];
        for (int j = 0; j <= pSubClients->getHighestIndex(); j++) {
            Subscription *pS = NULL;
            if (pS->matches(ui16Tag)) {
                bAddFilter = false;
                break;
            }
        }
        if (bAddFilter) {
            pGSCons->addFilter((*pTags)[i]);
        }
    }
    _m.unlock (328);
}
Example #30
0
void AppCustomer::parseResponse() {
  if (responseParser->hasName("created")) {
  created = responseParser->getDateByName("created");
  }
  if (responseParser->hasName("modified")) {
  modified = responseParser->getDateByName("modified");
  }
  if (responseParser->hasName("nick")) {
  nick = responseParser->getStrByName("nick");
  }
  if (responseParser->hasName("status")) {
  status = responseParser->getStrByName("status");
  }
  if (responseParser->hasName("subscriptions")) {
  QList<Parser *> listParser = responseParser->getListObjectParser("subscriptions");
  Parser *parser;
  foreach (parser, listParser) {
    Subscription tmp;
    tmp.setParser(parser);
    tmp.parseResponse();
    subscriptions.append(tmp);
  }