আপনার বিজনেস লজিক প্রয়োগ করতে এইসব ধাপ অনুসরণ করুন:
আপনার 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আপনার বিজনেস লজিক প্রয়োগ করতে কাস্টম কোড লিখুন।
vsidlcRust-এর জন্য মিডলওয়্যার বাইন্ডিং ও সার্ভিস বান্ডেল স্ক্যাফোল্ডিং (lib.rs,service_bundle.rsওmain.rs) তৈরি করে। আপনি C++-এ সার্ভিস বান্ডেল লিখলে, লাইফসাইকেল (libsdv_lifecycle_client_cpp) ও কমিউনিকেশন (libsdv_comms_cpp) ইন্টারফেস সরাসরি প্রয়োগ করুন:- RPC সার্ভার (Rust):
lib.rsথেকে জেনারেট করা ট্রেট প্রয়োগ করুন। - Publish, subscribe, and RPC clients (Rust): Call the generated functions
within
service_bundle.rsto interact with other services. লাইফসাইকেল ও কমিউনিকেশন (C++): সাবক্লাস
ServiceBundleএবংonStart-এ আপনার প্রকাশক, সাবস্ক্রাইবার বা RPC এন্ডপয়েন্ট ইনিশিয়ালাইজ করুন।
মরচে
এটি রান করে স্কেলিটন ইমপ্লিমেন্টেশন জেনারেট করুন:
vsidlc -c /path/to/catalog -o /path/to/output --services--servicesফ্ল্যাগ সহvsidlcরান করলে প্রতিটি সার্ভিস বান্ডেলের জন্য একটি বয়লারপ্লেট Rust ইমপ্লিমেন্টেশন তৈরি হয়। এটি সোর্স কোড (main.rs) এবং সব ডিপেন্ডেন্সি সহ একটি বিল্ড কনফিগারেশন ফাইল (Android.bp) প্রদান করে, যাতে আপনার বান্ডেল অবিলম্বে ডিফল্ট মেসেজ আদান-প্রদান করতে পারে এবং আপনি আপনার ব্যবসায়িক লজিকে ফোকাস করতে পারেন।প্রতিটি পরিষেবা বান্ডেলের জন্য, Rust ইমপ্লিমেন্টেশন এখানে খুঁজুন:
/path/to/output/services/ServiceBundleName/src/main.rs।ডিফল্ট হিসেবে, জেনারেট করা ইমপ্লিমেন্টেশন ডিফল্ট ভ্যালু সহ মেসেজ তৈরি করে এবং প্রকাশক ও সাবস্ক্রাইবার অথবা RPC ক্লায়েন্ট ও সার্ভারের মধ্যে সেগুলি পাঠায়। এই আচরণ পরিবর্তন করতে,
main.rs-এTODOকমেন্ট খুঁজে নিন এবং আপনার পছন্দ অনুযায়ী তা অ্যাডজাস্ট করুন। যেমন:rust 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() { // Allocate dynamic resources (sockets, files, publishers, and // subscribers such as TirePressureRange#UNIQUE) 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 active publishing loops and release the dynamic resources // that were 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 সার্ভার (Rust):
এর পরে কী করতে হবে
আপনার পরিষেবা বান্ডেল ডিপ্লয় করতে, পরিষেবা বান্ডেল তৈরি ও ডিপ্লয় করুন দেখুন।