/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "SharedData.h" #include "ILog.h" #include "ISharedData.h" static bool ObjectCheck(void *object) { if (nullptr == object) { LogError("nullptr object!\n"); return false; } if (*((const char **)(((char *)object) - sizeof(ISharedDataHeader))) != GetSharedDataModuleName()) { LogError("Illegal object!\n"); return false; } return true; } void *CreateSharedData(const enum SHARER_NAME name, const char *path, const int projectId) { std::shared_ptr *sharedDataObject = NewSharedData(name, path, projectId); if (nullptr != sharedDataObject) { // (*sharedDataObject)->OpenConfigFile(); } return sharedDataObject; } const StatusCode IMakeSharedData(void *object, const unsigned int readableSize, const unsigned int writableSize) { if (ObjectCheck(object) == true) { (*(std::shared_ptr *)object)->MakeSharedMemory(readableSize, writableSize); return CreateStatusCode(STATUS_CODE_OK); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } const StatusCode ICleanSharedData(void *object) { if (ObjectCheck(object) == true) { // (*(std::shared_ptr *)object)->MakeSharedMemory(readableSize, writableSize); return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } const StatusCode IGetReadableData(void *object, void *buf, const unsigned int bufLength) { if (ObjectCheck(object) == true) { return (*(std::shared_ptr *)object)->GetReadableMemory(buf, bufLength); } return CreateStatusCode(STATUS_CODE_INVALID_PARAMENTER); } void ISetWritableData(void *object, void *buf, const unsigned int bufLength) { if (ObjectCheck(object) == true) { (*(std::shared_ptr *)object)->SetWritableMemory(buf, bufLength); } } void IShareDataFree(void *object) { if (ObjectCheck(object) == true) { (*(std::shared_ptr *)object)->FreeSharedMemory(); (*(std::shared_ptr *)object).reset(); free(((char *)object) - sizeof(ISharedDataHeader)); } }