আপনার VSIDL ক্যাটালগ ডিরেক্টরিতে প্রয়োজনীয় বিল্ড, প্রোটোবাফ এবং 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থেকে বৈশিষ্ট্যগুলো প্রয়োগ করুন। পাবলিশ ও সাবস্ক্রাইব এবং আরপিসি ক্লায়েন্ট: অন্যান্য সার্ভিসের সাথে যোগাযোগ করতে
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.ডিফল্টরূপে, তৈরি হওয়া ইমপ্লিমেন্টেশনটি ডিফল্ট মান সহ মেসেজ তৈরি করে এবং পাবলিশার ও সাবস্ক্রাইবারদের মধ্যে অথবা RPC ক্লায়েন্ট ও সার্ভারের মধ্যে সেগুলো পাঠায়। এই আচরণটি পরিবর্তন করতে,
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ফোল্ডারের বাইরে সরিয়ে দিন।
সি++
আপনার সার্ভিস বান্ডেলের জন্য একটি ক্লাস সহ
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 সার্ভার:
এরপর কী?
আপনার সার্ভিস বান্ডেলগুলো ডিপ্লয় করতে, “সার্ভিস বান্ডেল তৈরি ও ডিপ্লয় করুন” দেখুন।