Example #1
0
void commandContainerCleanup(CommandContainer commandContainer){
	CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
        lockLock(internal->lock);
        time_t currentTime;       // Stores seconds elapsed since 01-01-1970
        time(&currentTime);
        // Cleanup atomic commands
        if(linkedListSize(internal->atomicCommands)>0){
            int length=linkedListSize(internal->atomicCommands);
            Command atomicCommand;
            while(length>0){
                 linkedListGetFirst(internal->atomicCommands,(Object*)&atomicCommand);
                 int commandTime=commandGetInt(atomicCommand,SERVER_HANDLING_TIME);
                 int distributed=commandGetInt(atomicCommand,DISTRIBUTED);
                 if((currentTime-commandTime>MAX_TIME_TO_HOLD_COMMAND&&distributed==TRUE)||(currentTime-commandTime>MAX_TIME_TO_HOLD_UNCLEANED_COMMAND)){
                   commandFree(atomicCommand);
                   linkedListRemoveFirst(internal->atomicCommands);
                 }else{
                     break;
                 }
                 length=linkedListSize(internal->atomicCommands);
            }
        }
        
        // Cleanup commands
        int length=linkedListSize(internal->versions);
        int i;
        int* intBuffer;
        while(length>0){
            linkedListGetFirst(internal->versions,(Object*)&intBuffer);
            Command temp;
            hashmapGet(internal->versionMap,*intBuffer,(Object*)&temp);
            int commandTime=commandGetInt(temp,SERVER_HANDLING_TIME);            
            int persisted=commandGetInt(temp,PERSISTED);
            int distributed=commandGetInt(temp,DISTRIBUTED);
            if((currentTime-commandTime>MAX_TIME_TO_HOLD_COMMAND&&persisted==TRUE&&distributed==TRUE)||(currentTime-commandTime>MAX_TIME_TO_HOLD_UNCLEANED_COMMAND)){
                linkedListRemoveFirst(internal->versions);
                hashmapRemove(internal->versionMap,*intBuffer);
                memoryFree(intBuffer);
                commandFree(temp);
            }else{
                break;
            }
            length=linkedListSize(internal->versions);
        }
        lockUnlock(internal->lock);
        
        

}
Example #2
0
void commandContainerRevertCommand(CommandContainer commandContainer,int lastVersion){
    CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
    lockLock(internal->lock);
    int* intBuffer=NULL;
    linkedListGetLast(internal->versions,(Object*)&intBuffer);
    while(intBuffer!=NULL&&lastVersion<=*intBuffer){
        linkedListRemoveLast(internal->versions);
        Command temp;
        hashmapGet(internal->versionMap,*intBuffer,(Object*)&temp);
        hashmapRemove(internal->versionMap,*intBuffer);
        linkedListGetLast(internal->versions,(Object*)&intBuffer);
    }
    lockUnlock(internal->lock);
   
}
Example #3
0
void commandContainerPushCommand(CommandContainer commandContainer,Command command){
	CommandContainerInternal* internal=(CommandContainerInternal*)commandContainer;
        lockLock(internal->lock);
        time_t currentTime;       // Stores seconds elapsed since 01-01-1970
        time(&currentTime);
        int type=commandGetInt(command,COMMAND_TYPE);
        if(type==ATOMIC_MODEL_COMMAND){
            commandPush(command,SERVER_HANDLING_TIME,INTEGER,&currentTime);
            linkedListAddLast(internal->atomicCommands,command);
        }else{
            int version=commandGetInt(command,VERSION);
            int* intBuffer=memoryAlloc(SIZE_OF_INT);
            memcpy(intBuffer,&version,SIZE_OF_INT);
            commandPush(command,SERVER_HANDLING_TIME,INTEGER,&currentTime);
            // Update version Map;
            hashmapPut(internal->versionMap,version,command);
            // Update version list
            linkedListAddLast(internal->versions,intBuffer);
        }
        
        lockUnlock(internal->lock);
}
    bool ISO7816ReaderUnit::reconnect(int action)
    {
        try
        {
            auto chip = getSingleChip();
            if (chip
                && chip->getGenericCardType() == CHIP_SAM)
            {
                std::this_thread::sleep_for(std::chrono::milliseconds(200));

                auto command = std::dynamic_pointer_cast<logicalaccess::SAMCommands<logicalaccess::KeyEntryAV2Information, logicalaccess::SETAV2 >>(chip->getCommands());
                if (command)
                    command->lockUnlock(getISO7816Configuration()->getSAMUnLockKey(), logicalaccess::SAMLockUnlock::Unlock, 0, 0, 0);
            }
        }
        catch (std::exception& ex)
        {
            LOG(ERRORS) << "ISO7816ReaderUnit reconnect: " << ex.what();
            return false;
        }

        return true;
    }