aboutsummaryrefslogtreecommitdiffstats
path: root/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-11 23:42:42 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-11 23:42:42 +0300
commit4eecf242d526781ef7cc1b8da54fb08a71edf4ad (patch)
treecb438664e8916c3d285b6f282e7bc97afd80aab5 /Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser
parent7fc37763c9210aac932bb6a199d6f2171b8a3036 (diff)
downloadUEFI-Lessons-4eecf242d526781ef7cc1b8da54fb08a71edf4ad.tar.gz
UEFI-Lessons-4eecf242d526781ef7cc1b8da54fb08a71edf4ad.tar.bz2
UEFI-Lessons-4eecf242d526781ef7cc1b8da54fb08a71edf4ad.zip
Add draft for lesson 38
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser')
-rw-r--r--Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c67
-rw-r--r--Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf22
2 files changed, 89 insertions, 0 deletions
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 <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/SimpleClass.h>
+
+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
+