From 4eecf242d526781ef7cc1b8da54fb08a71edf4ad Mon Sep 17 00:00:00 2001 From: Konstantin Aladyshev Date: Sun, 11 Jul 2021 23:42:42 +0300 Subject: Add draft for lesson 38 Signed-off-by: Konstantin Aladyshev --- .../SimpleClassUser/SimpleClassUser.c | 67 ++++++++++++++++++++++ .../SimpleClassUser/SimpleClassUser.inf | 22 +++++++ 2 files changed, 89 insertions(+) create mode 100644 Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c create mode 100644 Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf (limited to 'Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser') diff --git a/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c new file mode 100644 index 0000000..bd3ac1d --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c @@ -0,0 +1,67 @@ +#include +#include + +#include + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + UINTN HandleCount; + EFI_HANDLE* HandleBuffer; + UINTN Index; + SIMPLE_CLASS_PROTOCOL* SimpleClass; + + EFI_STATUS Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gSimpleClassProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + Print(L"Error! Can't find any handle with gSimpleClassProtocolGuid: %r\n", Status); + return Status; + } + + for (Index = 0; Index < HandleCount; Index++) { + Print(L"Handle = %p\n", HandleBuffer[Index]); + Status = gBS->OpenProtocol( + HandleBuffer[Index], + &gSimpleClassProtocolGuid, + (VOID **)&SimpleClass, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (!EFI_ERROR(Status)) { + UINTN Number; + + Status = SimpleClass->GetNumber(&Number); + if (!EFI_ERROR(Status)) { + Print(L"Number before=%d\n", Number); + } else { + Print(L"Error! Can't get number: %r\n", Status); + } + + Status = SimpleClass->SetNumber(Number+5); + if (EFI_ERROR(Status)) + Print(L"Error! Can't set number: %r\n", Status); + + Status = SimpleClass->GetNumber(&Number); + if (!EFI_ERROR(Status)) { + Print(L"Number after=%d\n", Number); + } else { + Print(L"Error! Can't get number: %r\n", Status); + } + } else { + Print(L"Error! Can't open SimpleClass protocol: %r\n", Status); + } + } + + return Status; +} diff --git a/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf new file mode 100644 index 0000000..cb57e68 --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf @@ -0,0 +1,22 @@ +[Defines] + INF_VERSION = 1.25 + BASE_NAME = SimpleClassUser + FILE_GUID = 466eed70-8def-44ea-9fb4-9012b266ec8c + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiMain + +[Sources] + SimpleClassUser.c + +[Packages] + MdePkg/MdePkg.dec + UefiLessonsPkg/UefiLessonsPkg.dec + +[Protocols] + gSimpleClassProtocolGuid + +[LibraryClasses] + UefiApplicationEntryPoint + UefiLib + -- cgit v1.2.3-18-g5258