?? corbaclient.c,v
字號:
@d1 6
a12 7
/* Include the functions needed to support non-client/server version? */
/*
DVD Store Application Reference API Implementation
This file contains definitions of functions conforming
to the DVD Store application database APIs.
*/
a13 2
/* Prototypes -- as in dvd.h */
/* Some prototypes... */
d74 1
a74 1
CORBA_exception_id(&ev));
d81 1
a81 1
CORBA_exception_id(&ev));
d89 1
a89 1
CORBA_exception_id(&ev));
d97 1
a97 1
CORBA_exception_id(&ev));
d105 1
a105 1
CORBA_exception_id(&ev));
d113 1
a113 1
CORBA_exception_id(&ev));
d144 1
a144 1
CORBA_exception_id(&ev));
d154 1
a154 1
int rc;
d165 4
a168 3
printf("Got CORBA exception %d/%d from DVD_MEMBERSHIP_get", ev._major,
CORBA_exception_value(&ev));
return (int) DVD_ERR_NOT_FOUND;
d172 1
a172 1
return (int) DVD_ERR_NOT_FOUND;
d231 1
a231 1
CORBA_exception_id(&ev));
d242 1
a242 1
int rc;
d254 1
a254 1
CORBA_exception_value(&ev));
d280 1
a280 1
CORBA_exception_value(&ev));
d309 1
a309 1
CORBA_exception_id(&ev));
d357 1
a357 1
CORBA_exception_id(&ev));
d380 1
a380 1
CORBA_exception_value(&ev));
d438 1
a438 1
CORBA_exception_id(&ev));
d448 1
a448 1
int rc;
d461 1
a461 1
CORBA_exception_value(&ev));
d480 1
a480 1
CORBA_exception_id(&ev));
d516 1
a516 1
CORBA_exception_id(&ev));
d525 2
a526 2
DVD_DISKS_dvddisks *cdisk;
int rc;
d531 1
d534 2
a535 2
case CORBA_NO_EXCEPTION:
rc = 0;
d539 1
a539 1
CORBA_exception_value(&ev));
d545 1
a545 2
CORBA_exception_free(&ev);
if (rc != 0) /* If we had an exception above... */
d547 1
d550 1
a550 1
if(disk_id != cdisk->diskid)
d552 2
a553 3
diskout->disk_id = cdisk->diskid;
diskout->title_id = cdisk->titleid;
CORBA_free(cdisk);
d574 1
a574 1
CORBA_exception_id(&ev));
d586 1
a586 1
int rc;
d599 1
a599 1
CORBA_exception_value(&ev));
d618 1
a618 1
CORBA_exception_id(&ev));
d652 2
a653 2
printf("Got CORBA exception %d/%d from DVD_DISKS_delete", ev._major,
CORBA_exception_value(&ev));
d672 4
a675 4
DVD_MEMBERSHIP_memberidt *memberid;
DVD_datec *daterented;
int rc;
DVD_RENTAL_rentdiskinfo(rental, disk_id, &memberid, daterented,
d680 1
a680 1
*member_id = *memberid;
d686 1
a686 1
ev._major, CORBA_exception_value(&ev));
d713 1
a713 1
ev._major, CORBA_exception_value(&ev));
d739 1
a739 1
ev._major, CORBA_exception_value(&ev));
d762 1
a762 1
ev._major, CORBA_exception_value(&ev));
d788 1
a788 1
ev._major, CORBA_exception_value(&ev));
d822 1
a822 1
CORBA_exception_id(&ev));
d837 1
a837 1
CORBA_exception_id(&ev));
d857 1
a857 1
CORBA_exception_id(&ev));
d872 1
a872 1
CORBA_exception_id(&ev));
@
1.4
log
@Added Titling, started on Disks
@
text
@a7 18
#define LEGACY 1
#ifdef LEGACY
#include "flatfileold.h" /* All the flat file support */
static int file_set(FILE *file, long file_position, int size, void *data);
#endif
/* Internal data structures for reservations and rentals */
typedef struct _reservation_struct {
int member_id;
int title_id;
char date[9];
} dvd_reserve;
typedef struct _rental_struct {
int disk_id;
int member_id;
char date[9];
} dvd_rental;
a12 1
a18 7
/* Implementation */
static int dvd_rental_set(int disk_id, dvd_rental *rental);
static int dvd_reserve_set(int member_id, dvd_reserve *reserve);
/* Database definitions */
a19 1
d30 94
d146 1
a146 1
g_error("Got CORBA exception %d/%s", ev._major,
d168 1
a168 1
g_error("Got CORBA exception %d/%d from DVD_MEMBERSHIP_get", ev._major,
d232 1
a232 1
g_error("Got CORBA exception %d/%s", ev._major,
d234 2
a235 1
return DVD_SUCCESS;
d255 1
a255 1
g_error("Got CORBA exception %d/%d from DVD_MEMBERSHIP_delete", ev._major,
d269 1
a269 1
int rc;
d278 2
a279 1
return DVD_SUCCESS;
d281 1
a281 1
g_error("Got CORBA exception %d/%d from DVD_MEMBERSHIP_delete", ev._major,
d283 2
a284 1
return DVD_ERR_NOT_FOUND;
d289 2
a290 1
return DVD_ERR_NOT_FOUND;
d293 2
a294 1
return DVD_ERR_NOT_FOUND;
d297 3
d306 1
a306 1
int *results = NULL, i;
d310 1
a310 1
g_error("Got CORBA exception %d/%s\n", ev._major,
d312 1
a312 1
return DVD_ERR_NOT_FOUND;
d314 1
d317 4
a320 1
results=calloc(CList->_length, sizeof(int));
d358 1
a358 1
g_error("Got CORBA exception %d/%s", ev._major,
d360 1
d368 1
a368 1
int err = DVD_SUCCESS;
d378 1
a378 1
err = 0;
d381 1
a381 1
g_error("Got CORBA exception %d/%d from DVD_TITLING_get", ev._major,
d383 2
a384 1
return (int) DVD_ERR_NOT_FOUND;
d387 2
a388 1
return (int) DVD_ERR_NOT_FOUND;
d390 3
a392 2
if (err != 0) /* If we had an exception above... */
return err;
d409 1
d437 1
d439 1
a439 1
g_error("Got CORBA exception %d/%s", ev._major,
d441 1
d449 1
a449 1
DVD_TITLING_titlet t;
d452 1
a452 1
t = title_id;
d459 2
a460 1
return DVD_SUCCESS;
d462 1
a462 1
g_error("Got CORBA exception %d/%d from DVD_TITLING_delete", ev._major,
d481 1
a481 1
g_error("Got CORBA exception %d/%s\n", ev._major,
d483 1
d517 1
a517 1
g_error("Got CORBA exception %d/%s", ev._major,
d525 1
a525 1
int dvd_disk_get(int disk_id, dvd_disk *disk_record_to_complete)
d527 3
a529 2
int err = DVD_SUCCESS;
if(disk_record_to_complete == NULL)
d531 26
a556 18
err = file_get(disk_file,
sizeof(dvd_disk) * disk_id,
sizeof(dvd_disk),
(void *) disk_record_to_complete);
/* If we cannot get the disk there may be an error
with the data, or the title may not exist */
if(err != DVD_SUCCESS)
return err;
/* If the retrieved disk id is not as expected there
may be an error, or the disk may be deleted */
if(disk_record_to_complete -> disk_id == 0)
return DVD_ERR_NOT_FOUND;
if(disk_id != disk_record_to_complete -> disk_id)
return DVD_ERR_BAD_MEMBER_TABLE;
d560 1
a560 1
int dvd_disk_create(dvd_disk *disk_record_to_add, int *disk_id)
d562 20
a581 30
int err;
dvd_disk new_disk;
dvd_rental null_rental;
/* Make a new disk record. See also notes in member_create.
Ought really to check that the title_id is valid, but
then again it can be invalidated independently anyway.
*/
/* Take a copy of the passed member, in case it is static */
new_disk = *disk_record_to_add;
/* The new disk_id is the next available id */
new_disk.disk_id = disk_count;
/* Add the new disk to the disk file and the rentals file */
err = dvd_disk_set(&new_disk);
if(err != DVD_SUCCESS)
return err;
memset((void *) &null_rental, 0, sizeof(dvd_rental));
null_rental.disk_id = new_disk.disk_id;
null_rental.member_id = 0;
err = dvd_rental_set(null_rental.disk_id, &null_rental);
if(err != DVD_SUCCESS)
return err;
/* Update disk file state */
*disk_id = disk_count;
disk_count++;
d587 23
a609 8
/* Delete a disk by setting the disk_id to zero */
dvd_disk null_disk;
memset((void *)&null_disk, 0, sizeof(null_disk));
return file_set(disk_file,
disk_id * sizeof(null_disk),
sizeof(null_disk),
&null_disk);
d614 22
a635 27
/* Search for disks of a particular title */
dvd_disk a_disk;
int id = 1;
int matches = 0;
int *results = NULL;
int results_size = 0;
int err;
*count = 0;
while(err = dvd_disk_get(id, &a_disk),
err == DVD_SUCCESS || err == DVD_ERR_NOT_FOUND) {
if(err == DVD_SUCCESS && a_disk.disk_id != 0) {
/* Valid record */
if(title_id == a_disk.title_id) {
/* Add a result to the list */
/* Increase capacity if required */
if(matches >= results_size) {
results_size += 4;
results = (int *)realloc(results, sizeof(int)*results_size);
if(results == NULL)
return DVD_ERR_NO_MEMORY;
}
results[matches] = a_disk.disk_id;
matches++;
}
}
id++;
d637 1
d639 2
a640 44
*count = matches;
return DVD_SUCCESS;
}
/*
Rentals and Reservation Scheme
Add another table that mirrors the disk table, but contains
a member_id field (if rented) and a date rented.
*/
/* Helper functions */
static int dvd_rental_set(int disk_id, dvd_rental *rental)
{
if(rental == NULL)
return DVD_ERR_NULL_POINTER;
return
file_set(rental_file,
sizeof(dvd_rental) * (rental -> disk_id),
sizeof(dvd_rental),
(void *) rental);
}
static int dvd_rental_get(int disk_id, dvd_rental *rental)
{
int err = DVD_SUCCESS;
if(rental == NULL)
return DVD_ERR_NULL_POINTER;
err = file_get(rental_file,
sizeof(dvd_rental) * disk_id,
sizeof(dvd_rental),
(void *) rental);
if(err != DVD_SUCCESS)
return err;
if(disk_id != rental -> disk_id)
return DVD_ERR_BAD_RENTAL_TABLE;
a643 38
static int dvd_reserve_set(int member_id, dvd_reserve *reserve)
{
if(reserve == NULL)
return DVD_ERR_NULL_POINTER;
return file_set(reserve_file,
sizeof(dvd_reserve) * (reserve -> member_id),
sizeof(dvd_reserve),
(void *) reserve);
}
static int dvd_reserve_get(int member_id, dvd_reserve *reserve)
{
int err = DVD_SUCCESS;
if(reserve == NULL)
return DVD_ERR_NULL_POINTER;
err = file_get(reserve_file,
sizeof(dvd_reserve) * member_id,
sizeof(dvd_reserve),
(void *) reserve);
if(err != DVD_SUCCESS)
return err;
if(member_id != reserve -> member_id)
return DVD_ERR_BAD_RENTAL_TABLE;
return DVD_SUCCESS;
}
/*
To rent a single title we need to find a disk of that title
and tell the owner which one to give the customer. BUT, we
must ensure that we do not have too many reservations for
this date for that title already.
*/
d646 18
a663 46
int count;
char *date;
int err;
dvd_disk disk;
dvd_rental rental;
dvd_reserve reserve;
int disk_id;
(void) dvd_today(&date);
/* See if there is a reservation for today, and clear it */
err = dvd_reserve_get(member_id, &reserve);
if(err != DVD_SUCCESS)
return err;
if(reserve.title_id == title_id &&
strcmp(date, reserve.date)) {
reserve.title_id = 0;
dvd_reserve_set(member_id, &reserve);
}
/* Check that there is a copy available (including reservations) */
err = dvd_title_available(title_id, date, &count);
if(err != DVD_SUCCESS)
return err;
if(count <= 0)
return DVD_ERR_NOT_FOUND;
/* Add an entry to the rental table and return allocated disk id */
for(disk_id = 1; disk_id < disk_count; disk_id++) {
err = dvd_disk_get(disk_id, &disk);
if(err == DVD_SUCCESS && title_id == disk.title_id) {
/* See if this copy is already out */
err = dvd_rental_get(disk_id, &rental);
if(err != DVD_SUCCESS)
return err;
if(rental.member_id == 0) {
rental.member_id = member_id;
strcpy(rental.date, date);
err = dvd_rental_set(disk_id, &rental);
if(err != DVD_SUCCESS)
return err;
*disk_id_to_rent = disk_id;
return DVD_SUCCESS;
}
}
d665 5
a669 1
return DVD_ERR_NOT_FOUND;
d674 24
a697 14
/* Lookup the disk in the rental table and return the details */
/* The user can get the title from dvd_disk_get */
dvd_rental rental;
int err;
err = dvd_rental_get(disk_id, &rental);
if(err != DVD_SUCCESS)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -