1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef INTEROP_CALLBACK_RESOURCE_H 17 #define INTEROP_CALLBACK_RESOURCE_H 18 19 #include <vector> 20 #include "interop-types.h" 21 22 // NOLINTBEGIN 23 24 class CallbackResourceHolder { 25 private: 26 std::vector<InteropCallbackResource> heldResources; 27 28 public: holdCallbackResource(const InteropCallbackResource * resource)29 void holdCallbackResource(const InteropCallbackResource *resource) 30 { 31 resource->hold(resource->resourceId); 32 this->heldResources.push_back(*resource); 33 } release()34 void release() 35 { 36 for (auto resource : this->heldResources) { 37 resource.release(resource.resourceId); 38 } 39 this->heldResources.clear(); 40 } 41 }; 42 43 struct CallbackBuffer { 44 InteropInt32 kind; 45 uint8_t buffer[60 * 4]; 46 CallbackResourceHolder resourceHolder; 47 }; 48 49 enum CallbackEventKind { 50 EVENT_CALL_CALLBACK = 0, 51 EVENT_HOLD_MANAGED_RESOURCE = 1, 52 EVENT_RELEASE_MANAGED_RESOURCE = 2, 53 }; 54 55 // CC-OFFNXT(G.NAM.01) false positive 56 void EnqueueCallback(const CallbackBuffer *event); 57 // CC-OFFNXT(G.NAM.01) false positive 58 void HoldManagedCallbackResource(InteropInt32 resourceId); 59 // CC-OFFNXT(G.NAM.01) false positive 60 void ReleaseManagedCallbackResource(InteropInt32 resourceId); 61 62 // NOLINTEND 63 64 #endif 65