/* Data provider. Copyright (C) 2001 Johan Rydberg. All Rights Reserved. This file is part of Crust. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __CoreFoundation_CFDataProvider_h #define __CoreFoundation_CFDataProvider_h #include #include /* A data provider is a way to supply data to a source in a I/O transparent way. Callbacks are used to fetch data. Standard data providers for file I/O is provided. */ struct CFDataProviderCallbacks { /* Reads COUNT bytes from provider into BUFFER. Number of bytes read is returned. Returns 0 if we have reached the end of the stream. */ int (*get_bytes) (void *arg, void *buffer, int count); /* Skip COUNT bytes in stream. */ void (*skip_bytes) (void *arg, int count); /* Rewind stream to start. Return zero on succes. */ void (*rewind) (void *arg); /* We are done with the provider. Closes the stream. */ void (*release) (void *arg); }; typedef struct CFDataProviderCallbacks CFDataProviderCallbacks; /* Opaque type for a data provider reference. */ typedef struct CFDataProvider *CFDataProviderRef; /* Create a custom data provider with CALLBACKS. A reference to the data provider is returned. */ CF_EXTERN CFDataProviderRef CFDataProviderCreate (CFDataProviderCallbacks *callbacks, void *callback_arg); /* Release a reference to PROVIDER. */ CF_EXTERN void CFDataProviderRelease (CFDataProviderRef provider); /* Retain a reference to PROVIDER. */ CF_EXTERN void CFDataProviderRetain (CFDataProviderRef provider); /* Create a file I/O data provider for FILE_NAME. A reference to the data provider is returned. */ CF_EXTERN CFDataProviderRef CFDataProviderCreateFromFile (const char *file_name); /* Read N bytes of data from PROVIDER. Returns number of bytes read, or zero if we have reached the end of the stream. */ CF_EXTERN int CFDataProviderRead (CFDataProviderRef provider, void *buffer, int n); /* Rewind PROVIDER stream. */ CF_EXTERN void CFDataProviderRewind (CFDataProviderRef provider); /* Skip N bytes in PROVIDER stream. */ CF_EXTERN void CFDataProviderSkipBytes (CFDataProviderRef provider, int n); #endif /* CFDataProvider.h */