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 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c (limited to 'Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c') 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; +} -- cgit v1.2.3-18-g5258