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 23 class CallbackResourceHolder { 24 private: 25 std::vector<InteropCallbackResource> heldResources; 26 public: holdCallbackResource(const InteropCallbackResource * resource)27 void holdCallbackResource(const InteropCallbackResource* resource) { 28 resource->hold(resource->resourceId); 29 this->heldResources.push_back(*resource); 30 } release()31 void release() { 32 for (auto resource : this->heldResources) { 33 resource.release(resource.resourceId); 34 } 35 this->heldResources.clear(); 36 } 37 }; 38 39 struct CallbackBuffer { 40 InteropInt32 kind; 41 uint8_t buffer[60 * 4]; 42 CallbackResourceHolder resourceHolder; 43 }; 44 45 enum CallbackEventKind { 46 Event_CallCallback = 0, 47 Event_HoldManagedResource = 1, 48 Event_ReleaseManagedResource = 2, 49 }; 50 51 void enqueueCallback(const CallbackBuffer* event); 52 void holdManagedCallbackResource(InteropInt32 resourceId); 53 void releaseManagedCallbackResource(InteropInt32 resourceId); 54 55 #endif 56