Example #1
0
err_code_t Client::touch(const char* const* keys, const size_t* keyLens,
                   const exptime_t exptime, const bool noreply, size_t nItems,
                   message_result_t*** results, size_t* nResults) {
  dispatchTouch(keys, keyLens, exptime, noreply, nItems);
  err_code_t rv = waitPoll();
  collectMessageResult(results, nResults);
  return rv;
}
Example #2
0
bool TouchPool::handleTouch(TouchTrigger::TouchAction action,int num,intptr_t ids[],float xs[],float ys[])
{
    intptr_t id = 0;
    float x = 0.0f;
    float y = 0.0f;
    int unusedIndex = 0;
    TouchTrigger touchTrigger;

    for(int i=0;i<num;i++)
    {
        id = ids[i];
        x = xs[i];
        y = ys[i];


        auto iter = _touchIdReorderMap.find(id);

        // it is a new touch
        if (iter == _touchIdReorderMap.end())
        {
             if(action != TouchTrigger::TouchAction::DOWN)
             {
                 FKLOG("if the index doesn't exist, it is an error");
                 continue;
             }

            FKLOG("id = %ld",(long int) id);
            unusedIndex = getUnUsedIndex();

             // The touches is more than MAX_TOUCHES ?
             if (unusedIndex == -1) {
                   FKLOG("The touches is more than MAX_TOUCHES, unusedIndex = %d", unusedIndex);
                   continue;
             }

             Touch* touch = _touches[unusedIndex] = new (std::nothrow) Touch();
             touch->setTouchInfo(unusedIndex, x, y);

             FKLOG("x = %f y = %f", touch->getLocationInView().x, touch->getLocationInView().y);

             _touchIdReorderMap.insert(std::make_pair(id, unusedIndex));
             touchTrigger._touches.push_back(touch);

         }
        else
        {
            FKLOG("unusedindex = %d", iter->second);
            FKLOG("other x = %f y = %f", x, y);
            Touch* touch = _touches[iter->second];
            if (touch)
            {
                  touch->setTouchInfo(iter->second, x, y);

                  touchTrigger._touches.push_back(touch);

                  if(action == TouchTrigger::TouchAction::UP || action == TouchTrigger::TouchAction::CANCEL)
                  {
                      _touches[iter->second] = nullptr;
                      removeUsedIndexBit(iter->second);

                      _touchIdReorderMap.erase(id);

                  }
            }
            else
            {
                // It is error, should return.
                FKLOG("Moving touches with id: %ld error", (long int)id);
                return false;
            }

        }

    }

    if (touchTrigger._touches.size() == 0)
    {
         FKLOG("touches: size = 0");
         return false;
    }

    touchTrigger.setAction(action);
    
    bool result = dispatchTouch(&touchTrigger);
	
    if(action == TouchTrigger::TouchAction::UP || action == TouchTrigger::TouchAction::CANCEL)
    {
        for (auto& touch : touchTrigger._touches)
        {
            // release the touch object.
            touch->release();
        }
    }
    return result;
}