MemoryCache Class Reference

List of all members.


Detailed Description

Class to provide read/write cache services to a 1-Wire memory device.

Writes are only performed when this classes sync() method is called. Provides page bitmap services for OTP devices.

Objectives:

Author:
DS
Version:
0.01, 1 June 2001
See also:
com.dalsemi.onewire.application.file.OWFile

com.dalsemi.onewire.application.file.OWFileDescriptor

com.dalsemi.onewire.application.file.OWFileInputStream

com.dalsemi.onewire.application.file.OWFileOutputStream


Public Member Functions

 MemoryCache (OneWireContainer device)
 Construct a new memory cache for provided 1-wire container device.
 MemoryCache (OneWireContainer[] devices)
 Construct a new memory cache for provided 1-wire container device.
int getNumberPages ()
 Gets the number of pages in this cache.
int getNumberPagesInBank (int bankNum)
 Gets the number of pages in the specified bank number.
int getPageOffsetForDevice (int deviceNum)
 Gets the page number of the first page on the specified device.
int getMaxPacketDataLength ()
 Gets the maximum number of bytes for data in each page.
boolean isWriteOnce ()
 Check if this memory device is write-once.
int readPagePacket (int page, byte[] readBuf, int offset) throws OneWireIOException, OneWireException
 Read a page packet.
void writePagePacket (int page, byte[] writeBuf, int offset, int buflen) throws OneWireIOException, OneWireException
 Write a page packet into the cache.
void sync () throws OneWireIOException, OneWireException
 Flush the pages written back to the 1-Wire device.
void addOwner (Object tobj)
 Add an owner to this memory cache.
void removeOwner (Object tobj)
 Remove the specified owner of this memory cache.
boolean noOwners ()
 Check to see if there on no owners of this memory cache.
void removeWriteOpen (String filePath)
 Remove the provided filePath from the list of files currently opened to write.
boolean isOpenedToWrite (String filePath, boolean addToList)
 Check to see if the provided filePath is currently opened to write.
boolean handlePageBitmap ()
 Check to see if this memory cache should handle the page bitmap.
void markPageUsed (int page)
 Mark the specified page as used in the page bitmap.
boolean freePage (int page)
 free the specified page as being un-used in the page bitmap
int getFirstFreePage ()
 Get the first free page from the page bitmap.
int getNextFreePage ()
 Get the next free page from the page bitmap.
int getNumberFreePages () throws OneWireException
 Get the total number of free pages in this Filesystem.
int getBitMapPageNumber ()
 Gets the page number used in the remote page bitmap in an OTP device.
int getBitMapNumberOfPages ()
 Get the number of pages used for the remote page bitmap in an OTP device.
PagedMemoryBank getMemoryBankForPage (int page)
 Get's the memory bank object for the specified page.
int getLocalPage (int page)
 Get's the local page number on the memory bank object for the specified page.
void clearLastPageRead ()
 Clears the lastPageRead global so that a readPage will not try to continue where the last page left off.

Constructor & Destructor Documentation

MemoryCache ( OneWireContainer  device  ) 

Construct a new memory cache for provided 1-wire container device.

Parameters:
device 1-Wire container

MemoryCache ( OneWireContainer[]  devices  ) 

Construct a new memory cache for provided 1-wire container device.

Parameters:
device 1-Wire container


Member Function Documentation

int getNumberPages (  ) 

Gets the number of pages in this cache.

Returns:
number of pages in the cache

int getNumberPagesInBank ( int  bankNum  ) 

Gets the number of pages in the specified bank number.

Parameters:
bankNum bank number to retrieve number of pages
Returns:
number of pages in the bank

int getPageOffsetForDevice ( int  deviceNum  ) 

Gets the page number of the first page on the specified device.

If the device number is not valid then return 0.

Parameters:
deviceNum device number to retrieve page offset
Returns:
page number of first page on device

int getMaxPacketDataLength (  ) 

Gets the maximum number of bytes for data in each page.

Returns:
max number of data bytes per page

boolean isWriteOnce (  ) 

Check if this memory device is write-once.

If this is true then the page bitmap facilities in this class will be used.

Returns:
true if this device is write-once

int readPagePacket ( int  page,
byte[]  readBuf,
int  offset 
) throws OneWireIOException, OneWireException

Read a page packet.

If the page is available in the cache then return that data.

Parameters:
page page to read
readBuf buffer to place the data in
offset offset into the read buffer
Returns:
the number byte in the packet
Exceptions:
OneWireException when the adapter is not setup properly
OneWireIOException when an 1-Wire IO error occures

void writePagePacket ( int  page,
byte[]  writeBuf,
int  offset,
int  buflen 
) throws OneWireIOException, OneWireException

Write a page packet into the cache.

Parameters:
page page to write
writeBuf buffer container the data to write
offset offset into write buffer
buflen length of data to write

void sync (  )  throws OneWireIOException, OneWireException

Flush the pages written back to the 1-Wire device.

Exceptions:
OneWireException when the adapter is not setup properly
OneWireIOException when an 1-Wire IO error occures

void addOwner ( Object  tobj  ) 

Add an owner to this memory cache.

This will be tracked for later cleanup.

Parameters:
tobj owner of instance

void removeOwner ( Object  tobj  ) 

Remove the specified owner of this memory cache.

Parameters:
tobj owner of instance

boolean noOwners (  ) 

Check to see if there on no owners of this memory cache.

Returns:
true if not owners of this memory cache

void removeWriteOpen ( String  filePath  ) 

Remove the provided filePath from the list of files currently opened to write.

Parameters:
filePath file to remove from write list

boolean isOpenedToWrite ( String  filePath,
boolean  addToList 
)

Check to see if the provided filePath is currently opened to write.

Optionally add it to the list if it not already there.

Parameters:
filePath file to check to see if opened to write
addToList true to add file to list if not present
Returns:
true if file was not in the opened to write list

boolean handlePageBitmap (  ) 

Check to see if this memory cache should handle the page bitmap.

Returns:
true if this memory cache should handle the page bitmap

void markPageUsed ( int  page  ) 

Mark the specified page as used in the page bitmap.

Parameters:
page number to mark as used

boolean freePage ( int  page  ) 

free the specified page as being un-used in the page bitmap

Parameters:
page number to mark as un-used
Returns:
true if the page as be been marked as un-used, false if the page is on an OTP device and cannot be freed

int getFirstFreePage (  ) 

Get the first free page from the page bitmap.

Returns:
first page number that is free to write

int getNextFreePage (  ) 

Get the next free page from the page bitmap.

Returns:
next page number that is free to write

int getNumberFreePages (  )  throws OneWireException

Get the total number of free pages in this Filesystem.

Returns:
number of pages free
Exceptions:
OneWireException when an IO exception occurs

int getBitMapPageNumber (  ) 

Gets the page number used in the remote page bitmap in an OTP device.

Returns:
page number used in the directory for the remote page bitmap

int getBitMapNumberOfPages (  ) 

Get the number of pages used for the remote page bitmap in an OTP device.

Returns:
number of pages used in page bitmap

PagedMemoryBank getMemoryBankForPage ( int  page  ) 

Get's the memory bank object for the specified page.

This is significant if the Filesystem spans memory banks on the same or different devices.

int getLocalPage ( int  page  ) 

Get's the local page number on the memory bank object for the specified page.

This is significant if the Filesystem spans memory banks on the same or different devices.

void clearLastPageRead (  ) 

Clears the lastPageRead global so that a readPage will not try to continue where the last page left off.

This should be called anytime exclusive access to the 1-Wire canot be guaranteed.


The documentation for this class was generated from the following file:

Generated on Thu Aug 28 15:42:30 2008 for 1-Wire API for .NET by  doxygen 1.5.6