Example #1
0
    void NewSerialPort::read(std::vector<char>& aDataBuffer,
                             size_t aNumOfBytesToRead)
    {
#if _WIN32
        size_t numBytesRead = 0;

        aDataBuffer.clear();
        aDataBuffer.assign(aNumOfBytesToRead, '\0');

		BOOL result = ReadFile(
            m_serialPortHandle,
            aDataBuffer.data(),
            aNumOfBytesToRead,
            reinterpret_cast<LPDWORD>(&numBytesRead),
            NULL);

		DWORD error = GetLastError();

        if (!result && GetLastError() != ERROR_IO_PENDING)
        {
            throw unknown_error();
        }
        else if (numBytesRead > 0)
        {
            // For an accurate reading of how many bytes were actually read
            aDataBuffer.resize(numBytesRead);
            storeReadData(aDataBuffer);
			processData();
        }

#endif
    }
Example #2
0
bool storeFileExists(LCStoreRef store, LCTypeRef type, char hash[HASH_LENGTH]) {
  FILE *fp = storeReadData(store, type, hash);
  if (fp) {
    fclose(fp);
    return true;
  } else {
    return false;
  }
}
Example #3
0
void objectCache(LCObjectRef object) {
  if (!object->data) {
    LCContextRef context = objectContext(object);
    if (context) {
      FILE* fp = storeReadData(context->store, objectType(object), _objectHash(object));
      objectDeserialize(object, fp);
      fclose(fp);
    }
  }
}
Example #4
0
static char* test_object_persistence_with_store(LCStoreRef store, char *storeType) {
  LCContextRef context = contextCreate(store, NULL, 0);
  
  mu_assert("contextStringToType", contextStringToType(context, "LCString") == LCTypeString);
  
  char* string = "abcdef";
  LCStringRef test = LCStringCreate(string);
  objectStore(test, context);
  objectDeleteCache(test, context);
  mu_assert("string persistence", LCStringEqualCString(test, string));
  
  char hash[HASH_LENGTH];
  objectHash(test, hash);
  FILE *fd = storeReadData(store, LCTypeString, hash);
  LCStringRef stringFromFile = objectCreateFromFile(context, fd);
  mu_assert("objectCreateFromFile", LCStringEqualCString(stringFromFile, string));

  LCStringRef string1 = LCStringCreate("abc");
  LCStringRef string2 = LCStringCreate("def");
  LCStringRef string3 = LCStringCreate("ghi");
  LCStringRef stringArray[] = {string1, string2, string3};
  LCArrayRef array = LCArrayCreate(stringArray, 3);
  objectStore(array, context);
  objectDeleteCache(array, context);
  LCStringRef *strings = LCArrayObjects(array);
  mu_assert("array persistence", LCStringEqual(string1, strings[0]) && LCStringEqual(string2, strings[1]) &&
            LCStringEqual(string3, strings[2]));
  
  LCKeyValueRef keyValue = LCKeyValueCreate(string1, array);
  objectStore(keyValue, context);
  objectDeleteCache(keyValue, context);
  objectCache(keyValue);
  mu_assert("keyValue persistence", LCStringEqual(LCKeyValueKey(keyValue), string1));
  
  LCArrayRef mArray = LCMutableArrayCreate(stringArray, 3);
  objectStore(mArray, context);
  objectDeleteCache(mArray, context);
  LCMutableArrayAddObject(mArray, string1);
  objectStore(mArray, context);
  objectDeleteCache(mArray, context);
  objectCache(mArray);
  LCStringRef *strings1 = LCMutableArrayObjects(mArray);
  mu_assert("mutable array persistence", LCStringEqual(string1, strings1[0]) && LCStringEqual(string2, strings1[1]) &&
            LCStringEqual(string3, strings1[2]) && LCStringEqual(string1, strings1[3]));
  
  LCMutableArrayAddObject(mArray, LCStringCreate("test1"));
  objectStoreAsComposite(mArray, context);
  objectDeleteCache(mArray, context);
  LCStringRef *strings2 = LCMutableArrayObjects(mArray);
  mu_assert("composite persistence", LCStringEqual(string1, strings2[0]) && LCStringEqual(string2, strings2[1]) &&
            LCStringEqual(string3, strings2[2]) && LCStringEqual(string1, strings2[3]));

  return 0;
}