पक्का करें कि आपकी VSIDL कैटलॉग डायरेक्ट्री में, ज़रूरी बिल्ड, protobuf, और VSIDL फ़ाइलें हों. मौजूदा सैंपल से शुरू करने के लिए, आपको
/system/software_defined_vehicle/samples/vsidl/stable/catalogमें, मान्य कैटलॉग फ़ोल्डर का एक उदाहरण मिल सकता है.कैटलॉग का सैंपल स्ट्रक्चर:
my_catalog/ ├── Android.bp # Defines rust_protobuf modules for .proto files ├── types.proto # Protobuf message / RPC service definitions └── architecture.vsidl # VSIDL service bundle definitionsअपने कारोबार के लॉजिक को लागू करने के लिए, ज़रूरत के हिसाब से कोड लिखें:
- RPC सर्वर:
lib.rsसे trait लागू करें. पब्लिश और सब्सक्राइब करने वाले और आरपीसी क्लाइंट: अन्य सेवाओं के साथ इंटरैक्ट करने के लिए,
service_bundle.rsमें जनरेट किए गए फ़ंक्शन कॉल करें.
रस्ट
स्केलेटन लागू करने के लिए, यह कमांड चलाएं:
vsidlc -c /path/to/catalog -o /path/to/output --services--servicesफ़्लैग के साथvsidlcचलाने पर, हर सर्विस बंडल के लिए बॉयलरप्लेट रस्ट लागू होता है. इससे ज़रूरी स्कैफ़ोल्डिंग मिलती है. इसमें सोर्स कोड (main.rs) और सभी डिपेंडेंसी के साथ बिल्ड कॉन्फ़िगरेशन फ़ाइल (Android.bp) शामिल होती है. इससे, मुख्य कारोबारी लॉजिक को लागू करने पर ध्यान देने के दौरान, डिफ़ॉल्ट मैसेज तुरंत भेजे जा सकते हैं.हर सर्विस बंडल के लिए, रस्ट का लागू होना यहां देखें:
/path/to/output/services/ServiceBundleName/src/main.rs.डिफ़ॉल्ट रूप से, जनरेट किया गया लागू करने का तरीका, डिफ़ॉल्ट वैल्यू वाले मैसेज बनाता है और उन्हें पब्लिशर और सब्सक्राइबर या आरपीसी क्लाइंट और सर्वर के बीच भेजता है. इस व्यवहार में बदलाव करने के लिए,
main.rsमेंTODOटिप्पणियां ढूंढें और उन्हें अपनी प्राथमिकताओं के हिसाब से अडजस्ट करें. उदाहरण के लिए:async fn handle_tire_pressure_range_unique_publisher( publisher: sdv::mw::Publisher<TirePressureRange>, ) { loop { // TODO: Modify the frequency of publishing messages here. sleep(Duration::from_secs(1)).await; // TODO: Modify the message content here. let message = TirePressureRange::default(); info!("Publishing on TirePressureRange#UNIQUE"); publisher.publish(&message).unwrap(); } }vsidlcके अगली बार चलने पर, जनरेट की गई फ़ाइलों में किए गए आपके बदलाव ओवरराइट न हों, इसके लिएservicesफ़ोल्डर को/path/to/outputफ़ोल्डर से बाहर ले जाएं.
C++
अपने सर्विस बंडल के लिए, क्लास के साथ एक नई हेडर फ़ाइल,
src/lib.hpp, बनाएं:#pragma once #include <sdv/service_bundle.h> #include <sdv/context.hpp> namespace com::sdv::oem::service_bundle { // Sample implementation of the service bundle interface. class ServiceBundleName : public android::sdv::service_bundle::ServiceBundle { public: ServiceBundleName(sdv_comms::ctx::Context context); ~ServiceBundleName(); void onStart() override; void onStop() override; }; } // namespace com::sdv::oem::service_bundleक्लास को लागू करने के लिए, एक नई सोर्स फ़ाइल,
src/lib.cpp, बनाएं:#include "src/lib.hpp" #include <sdv/sb_macro.h> #include <iostream> using com::sdv::oem::service_bundle::ServiceBundleName; // Register the new service bundle. REGISTER_SERVICE_BUNDLE(ServiceBundleName); // Sample implementation of the service bundle interface. namespace com::sdv::oem::service_bundle { // Creates a new instance of the ServiceBundleName. // Called when service bundle is created by the system. // Context object is provided as a parameter that gives access to the // communication stack APIs. ServiceBundleName::ServiceBundleName([[maybe_unused]] sdv_comms::ctx::Context context) : ServiceBundle(context) { // Memory allocations and static data loading should be done as // part of this method. // // Loading of the dynamic resources (sockets, files, etc) // is strongly discouraged due to possible Suspend-to-RAM scenario. // // The dynamic data can be loaded in the onStart method. } // Called when the service bundle is started by the system. void ServiceBundleName::onStart() { // Dynamic resources(sockets, files, etc) should be allocated during this call. } // Called when the service bundle is stopped by the system in preparation // for shutdown or suspend to RAM/Disc. void ServiceBundleName::onStop() { // Stop phase requires the service bundle to delete the dynamic resources // (sockets, files, etc) that were previously allocated in the onStart method. } // Called when the service bundle is destroyed by the system. ServiceBundleName::~ServiceBundleName() { // Static resources deallocation needs to be implemented in the destructor. } } // namespace com::sdv::oem::service_bundleनई या मौजूदा
Android.bpफ़ाइल में, सर्विस बंडल लाइब्रेरी का Soong टारगेट बनाएं:// Service bundle library. cc_library_shared { name: "libservice_bundle", srcs: ["src/lib.cpp",], // Allows the library to be available inside APEX. apex_available: [ "//apex_available:platform", "//apex_available:anyapex", ], shared_libs: [ // Service Bundle lifecycle C++ API. "libsdv_lifecycle_client_cpp", // commstack library that provides context object reference "libsdv_comms_cpp", ], // Service bundle package is packed into /product apexes. product_specific: true, }
- RPC सर्वर:
अगला कदम क्या है
अपने सर्विस बंडल को डिप्लॉय करने के लिए, सर्विस बंडल बनाना और डिप्लॉय करना लेख पढ़ें.