# Spectra ORB

# C++ Edition

# Lightweight Log Service Guide

![in-commerce\ne](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/a46897f454d08d46699b9d754a43b01b980ece3a973e8c2296c781811d2df96c.jpg)

# Spectra ORB

# C++ Edition

# LIGHTWEIGHTLOG SERVICE GUIDE

# Copyright Notice

© 2013 PrismTech Limited. All rights reserved.

This document may be reproduced in whole but not in part.

The information contained in this document is subject to change without notice and is made available in good faith without liability on the part of PrismTech Limited or PrismTech Corporation.

All trademarks acknowledged.

# CONTENTS

# Table of Contents

# Preface

About the Lightweight Log Service Guide . . . . . . . . vii

Contacts . . . . . . . viii

# Introduction

Description 3

OMG Standard Features . . . .

# Log Service

# Chapter 1 Basic Concepts 7

1.1 Architecture. . . .

1.1.1 General Organisation . . .

1.1.2 Log Records. . . .

1.1.3 Log Lifecycle . . . .

1.1.4 LogRecord Lifecycle . . . . . . 10

# Chapter 2 Specific Features 1 1

2.1 Data Types and Structures . . . . . . . 12

2.1.1 Constants . . . 12

2.1.2 TypeDefs . . . . 12

2.1.3 Enumerations . . . 13

2.1.4 Structs . . . 14

2.2 Interfaces . . . . . . . . . 16

2.3 Exceptions . . . . . . 24

# Chapter 3 Running the Service 25

3.1 Embedding the Service. . . . . . 25

3.1.1 Configuration Properties . . . . . . . 26

3.1.2 The init() Method. . . . . 26

3.2 Running from the Command Line . . . . . . 27

3.2.1 Running on a Fixed Endpoint . . . . 27

3.2.2 lwlogcpp Source Code. . . . . . 27

# Chapter 4 Creating Applications 2 9

4.1 Server . . . . . . . 29

4.1.1 The IDL File . . . . . 29

4.1.2 Developer-written Implementation Files . . . . . . 30

4.1.2.1 The Header File . . . . . 30

# Table of Contents

4.1.2.2 The Implementation File . . . . 30
4.2 Client . . . . . . . 33

# Index 43

# P re f a c e

# About the Lightweight Log Service Guide

The Lightweight Log Service Guide describes the Spectra ORB Lightweight Log Service C++ Edition product and how it can be used as a minimal, lightweight logging service for resource-constrained, applications using the Spectra ORB.

The Lightweight Log Service Guide is included with the Spectra ORB Documentation Set and is intended to be used with the IDL, Reference, and User Guides, as well as the other documents included with the Spectra ORB product. Please refer to the Product Guide for a complete list of documents.

# Intended Audience

The Lightweight Log Service Guide is intended to be used by developers who wish to integrate the Spectra ORB Lightweight Log Service C++ Edition into products which comply with OMG standards for object services. Readers should have a good understanding of the relevant programming languages (e.g. C++, IDL) and of the underlying technologies (e.g. CORBA).

# Organisation

The Lightweight Log Service Guide is organised into the following sections:

• The Introduction provides a general description of the service
• Chapter 1, Basic Concepts, describes the basic concepts and architecture
• Chapter 2, Specific Features, describes specific features and API
• Chapter 3, Running the Service, describes how to embed the Spectra ORB Lightweight Log Service into programs and use the Service’s standalone executable
• Chapter 4, Creating Applications, demonstrates application creation.

# Conventions

The conventions listed below are used to guide and assist the reader in understanding the Lightweight Log Service Guide.

. i
WIN
UNIX
C
Item of special significance or where caution needs to be taken.
Item contains helpful hint or special information.
Information applies to Windows (e.g. XP, Vista, Windows 7) only.
Information applies to Unix-based systems (e.g. Solaris) only.
C language specific.

![The image depicts a triangular safety warning sign featuring a thick red border and a white background. Centered inside is a black exclamation mark, with a small black diamond shape situated directly below it.](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/32f2bcf3575a2305287205fab7281e321de98f73c980267ef1009db711ee7303.jpg)

C++ Java

C++ language specific.

Java language specific.

Hypertext links are shown as blue italic underlined.

On-Line (PDF) versions of this document: Items shown as cross references to other parts of the document, e.g. Contacts on page viii, behave as hypertext links: users can jump to that section of the document by clicking on the cross reference.

```txt
% Commands or input which the user enters on the command line of their computer terminal
```

Courier fonts indicate programming code and file names.

Extended code fragments are shown in shaded boxes:

```txt
NameComponent newName[] = new NameComponent[1];
// set id field to "example" and kind field to an empty string scarf
newName[0] = new NameComponent ("example", "");
```

Italics and Italic Bold indicate new terms, or emphasise an item.

Arial Bold indicates user-related actions, e.g. File > Save from a menu.

Step 1: One of several steps required to complete a task.

# Contacts

PrismTech can be reached at the following contact points for information and technical support.

USA Corporate Headquarters European Head Office

<table><tr><td>PrismTech Corporation400 TradeCenterSuite 5900Woburn, MA01801USA</td><td>PrismTech LimitedPrismTech House5th Avenue Business ParkGatesheadNE11 0NGUK</td></tr><tr><td>Tel: +1 781 569 5819</td><td>Tel: +44 (0)191 497 9900Fax: +44 (0)191 497 9901</td></tr></table>

Web: http://www.prismtech.com

Technical questions: crc@prismtech.com (Customer Response Center)

Sales enquiries: sales@prismtech.com

# INTRODUCTION

# Description

The Spectra ORB Lightweight Log Service accepts and manages log records. It is intended to be an efficient, central facility used mainly in high performance, resource constrained environments such as in embedded environments. The log records which the Lightweight Log Service is designed to store and manage will be produced by applications which reside in the same environment as the Service. The records are stored in a memory-only storage area which is owned and managed by the Service.

The Spectra ORB Lightweight Log Service C++ Edition is compliant with version 1.1 of the OMG’s Lightweight Log Service Specification and satisfies the requirements of the Software Communications Architecture (SCA).

The Spectra ORB Lightweight Log Service can be used in all areas of embedded systems (such as machine control, onboard vehicle systems, pocket computer and electronic organizers) plus in any application area where a small, memory-only logging facility is needed.

# OMG Standard Features

The Spectra ORB Lightweight Log Service is designed for use in embedded and real-time systems. The service provides the following OMG specified features:

• Support for simple logging. The Spectra ORB Lightweight Log Service is a lean, stand-alone service targeted for use where resources are constrained, such as in embedded environments.

• Provision of simple log producer and log consumer interfaces for ease of use.

• Logging information is stored only in memory in order to accommodate constrained environments: no persistent storage is supported nor required.

• The data structure which is used to store a log record is specially designed to accommodate the constraints of embedded environments. This structure, combined with a list of well known typecodes, provides the control on type variety which is needed in an embedded system. Further, the structure does not use anys, thereby simplifying use with embedded ORBs (which frequently impose restrictions on the any type).

• Log records can be read as a series of small, consecutive groups for efficiency, similar to using an iterator.

• Log write operations are strictly asynchronous. The log does not transmit feedback or exceptions: this avoids any interference to log producer timing constraints.

Introduction

# LOG SERVICE

# CHAPTER

# 1 Basic Concepts

This section describes the basic concepts and architecture of the Lightweight Log Service as defined in the OMG’s Lightweight Log Service Specification.

# 1.1 Architecture

# 1.1.1 General Organisation

The Lightweight Log Service is a self-contained service. It does not use or rely on event channels or other infrastructure, unlike the OMG's Telecom Log Service which is layered on top of the Notification Service. The Lightweight Log Service is specifically designed for resource constrained environments.

A Lightweight Log Service instance (Log) is an implementation detail. There is no single interface in the IDL which represents a Log. Instead, a Log instance realises three distinct interfaces, each implemented as separate CORBA objects, corresponding to a different client role:

• LogProducer - This interface is for use by clients which produce Log records. It declares operations for writing Log records into the associated Log.
• LogConsumer - This interface is for use by clients which consume or query the Log records which are stored in the associated Log. It declares operations for querying and retrieving Log records according to various criteria.
• LogAdministrator - This interface is for use by clients which manage the operational state of a Log. It declares operations for setting the various administrative options, and for clearing or destroying the associated Log.

This approach to interface design is a departure from the majority of OMG service specifications with which the reader may be familiar. The typical approach, taken in other OMG service specifications is to declare separate aspects in separate interfaces, but then to inherit them all into one large interface. This enables clients to access all the supported interfaces of an object through a single object reference.

All three interfaces inherit the LogStatus interface. The LogStatus interface provides access to status information for the associated Log. This enables all clients to have easy access to status information for the Log.

As of version 1.1 of the specification a new interface Log has been defined that inherits from the main three functional interfaces of the service (producer, consumer and administrator). The allows a single object reference to be used to resolve the service, from which the individual log component interfaces can be found.

# 1.1.2 Log Records

A client which writes to a Log, does so by using the ProducerLogRecord struct to pass the Log record information. This struct declares the following fields:

• producerId - a textual identifier for the producer
• producerName - a textual name for the producer
• level - Log record classification according to the LogLevel type
• logData - the informational message to be logged.

When a Log receives a ProducerLogRecord from a producer, it wraps it in a LogRecord structure, fills in some additional information, and then stores it. The LogRecord structure declares the following fields:

• id - uniquely identifies the Log record within the context of the Log
• time - the time stamp for the record
• info - the ProducerLogRecord (from the producer)

Figure 1, Lightweight Log Service, shows the relationship between these components, along with the other Lightweight Log Service components.

![**Blocks:**\n\n*   **`((interface)) LogStatus`**\n    *   `+get_max_size()`\n    *   `+get_current_size()`\n    *   `+get_n_records()`\n    *   `+get_log_full_action()`\n    *   `+get_availability_status()`\n    *   `+get_administrative_state()`\n    *   `+get_operational_state()`\n*   **`((interface)) LogProducer`**\n    *   `+write_records()`\n    *   `+write_record()`\n*   **`((interface)) LogConsumer`**\n    *   `+get_record_id_from_time()`\n    *   `+retrieve_records()`\n    *   `+retrieve_records_by_level()`\n    *   `+retrieve_records_by_producer_id()`\n    *   `+retrieve_records_by_producer_name()`\n*   **`((interface)) LogAdministrator`**\n    *   `+set_max_size()`\n    *   `+set_log_full_action()`\n    *   `+set_administrative_state()`\n    *   `+clear_log()`\n    *   `+destroy()`\n*   **`Log`**\n*   **`ProducerLogRecord`**\n    *   `+producerId : String`\n    *   `+producerName : String`\n    *   `+level : LogLevel`\n    *   `+logData : String`\n*   **`((Integer)) RecordId`**\n*   **`LogRecord`**\n    *   `-id : RecordId`\n    *   `-time : LogTime`\n*   **`LogTime`**\n    *   `+seconds : long`\n    *   `+nanoseconds : long`\n*   **`LogLevel`**\n\n**Connections:**\n\n*   **Generalization (Inheritance):**\n    *   `LogProducer` inherits from `LogStatus`\n    *   `LogConsumer` inherits from `LogStatus`\n    *   `LogAdministrator` inherits from `LogStatus`\n*   **Realization (Implementation):**\n    *   `Log` implements `LogConsumer` (solid line with hollow triangle)\n    *   `Log` implements `LogProducer` (dashed line with hollow triangle)\n    *   `Log` implements `LogAdministrator` (dashed line with hollow triangle)\n*   **Aggregation:**\n    *   `Log` aggregates `LogRecord` (solid line with open diamond at `Log` end, multiplicity `0..*` at `LogRecord` end)\n*   **Composition:**\n    *   `LogRecord` composes `ProducerLogRecord` (solid line with filled diamond at `LogRecord` end)\n*   **Dependency:**\n    *   `LogRecord` depends on `RecordId`\n    *   `LogRecord` depends on `LogTime`\n    *   `ProducerLogRecord` depends on `LogLevel`](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/994c169154c08987cb4f6b7e8676f95a63d18fbbdcfb7bb5cf7e0b1dabf44e5b.jpg)

Figure 1 Lightweight Log Service

# 1.1.3 Log Lifecycle

Log creation and destruction is straightforward:

1. A Log instance is created by an application using the LwLogService::init() method of the service's Embedding API (see Section 3.1, Embedding the Service, on page 25). This operation returns three distinct CORBA object references, each one supporting one of the three interfaces onto the Log (LogProducer, LogConsumer and LogAdministrator).
2. During the life of a Log, its clients interact with it via one or more of its three interfaces.
3. A Log can be destroyed using the destroy() operation on its LogAdministrator interface. This operation destroys the Log, its associated storage area, and any Log records that it may contain. It also destroys the three objects that implement the Log interfaces.

# 1.1.4 LogRecord Lifecycle

1. A client which produces Log records does so by creating a ProducerLogRecord, containing the information to be logged. It then invokes one of the write operations on the LogProducer interface.
2. When a Log receives a ProducerLogRecord (via its LogProducer interface), it wraps it in a LogRecord structure and fills in the id and time members.
3. The Log then stores that LogRecord in its memory-based Log storage area if the Log is able or allowed to accept it. Whether the Log record can be stored or not depends on the administrative and operational settings of the Log.
4. A consumer retrieves LogRecords, from a Log, using the operations on the LogConsumer interface. The LogConsumer interface declares a number of operations for retrieving Log records according to various search criteria.
5. Records can be removed from a Log, using the clear\_log() operation on the LogAdministrator interface. This operation removes all of the records from the Log, reducing the current size of the Log to zero, but leaving the maximum size unaffected.
6. Although there are no operations available to selectively remove Log records from a Log, a Log’s administrative properties can be set to allow new records to overwrite the oldest records in order to reuse the existing storage space.

# 2 Specific Features

This section describes the Spectra ORB Lightweight Log Service’s specific features and API.

This section covers the following log components, in order:

• Data types and structures, including constants, typedefs, enumerations and structs. Items covered include log levels, administrative and operational states’ values, log time and log record structures.
• Interfaces and their associated operations, including:

- LogStatus (the base-interface for the remaining interfaces)
- LogProducer
- LogConsumer
- LogAdministrator

• Exceptions

The components described here include:

• those which comply with the OMG Lightweight Log Service Specification
• PrismTech-specific components which are in addition to those specified in the OMG’s specification.

The OMG Lightweight Log components are in the CosLwLog module.

The PrismTech Lightweight Log components are in the EORB::LwLogService module.

The components which are PrismTech-specific are noted as such in the text.

The API definitions generally follow the convention for the C++ language, although the namespace component of the interface and other names may be omitted for simplicity and readability. For example, the following C interface definitions

CosLwLog::LogStatus::get\_operational\_state ()

CosLwLog::OperationalState CosLwLog::LogStatus::get\_operational\_state ()

are shown as simply

get\_operational\_state ()

OperationalState get\_operational\_state ()

# 2.1 Data Types and Structures

# 2.1.1 Constants

# LogLevel Constants

The following constants are used to classify log records. The value is saved as a LogLevel type. See typedef unsigned short LogLevel on page 12.

```python
SECURITY_ALARM = 1
FAILURE_ALARM = 2
DEGRADED_ALARM = 3
EXCEPTION_ERROR = 4
FLOW_CONTROL_ERROR = 5
RANGE_ERROR = 6
USAGE_ERROR = 7
ADMINISTRATIVE_EVENT = 8
STATISTIC_REPORT = 9
```

Codes 10-26 are reserved for program debugging levels.

# 2.1.2 TypeDefs

# typedef unsigned short LogLevel

The LogLevel type is used to classify log records. A LogLevel value is saved in the log record and is available to the consumer clients when the record is retrieved. The value has no particular meaning nor has any side effects during storage of the record in the log. See LogLevel Constants on page 12.

# typedef sequence&lt;CosLwLog::LogLevel&gt; LogLevelSequence

Defines an unbound sequence of LogLevel values.

# typedef sequence&lt;CosLwLog::LogRecord&gt; LogRecordSequence

Defines an unbounded sequence of LogRecords.

# typedef sequence&lt;CosLwLog::ProducerLogRecord&gt; ProducerLogRecordSequence

Defines an unbound sequence of ProducerLogRecords.

# typedef unsigned long long RecordId

A 64-bit integer which is used to hold the unique ID value for a log record.

# typedef sequence&lt;string&gt; StringSeq

A sequence of producerIds. See struct ProducerLogRecord on page 15.

# 2.1.3 Enumerations

# enum AdministrativeState

```txt
enum AdministrativeState {
    locked,
    unlocked
}

The AdministrativeState enumerations indicate whether the log will accept and store log records from log record producers or not.

unlocked - the log will accept log records for storage

locked - the log will not accept new log records for storage. Records which are already in the log can still be read or deleted
```

# enum LogFullAction

```txt
enum LogFullAction {
    WRAP,
    HALT
}

The LogFullAction values are used by set_log_full_action() to determine which action to take when the log becomes full. Also see set_log_full_action() on page 23.

HALT - no more log records are allowed to be placed into the log

WRAP - log records can continue to be placed into the log; new log records will overwrite the space occupied by the oldest log records
```

# enum OperationalState

```txt
enum OperationalState {
    disabled,
    enabled
}

The OperationalState enumeration defines the Lightweight Log Service's operational states.

enabled - signifies that the log is available for use by log record producer and consumer clients

disabled - signifies that the log has encountered a run time problem and is not available for use by log record producers or consumers.
```

# 2.1.4 Structs

struct AvailabilityStatus
```txt
struct AvailabilityStatus {
    boolean off_duty;
    boolean log_full;
};
The AvailabilityStatus' members indicate if the log is available for use.
off_duty - indicates that the log's AdministrativeState is locked or the OperationalState is disabled, in other words, the service is not available for use, when this is set to TRUE.
log_full - indicates the log is full when this is set to TRUE.
```

struct EORB::LwLogService::Config
```cpp
struct EORB::LwLogService::Config {
    unsigned long boolean qosMaxSize;
    boolean qosEntryLocking;
};
```

i This is a PrismTech-specific structure which is used when creating a log. This struct holds values which determine certain aspects of the log’s behaviour.

qosMaxSize - Specifies the maximum size, in bytes, that will be used by the log storage area, for storing log records. The default value is 2048 bytes

qosEntryLocking - Controls whether the implementation uses locking (TRUE) or not (FALSE). If locking is turned off, then concurrent invocations on the service may result in undefined behaviour. The default value of this property is TRUE(1).

struct LogRecord
```cpp
struct LogRecord {
    CosLwLog::RecordId id;
    CosLwLog::LogTime time;
    CosLwLog::ProducerLogRecord info;
};
```

LogRecord is the data type which is placed into the log. LogRecord contains the log information created by a log producer, plus additional information which identifies the log record and when it was placed into the log.

id - a value which uniquely identifies the log record

time - the time that the log record has been created and subsequently placed into the log

info - the ProducerLogRecord created by a log producer. See struct ProducerLogRecord below.

struct LogTime
```txt
struct LogTime {
    long seconds;
    long nanoseconds;
};
```

The time format used by LogRecord to record when a log record was created. The LogTime fields map directly to the POSIX timespec structure.

struct ProducerLogRecord
```txt
struct ProducerLogRecord {
    string producerId;
    string producerName;
    CosLwLog::LogLevel level;
    string logData;
};
```

ProducerLogRecord is the data type used by log producer clients to contain the producer’s log data. The ProducerLogRecord is encapsulated in a LogRecord struct before it is stored in the log.

producerId - a string value which identifies the log producer

producerName - the log producer’s name

level - a classification value used to indicate the type LogRecord the log is, such as if it is a security alarm log, failure alarm log, etc. See LogLevel Constants on page 12.

logData - textual information which the log producer wants to store in the log record

struct EORB::LwLogService::References
```cpp
struct EORB::LwLogService::References {
    CosLwLog::LogConsumer consumer;
    CosLwLog::LogProducer producer;
    CosLwLog::LogAdministrator administrator;
};
```

i T h i s i s a P r i s m Te c h - s p e c i f i c s t r u c t u r e w h i c h i s r e t u r n e d b y t h e EORB::LwLogService::init() when creating a log.

The References’ members contain object references to the log’s interfaces.

consumer - reference to the LogConsumer object

producer - reference to the LogProducer object

administrator - reference to the LogAdministrator object

# 2.2 Interfaces

# interface LogStatus

The LogStatus interface provides common operations which are inherited by the other Lightweight Log Service interfaces.

# get\_administrative\_state ()

CosLwLog::AdministrativeState get\_administrative\_state ()

This operation gets the value indicating whether the log is allowed to accept new log records or not.

Returns an AdministrativeState value (see enum AdministrativeState on page 13) for the description of AdministrativeState values.

# get\_availability\_status ()

CosLwLog::AvailabilityStatus get\_availability\_status ()

This operation obtains the availability status of the log. The availability status indicates whether the log is able to able to accept log records or not.

Returns an AvailabilityStatus value (see struct AvailabilityStatus on page 14) for the description of AvailabilityStatus values.

# get\_current\_size ()

unsigned long long get\_current\_size ()

Log records are stored in a storage area encapsulated by the Log class. This operation returns the size, in bytes, of the log currently occupied by log records. This value is less than or equal to the total storage area size returned by the get\_max\_size() operation.

# get\_log\_full\_action ()

CosLwLog::LogFullAction get\_log\_full\_action ()

get\_log\_full\_action() gets the type of action which is to be taken when the log is full.

Returns a LogFullAction value (see enum LogFullAction on page 13) for the description of LogFullAction values.

# get\_max\_size ()

unsigned long long get\_max\_size ()

Log records are stored in the log’s storage area. This operations returns the maximum size, in bytes, that the storage area is allowed to be. See also set\_max\_size () on page 23.

# get\_n\_records ()

unsigned long long get\_n\_records ()

The get\_n\_records() operation returns the number of log records currently stored in the log.

# get\_operational\_state ()

CosLwLog::OperationalState get\_operational\_state ()

This operation gets a value which indicates whether the log can be accessed or not, for both log producers and consumers.

Returns an OperationalState value (see enum OperationalState on page 13) for the description of OperationalState values.

# interface LogProducer

This interface is used by log producers to save or write log records to a log.

![The image shows a triangular warning sign with a thick red border and a white interior. In the center is a black symbol consisting of a vertical line with a downward-pointing arrow at the bottom.](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/91cc1a430005fa525b2bc03eed1d45ee613c83c0c39096d39db094dafec62bbe.jpg)

There is no guarantee that a log record will be accepted or stored by the log.

# write\_record ()

oneway void write\_record ( in CosLwLog::ProducerLogRecord record)

This operation stores or writes a log record to the log. A log record will only be stored when

• the AdministrativeState is set to unlocked
• the OperationalState is set to enabled
• the AvailabilityStatus’ off\_duty value is FALSE
and
• the size of the log record is smaller than the amount of free space in the log or
• the size of the log record is greater than the amount of free space in the log storage area and the value of LogFullAction is set to WRAP.

If there is not enough space in the store to save the log record and LogFullAction is set to HALT, then write\_record() will set the AvailabilityStatus’ log\_full value to TRUE.

writeRecord() places the record passed to it (ProducerLogRecord) into a LogRecord struct: the LogRecord.time field is set to the current UTC time and the LogRecord.id field is set to a value which uniquely identifies the log.

# Parameters

record - the log record to be stored

# write\_records ()

oneway void write\_records ( in CosLwLog::ProducerLogRecordSequence records)

The write\_records() operation writes a sequence of log records to the log. write\_records() behaviour and is the same write\_record(), notwithstanding that write\_records() saves a sequence of records. (Refer to write\_record () above).

Log records (in the sequence passed to write\_records()) will be saved to the log until the available storage space becomes less than the size of current record which write\_records() is attempting to save. For example, if write\_records() is passed a sequence of ten records and the record store runs out of space while trying to save the seventh record, then the seventh and subsequent records will not be saved, whereas the first six records will have been saved.

# Parameters

records - sequence of records to be saved or written to the log

# interface LogConsumer

The LogConsumer interface enables log records to be retrieved from the log by log consumers.

# get\_record\_id\_from\_time ()

CosLwLog::RecordId get\_record\_id\_from\_time ( in CosLwLog::LogTime fromTime) raises(CosLwLog::InvalidParam)

The get\_record\_id\_from\_time() operation returns the record ID of the first record in the log which has a time stamp that is greater than or equal to the time specified in the fromTime parameter.

If the log does not contain a record that meets this criteria, then a record ID will be returned for the next logical record which would have been placed in the store, noting that this future record will not have been placed in the store yet. If a retrieval operation attempts to retrieve a record using the ID for this record and it has not yet been placed in the log then an empty record will be returned.

If the time specified in the fromTime parameter is in the future, then there is no guarantee that the records returned by a retrieval operation will have a time stamp that satisfy the time criteria, in other words the returned records could be empty.

# Parameters

fromTime - specifies which records to retrieve where the record’s time stamp must be greater than or equal to the time specified

# retrieve\_records ()

```cpp
CosLwLog::LogRecordSequence retrieve_records (
    inout CosLwLog::RecordId currentId,
    inout unsigned long howMany)
raises(CosLwLog::InvalidParam)
```

This operation retrieves a sequence of log records from the log. The first record to be retrieved is specified by the currentId parameter; the number of records to be retrieved is specified by howMany parameter. If the number of records specified by howMany is greater than number of records available, then only the available records will be returned.

The currentId and howMany values are updated when each record is retrieved:

• currentId is set to the record ID of the next record, unless there are no further records, in which case currentId is set to zero (0)
• howMany is set to the total number of records which have been retrieved

If the record specified by currentId does not exist, but corresponds to the next record that will be recorded in the future, retrieveRecords() returns an empty sequence of LogRecords, sets howMany to zero and leaves the value of currentId unchanged.

If the record specified by currentId does not exist and does not correspond to the next record that will be recorded in the future, or if the log is empty, then retrieveRecords() returns an empty sequence of LogRecords and sets currentId and howMany to zero (0).

# Parameters

currentId - the first record to be retrieved from the log

howMany - the number of records to be retrieved from the log

# retrieve\_records\_by\_level ()

```cpp
CosLwLog::LogRecordSequence retrieve_records_by_level (
    inout CosLwLog::RecordId currentId,
    inout unsigned long howMany,
    in CosLwLog::LogLevel valueList)
    raises(CosLwLog::InvalidParam)
```

This operation retrieves, from the log, the number of records specified by howMay parameter which have a log level value appearing in the list of log levels specified by valueList. The first log record which will be retrieved is specified by the currentId.

If the number of records specified by howMany is greater than number of records available, then only the available records will be returned.

The currentId and howMany values are updated when each record is retrieved:

• currentId is set to the record ID of the next record
• howMany is set to the total number of records which have been retrieved

If no further records are available, then currentId is set to the next record that will be recorded in the future the retrieve\_records\_by\_level() returns an empty sequence of LogRecords, sets howMany to zero and leaves the value of currentId unchanged.

If the record specified by currentId does not exist and does not correspond to the next record that will be recorded in the future, or if the log is empty, then retrieve\_records\_by\_level() returns an empty list of LogRecords and sets currentId and howMany to zero (0).

![The image displays a standard warning symbol consisting of a red triangle with rounded corners enclosing a black exclamation point. The background is white.](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/5017a5496d70744ad93134110999bdec87d5f6fe2408e5799fe4a47813aae260.jpg)

retrieve\_records\_by\_level() does not guarantee to return a sequence of log records nor to update the currentId value. Consequently, the record ID of the first record to be retrieved should be re-established before subsequent invocations of this operation when using a different valueList or when using other retrieval operations.

# Parameters

currentId - record ID of the starting record

howMany - specifies the number of records to retrieve; during record retrieval its value is set to the number of records actually retrieved

valueList - the log levels to be searched

# retrieve\_records\_by\_producer\_id ()

```cpp
CosLwLog::LogRecordSequence retrieve_records_by_producer_id (
    inout CosLwLog::RecordId currentId,
    inout unsigned long howMany,
    in CosLwLog::StringSeq valueList)
    raises(CosLwLog::InvalidParam)
```

This operation retrieves a sequence of records from the log which have a producer ID that is listed in the valueList parameter. The currentId identifies first record to be retrieved; howMany specifies the number of records to be retrieved. If the number of records specified by howMany is greater than number of records available, then only the available records will be returned.

The currentId and howMany values are updated when each record is retrieved:

• currentId is set to the record ID of the next record
• howMany is set to the total number of records which have been retrieved

If no further records are available, then currentId is set to the next record that will be saved in the future, the operation returns an empty list of LogRecords, sets howMany to zero and leaves the value of currentId unchanged.

If the record specified by currentId does not exist and does not correspond to the next record that will be recorded in the future, or if the log is empty, then retrieve\_records\_by\_producer\_id() returns an empty list of LogRecords and sets currentId and howMany to zero (0).

![The image displays a red triangular warning sign with a white interior. Inside, there is a black exclamation mark centered above a black diamond shape.](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/e02f577a656ea4f543d0177b6da7f7e5dad30ec94b4fe15fc50aeb757e251c2a.jpg)

retrieve\_records\_by\_producer\_id() does not guarantee to return a sequence of log records nor to correctly update the currentId value. Consequently, the record ID of the first record to be retrieved should be re-established before subsequent invocations of this operation when using a different valueList or when using other retrieval operations.

# Parameters

currentId - record ID of the starting record

howMany - specifies the number of records to retrieve; during record retrieval its value is set to the number of records actually retrieved

valueList - the producer IDs to be searched

# retrieve\_records\_by\_producer\_name ()

```cpp
CosLwLog::LogRecordSequence retrieve_records_by_producer_name (
    inout CosLwLog::RecordId currentId,
    inout unsigned long howMany,
    in CosLwLog::StringSeq valueList)
    raises(CosLwLog::InvalidParam)
```

This operation retrieves a sequence of records from the log which have a producer name that is listed in the valueList parameter. The currentId identifies first record to be retrieved; howMany specifies the number of records to be retrieved. If the number of records specified by howMany is greater than number of records available, then only the available records will be returned.

The currentId and howMany values are updated when each record is retrieved:

• currentId is set to the record ID of the next record
• howMany is set to the total number of records which have been retrieved

If no further records are available, then currentId is set to the next record that will be saved in the future, the operation returns an empty list of LogRecords, sets howMany to zero and leaves the value of currentId unchanged.

If the record specified by currentId does not exist and does not correspond to the next record that will be recorded in the future, or if the log is empty, then retrieve\_records\_by\_producer\_name() returns an empty list of LogRecords and sets currentId and howMany to zero (0).

![The image displays a standard warning symbol. It consists of a red triangular outline with a white interior. Centered within the triangle is a bold, black exclamation point.](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/66eae486cdccae9205702f7e608b48d8c68025d65b6a6c2a42dcb40929dd231f.jpg)

retrieve\_records\_by\_producer\_name() does not guarantee to return a sequence of log records nor to update the currentId value. Consequently, the record ID of the first record to be retrieved should be re-established before subsequent invocations of this operation when using a different valueList or when using other retrieval operations.

# Parameters

currentId - record ID of the starting record

howMany - specifies the number of records to retrieve; during record retrieval its value is set to the number of records actually retrieved

valueList - the producer names to be searched

# interface LogAdministrator

The LogAdministrator interface provides the management functionality which is needed to operate and manage a log.

# clear\_log ()

void clear\_log ()

This operation removes all log records from the log. The maximum size of the storage area is not changed.

# destroy ()

void destroy ()

This operation destroys the log and removes it from memory, releasing associated memory resources.

![The image displays a standard warning symbol, featuring a red triangle outline with a black exclamation mark centered inside it.](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/fd17f10936f4bfe29fecea854ba664a748a99403092b57a9467985613aa03699.jpg)

Use destroy() with care since any log records which are in the log when destroy() is called will be lost.

# set\_administrative\_state ()

void set\_administrative\_state ( in CosLwLog::AdministrativeState state)

Sets the administrative state of the log. The administrative state determines whether or not log records can be saved to the log. The required administrative state, passed to the operation via state parameter and can be:

• UNLOCKED - log records are allowed to be placed into the log and log records can be read from the log
• LOCKED - log records are not allowed to be placed into the log; log records can still be read from the log

Also see enum AdministrativeState on page 13.

# Parameters

state - the required administrative state

# set\_log\_full\_action ()

void set\_log\_full\_action ( in CosLwLog::LogFullAction action)

Sets the action to be taken when the log becomes full. The action to be taken is passed via the action parameter. The available actions can be:

• HALT - no more log records are allowed to be placed into the log
• WRAP - log records can continue to be placed into the log; new log records will over write the space occupied by the oldest log records

Also see enum LogFullAction on page 13.

# Parameters

action - The action to be taken when the log becomes full.

# set\_max\_size ()

void set\_max\_size ( in unsigned long long size) raises(CosLwLog::InvalidParam)

This operation sets the maximum size, in bytes, of the log. It raises the InvalidParam exception if the supplied parameter (size) is invalid.

![The image displays a standard warning sign, characterized by an upright red triangle with a thick red border and a white background. Inside the triangle, centered, is a black symbol. This symbol consists of an exclamation mark (!) positioned directly above a downward-pointing arrow (▼).](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/bd584fec2eebe3f79659516e567e39ef1267a853fdfa5dfd6c3a02506c851371.jpg)

Care should be taken when using set\_max\_size() to avoid allocating a maximum size storage which impinges on or exceeds the amount of memory available on the platform. Further, the maximum size might be highly contrained on certain memory-restricted platforms, therefore particular care is needed in setting the maximum memory sized in these cases.

# Parameters

size - the size, in bytes, to set the maximum log size to.

# 2.3 Exceptions

The CosLwLog module defines a single exception, InvalidParam, described below.

# exception InvalidParam

This exception is thrown when a operation is passed an invalid parameter.

# CHAPTER

# 3 Running the Service

The Lightweight Log Service is usually run by programatically embedding it into an executable or module, using the LwLogService embedding API. For convenience, a standalone executable is also provided so that it can be run from the command line.

This section describes how to embed the Lightweight Log Service using its embedding API, plus it describes how to run the standalone executable from the command line.

# 3.1 Embedding the Service

A Refer to the Install Guide for specific compiler and linking details for your platform.

The Spectra ORB Lightweight Log Service, as described in previous sections, c o n s i s t s o f t h r e e i n t e r f a c e s ( L o g P r o d u c e r, L o g C o n s u m e r a n d LogAdministrator), a log record storage area and other components which are used to configure and control the Service’s behaviour.

The tasks described below show how to embed a Spectra ORB Lightweight Log Service into a code module by setting the configuration component and retrieving references to the interfaces that store, retrieve and administer log records.

Step 1: Make the log’s embedding API available by placing the following include statements in the source code:

```c
#include "CosLwLog.h"
#include "eOrb/EORB/LwLogService.h"
```

i Ensure your build system has \$(EORBHOME)/include/eOrb/services/lw on its include path .

Step 2: Initialise the log by calling the EORB::LwLogService::init() method. The EORB::LwLogService::init() method returns a struct, of type EORB::LwLogService::References. The References struct contains references to the log’s three interfaces, LogProducer, LogConsumer and LogAdministrator, which respectively are used to create and retrieve the log’s records and to administer the log.

Step 3: Call the appropriate LogProducer, LogConsumer and LogAdministrator, operations to perform required logging operations.

# 3.1.1 Configuration Properties

The EORB::LwLogService::Config struct declares the qosMaxSize and qosEntryLocking configuration properties to control aspects of the log’s behaviour: qosMaxSize Specifies the maximum size, in bytes, that can be used to store log records; qosEntryLocking controls whether locking is used or not. For a complete description of these properties see struct EORB::LwLogService::Config on page 14.

An example of how to set these configuration properties is shown in Example 1, below.

Example 1 Setting Configuration Properties
```txt
EORB::LwLogService::Config config;
config.qosMaxSize = 2048;
config.qosEntryLocking = true;
```

# 3.1.2 The init() Method

The Spectra ORB Lightweight Log Service’s initialisation method, EORB::LwLogService::init() initialises a log instance. The init() method takes three parameters:

• a reference to the CORBA::ORB that the log service will run with
• a reference to a PortableServer::POA that the service will run in
• a EORB::LwLogService::Config struct containing configuration properties (see struct EORB::LwLogService::Config on page 14).

The init() method returns a struct containing references to the Log interfaces, LogProducer, LogConsumer and LogAdministrator. See struct EORB::LwLogService::References on page 15 for details.

# Example 2 Using the init() Method

The following code extract creates a lightweight log instance using the EORB::LwLogService::init() method. The init() method is passed a reference to an initialised ORB object and a EORB::LwLogService::Config struct (see struct EORB::LwLogService::Config on page 14).

```cpp
EORB::LwLogService::References_ptr refs = EORB::LwLogService::init (orb, poa, config);
```

# 3.2 Running from the Command Line

The Service can run from the command line using the lwlogcpp example executable with zero or more of the options listed in Table 1.

```txt
% lwlogcpp [options]
```

The complete source code for lwlogcpp is shown after Table 1.

Table 1 Command Line Options

<table><tr><td>Option</td><td>Description</td></tr><tr><td>-LogServiceMaxSize</td><td>Sets the maximum size, in bytes, of the log record storage area.The default value is 1024.This option corresponds to the qosMaxSize configuration property in the EORB::LwLogService::Config struct.</td></tr><tr><td>-LogServiceEntryLocking</td><td>Turns locking on or off in the service implementation.The default value is on.This option corresponds to the qosWithLocking configuration property in the EORB::LwLogService::Config struct.</td></tr><tr><td>-LogServiceUIOP</td><td>Runs the service on a UIOP endpoint. Only available on systems where UIOP is a supported transport.The default is no.</td></tr></table>

# 3.2.1 Running on a Fixed Endpoint

The server can be run on a fixed endpoint by running with the -ORBPOAEndpoints argument. The Log Service servant is created within a child POA LogService so for example can be run on a fixed IIOP endpoint with:

-ORBPOAEndpoints LogService:iiop:&lt;host&gt;:&lt;port&gt;

and resolved as an initial reference by a client using:

-ORBInitRef LogService=corbaloc:iiop:&lt;host&gt;:&lt;port&gt;/LogService

# 3.2.2 lwlogcpp Source Code

The source code for creating a log service executable can be found in the provided code examples (examples/cpp/services/lwlog/server).

# CHAPTER

# Creating Applications

The main tasks which may normally be performed when using the Spectra ORB Lightweight Log Service include:

• creation of a log service server for storing records of data or events sent by clients
• creation of clients which supply the data or events
• creation of clients which use the log’s records

This section, Creating Applications, describes how the specific features and requirements for the Spectra ORB Lightweight Log Service can be used to achieve the tasks listed above. The section is organised into a sequence of topics which describes how to

• create a log service server
• create a combined client which demonstrates how to write and read data to and from the log server1

The topics use examples to illustrate how relevant tasks can be achieved.

# 4.1 Server

The following code demonstrates how to create a Lightweight Log Service server.

# 4.1.1 The IDL File

An IDL file, lwlog.idl in this example, defines the log service example’s interface. The interface contains a single operation, shutdown(), which is used to shutdown or stop the server.

```txt
interface lwlog_example
{
    oneway void shutdown();
};
```

The IDL compiler generates the server files, lwlog\_s.h and lwlog\_s.cpp. The lwlog\_s.h file will be imported into the developer-written server implementation files, lwlog\_i.h and lwlog\_i.cpp, shown below.

# 4.1.2 Developer-written Implementation Files

# 4.1.2.1 The Header File

```cpp
#ifndef _lwlog_i_h_
#define _lwlog_i_h_

#include "lwlog_s.h"

class lwlog_impl : virtual public POA_lwlog {
public:
    lwlog_impl (CORBA::ORB_ptr orb);
    virtual void shutdown (EORB_ENV_ARG1);

private:
    CORBA::ORB_ptr porb;
};

#endif
```

The Header file declares the lwlog class. In addition to a default constructor declared here, this class contains the public shutdown() operation (previously declared in the lwlog.idl file). The private variable, porb, is declared which will be used to hold a pointer to the ORB object.

The declaration for the shutdown() operation uses a Spectra ORB portable exception macro. The Spectra ORB portable exception macros are an alternative method for passing exception information on platforms that do not support C++ exceptions (see the Platforms Without C++ Exception Support section of the User Guide for details).

# 4.1.2.2 The Implementation File

The server implementation file, server.cpp, configures, instantiates, runs and shuts down the log server.

# The Includes

The implementation file includes the following header files:

• LwLogService.h - for the Lightweight Log Service
• lwlog\_i.h - the developer-written implementation header file declaring the log example’s implementation class, lwlog\_impl.

```c
#include "eOrb/EORB/LwLogService.h"
#include "lwlog_i.h"
```

A ‘usage’ message to list valid command-line arguments is provided:

```txt
static void usage ()
```

```txt
{
    printf ("Valid optional arguments :\n");
    printf (" -LogServiceEntryLocking &lt;on | off&gt; (default on)\n");
    printf (" -LogServiceMaxSize &lt;num&gt; (default 1024)\n");

#if EORB_USE_UIOP
    printf (" -LogServiceUIOP (default no)\n");
#endif
}
```

# Main

The main operation is defined using the Spectra ORB EORB\_MAIN macro, which is for code portability for systems without a main entry point.

The following essential variables are declared and given default values; a check for command-line arguments which over-ride these defaults is also performed.

• config - a PrismTech-specific structure holding values which determine certain aspects of the log’s behaviour
• ref - an object reference to the Log interface
• poa - a pointer to the ORB’s Portable Object Adapter instance
• oid - a pointer to the object id of the log servant associated with the POA instance, poa

# Log Initialisation

The log’s configuration structure, config, is initialised, followed by initialisation of the ORB, POA, log example implementation, and log service instance. The IOR for the log service is then published by registering it with the ORB as an initial reference. The Spectra ORB-specific Stdio and File plugins then ensure that this reference is both published to stdout and written to a file corresponding to the name of the registered reference. Note that the normal try-catch block has been replaced with the EORB\_TRY and EORB\_CATCH macros.

```cpp
orb = CORBA::ORB_init (argc, argv EORB_ENV_VARN);
EORB_CHECK_ENV;

CORBA::Object_var obj;
PortableServer::POA_var poa;
PortableServer::POA_var child;
CORBA::PolicyList poaPolicies (0);

obj = orb->resolve_initial_references ("RootPOA"
EORB_ENV_VARN);
poa = PortableServer::POA::_narrow (obj EORB_ENV_VARN);

child = poa->create_POA
(
    "LogService",
    PortableServer::POAManager::_nil (),
    poaPolicies
```

```cpp
EORB_ENV_VARN
);

ref = EORB::LwLogService::init (orb, child, config EORB_ENV_VARN);
EORB_CHECK_ENV;

orb->register_initial_reference ("LogService", ref EORB_ENV_VARN);
EORB_CHECK_ENV;

servant = new LwLog_Example_impl (orb.in());
EORB_CHECK_ENV;

oid = poa->activate_object (servant EORB_ENV_VARN);
EORB_CHECK_ENV;

LwLog_Example_var server = servant->_this (EORB_ENV_VAR1);
EORB_CHECK_ENV;

orb->register_initial_reference (
    "server",
    server
    EORB_ENV_VARN
);
EORB_CHECK_ENV;
```

The orb->run() operation is then executed, starting the event loop which waits for incoming requests from clients.

When the log service is stopped the ORB’s shutdown operation is called via the lwlog\_example\_impl’s shutdown() operation (defined in lwog\_i.cpp).

```c
orb->run (EORB_ENV_VAR1);
// Clean up
orb->destroy (EORB_ENV_VAR1);
EORB_CHECK_ENV;
}
EORB_CATCH (CORBA::Exception, exc)
{
    printf ("Exception: %s\n", exc._rep_id());
    return 1;
}
EORB_END_TRY
delete servant;
printf ("lwlog server complete\n");
return 0;
}
```

# 4.2 Client

The client code shown here demonstrates how to create a Lightweight Log Service client.

# Implementation

The client implementation file, client.cpp, imports the CosLwLogService.h header file. Instead of including the developer-written lwlog\_i.h header file, the client includes the IDL-generated lwlog.h file which contains the interface declarations needed by the client to connect, via the ORB and POA, to the log server implementation.

```c
#include "lwlog.h"
#include "CosLwLogService.h"
```

The starttime variable, type LogTime, is declared: starttime records the time, in seconds and nanoseconds, when a log record is created. This variable will be used by the example for retrieving records based on their creation time stamps.

```txt
static CosLwLog::LogTime starttime;
```

The printRecords() operation demonstrates how to obtain information about a sequence of log records by using CosLwLog::LogRecordSequence.

The LogRecordSequence subscript operator is used to obtain direct access to the buffer underlying the records sequence: this enables simple retrieval of each record’s id, log creation time and ProducerLogRecord (the info value) for each record held in the records sequence.

```cpp
static void printRecords (CosLwLog::LogRecordSequence * records)
{
    printf (" Recovered %d records\n\n", records->length());
    for (CORBA::ULong i = 0; i &lt; records-&gt;length(); i++)
    {
    CosLwLog::RecordId id = records->get_buffer ()[i].id;
    CosLwLog::LogTime time = records->get_buffer ()[i].time;
    CosLwLog::ProducerLogRecord info = records->get_buffer ()[i].info;

    printf (" RecordId : %d\n", (int) id);
    printf (" Time : %d secs %d nsecs\n", time.seconds, time.nanoseconds);

    printf (" Producer Id : %s\n", info.producerId.in());
    printf (" Producer Name : %s\n", info.producerName.in());
    printf (" Log Level : %d\n", info.level);
    printf (" Log Data : %s\n\n", info.logData.in());
    }
}
```

The client uses get\_current\_time to set starttime and thus synchronize itself w it h t h e s e r v e r. T h i s v a l u e i s u s e d b y t h e r e t r i e v e R e c o r d s a n d retrieveRecordsByProducerId operations to ensure that records with correct timestamps are retrieved.

```c
static void current_time (LwLog_Example_ptr server EORB_ENV_ARGN)
{
    starttime = server->get_current_time (EORB_ENV_VAR1);
    EORB_CHECK_ENV_RETURN_VOID;
}
```

The get\_status() operation demonstrates how to use the LogStatus interface to obtain a log’s current status.

T h e o p e r a t i o n s u ce s s i v e l y c a l l s t h e i n t e r f a ce ’s g e t \_ m a x \_ s i z e ( ) , get\_current\_size() and get\_n\_records() operations.1

```c
/*
 * get_status : all three of the CosLwlog object references are of
 * the type CosLwLog::LogStatus so can be used to call this operation
 * which prints the current statis of the log.
 */
static void get_status (CosLwLog::LogStatus * status EORB_ENV_ARGN)
{
    CORBA::ULongLong size;

    size = status->get_max_size (EORB_ENV_VAR1);
    EORB_CHECK_ENV_RETURN_VOID;

    printf (" Max Size : %d\n", (int) size);

    size = status->get_current_size (EORB_ENV_VAR1);
    EORB_CHECK_ENV_RETURN_VOID;

    printf (" Current Size : %d\n", (int) size);

    size = status->get_n_records (EORB_ENV_VAR1);
    EORB_CHECK_ENV_RETURN_VOID;

    printf (" Number of Records : %d\n\n", (int) size);
}
```

The writeRecords() operation demonstrates how the LogProducer interface can be used to add a sequence of log producer records to a log.

1. See interface LogStatus on page 16 for a complete list of available LogStatus operations.

After creating a sequence of producer log records, the operation creates a sequence of ProducerLogRecords. Each ProducerLogRecord, rec, is added to the sequence of ProducerLogRecords after being assigned producerId, producerName, log level, and logData values.

The completed ProducerLogRecords sequence is then written to the log using the ProducerLogRecords::write\_records() operation. The status of the log is subsequently obtained and printed.

```c
/*
 * writeRecords illustrates CosLwLog::LogProducer functionality
 */
static void writeRecords (CosLwLog::LogProducer * producer EORB_ENV_ARGN)
{
    CORBA::ULong size = 4;
    CosLwLog::ProducerLogRecordSequence records;
    records.length (size);

    printf ("\\nWriting %d records\n\n", size);

    /* Create the records */

    for (CORBA::ULong i = 0; i &lt; size; i++)
    {
    CosLwLog::ProducerLogRecord rec;
    char id[8];
    char data[16];

    sprintf (id, "ID %d", i);
    sprintf (data, "Data Entry %d", i);

    rec.producerId = CORBA::string_dup (id);
    rec.producerName = CORBA::string_dup ("LwLog Example");
    rec.level = (CORBA::UShort) i;
    rec.logData = CORBA::string_dup (data);

    records.get_buffer ()[i] = rec;
    }

    /* Write the records to the log */
    producer-&gt;write_records (records EORB_ENV_VARN);
    EORB_CHECK_ENV_RETURN_VOID;

    /* Print the status of the log */

    printf (" Current status\n");
    get_status (producer EORB_ENV_VARN);
    EORB_CHECK_ENV_RETURN_VOID;
}
```

The retrieveRecords() operation demonstrates how the LogConsumer interface can retrieve a sequence of log producer records from a log.

The variables used by the operation, as part of the retrieval process, are:

• LogRecordSequence records - structure which will hold the retrieved records
• RecordId id - variable holding the id value which will be used to identify the records to be retrieved
• howMany - an unsigned long specifiying the number of records which are to be retrieved (4 in this example) by the operation

```c
/*
 * retrieveRecords illustrates CosLwLog::LogConsumer
retrieve_records functionality
 */
static void retrieveRecords (CosLwLog::LogConsumer * consumer EORB_ENV_ARGN)
{
    CosLwLog::LogRecordSequence * records;
    CosLwLog::RecordId id;
    CORBA::ULong howMany = 4;

    printf("\nRetrieving records\n\n");

    /* Using the starttime saved during witeRecords operation
    * obtain the RecordId of the record that has a matching or
    * later timestamp */
    id = consumer->get_record_id_from_time (starttime EORB_ENV_VARN);
    EORB_CHECK_ENV_RETURN_VOID;

    /* Starting with the returned id retrieve the required number
    * of records from the log.
    */
    records = consumer->retrieve_records (id, howMany EORB_ENV_VARN);
    EORB_CHECK_ENV_RETURN_VOID;

    /* Display the results */
    printRecords (records);

    delete records;
}
```

The retrieveRecordsByProducerID() operation shows how the LogConsumer interface can selectively retrieve a log record using its producer id and the time the record was created.

```cpp
/*
 * retrieveRecordsByProducerId illustrates CosLwLog::LogConsumer
 * retrieve_records_by_producer_id functionality where only records
 * with a matching producer id to that in vals will be returned.
 * The other consumer retrieve operations are similar to this one.
 */
static void retrieveRecordsByProducerId
(
    CosLwLog::LogConsumer * consumer
    EORB_ENV_ARGN
)
{
    CosLwLog::LogRecordSequence * records;
```

```c
CosLwLog::RecordId id;
CORBA::ULong howMany = 4;
CosLwLog::StringSeq vals;

printf("\nRetrieving records by producer id\n\n");

vals.length (1);
vals[0] = CORBA::string_dup("ID 1");

/* Using the starttime saved during witeRecords operation
* obtain the RecordId of the record that has a matching or
* later timestamp */
id = consumer->get_record_id_from_time (starttime EORB_ENV_VARN);
EORB_CHECK_ENV_RETURN_VOID;

/* Starting with the returned id retrieve the required number
* of records from the log that also have a matching producer id.
* In this case 4 records are requested but only one will be returned.
*/
records = consumer->retrieve_records_by_producer_id
(
    id,
    howMany,
    vals
    EORB_ENV_VARN
);
EORB_CHECK_ENV_RETURN_VOID;

/* Display the results */
printRecords (records);

delete records;
}
```

The client’s main function is implemented using the Spectra ORB EORB\_MAIN macro. The main function performs initialisations and declarations (including the ORB and Log objects). Main then runs the operations, described above, which demonstrate the various Log operations.

```cpp
EORB_MAIN (client)
{
    EORB_DECLARE_ENV;

    printf ("LwLog client starting\n\n");

    EORB::Plugin::IIOP::add();

    EORB_TRY
    {
    CORBA::ORB_var orb;
    CORBA::Object_var obj;
    LwLog_Example_var server;
    CosLwLog::Log_var log;

    /* initialise the Orb */
```

```c
orb = CORBA::ORB_init (argc, argv EORB_ENV_VARN);
EORB_CHECK_ENV;

obj = orb->resolve_initial_references ("server" EORB_ENV_VARN);
EORB_CHECK_ENV;

server = LwLog_Example::_narrow (obj EORB_ENV_VARN);
EORB_CHECK_ENV;

/* Initialise the administartor object reference */

obj = orb->resolve_initial_references ("LogService" EORB_ENV_VARN);
EORB_CHECK_ENV;

log = CosLwLog::Log::_narrow (obj EORB_ENV_VARN);
EORB_CHECK_ENV;

/* Get the empty status of the log using the administrator */

printf (" Default status\n");
get_status (log EORB_ENV_VARN);
EORB_CHECK_ENV;

/* Obtain the server's current time */

current_time (server EORB_ENV_VARN);
EORB_CHECK_ENV;

/* Write and read records */

writeRecords (log EORB_ENV_VARN);
EORB_CHECK_ENV;

retrieveRecords (log EORB_ENV_VARN);
EORB_CHECK_ENV;

retrieveRecordsByProducerId (log EORB_ENV_VARN);
EORB_CHECK_ENV;

/* Clear the log of all the records */

log->clear_log (EORB_ENV_VAR1);
EORB_CHECK_ENV;

/* Get the now empty status of the log using the administrator */

printf (" Final status\n");
get_status (log EORB_ENV_VARN);
EORB_CHECK_ENV;

/* Destroy the log */

log->destroy (EORB_ENV_VAR1);
EORB_CHECK_ENV;

server->shutdown (EORB_ENV_VAR1);

// Clean up
```

```c
orb->destroy (EORB_ENV_VAR1);
EORB_CHECK_ENV;
}
EORB_CATCH (CORBA::Exception, exc)
{
    printf ("Exception: %s\n", exc._rep_id());
}
EORB_END_TRY
printf ("LwLog client complete\n");
return 0;
}
```

# INDEX

# I n d e x

# A

AdministrativeState . . . . . 13

# C

clear\_log . . . . . . . . 22

# D

destroy . . . . 22

# G

get\_administrative\_state . . . . . 16

get\_availability\_status . . . . 16

get\_current\_size . . . 16

get\_log\_full\_action. . . . 16

get\_max\_size . . . 16

get\_n\_records . . 17

get\_operational\_state . . . . 17

get\_record\_id\_from\_time. . . . 18

# I

InvalidParam. . . . 24

# L

LogAdministrator . . . . 22

LogConsumer . . . . . 18

LogFullAction . . . . . 13

LogLevel. . . . . 12

LogLevelSequence . . . . . 12

LogProducer . . . . . 17

LogRecordSequence. . . . . . 12

LogStatus . . . . . 16

LogTime . . . . . 15

# M

module CosLwLog . . . . . . . . 17

# O

OperationalState . . . . 13

# P

ProducerLogRecord . . . . . . 15

ProducerLogRecordSequence . . . . . . . . . . . 12

# R

RecordId . . . 12

retrieve\_records . . . 19

retrieve\_records\_by\_level . . 19

retrieve\_records\_by\_producer\_id . . . . . . . . . . . 20

retrieve\_records\_by\_producer\_name . . . . . . . . 21

Running from the Command Line . . . . . . . 27

# S

set\_administrative\_state . . . . . . 23

set\_log\_full\_action . . . 23

set\_max\_size . . . 23

StringSeq . . . . 13

# W

write\_record . 17

write\_records. . 18
[🔗 Link to the original document](.spectra-orb-c-edition-lightweight-log-service-user-guide-2/spectra-orb-c-edition-lightweight-log-service-user-guide.pdf)
