Urgent !!!!! please help me to uderstand this code if possible today.

P

Pravin Shetty

Hello to All,
I have interview 2moro.I need to explain this code and
i'm not getting this properly.I don't know what to do?
Please help me.


Requirement:

1) Look at ansc_tso_interface.h, and understand the definitions of
ANSC_TIMER_SCHEDULER_OBJECT,
ANSC_TIMER_DESCRIPTOR_OBJECT
and ANSC_TDO_CLIENT_OBJECT
2) Read the function: AnscTsoCancelTimer. Explain the functions line
by line
in person. You don't need to write down anything.
3) Explain to me the relationship between the
ANSC_TIMER_DESCRIPTOR_OBJECT and ANSC_TIMER_SCHEDULER_OBJECT in
person.

/**********************************************************************

module: ansc_co_interface.h

For Advanced Networking Service Container (ANSC),
BroadWay Service Delivery System

---------------------------------------------------------------
description:
This wrapper file defines the base class data structure and
interface for the general Ansc Component Objects.
---------------------------------------------------------------
environment:
platform independent
---------------------------------------------------------------

**********************************************************************/


#ifndef _ANSC_CO_INTERFACE_
#define _ANSC_CO_INTERFACE_


/***********************************************************
GENERAL NSM FUNCTION OBJECT DEFINITION
***********************************************************/

/*
* Define some const values that will be used in the container object
definition.
*/
#define ANSC_COMPONENT_OBJECT_NAME
"abstractComponentObject"
#define ANSC_COMPONENT_OBJECT_ID 0xFFFFFFFF

/*
* Since we write all kernel modules in C (due to better performance
and lack of compiler support),
* we have to simulate the C++ object by encapsulating a set of
functions inside a data structure.
*/
typedef ANSC_HANDLE
(*PFN_ANSCCO_CREATE)
(
ANSC_HANDLE hContainerContext,
ANSC_HANDLE hOwnerContext,
ANSC_HANDLE hAnscReserved
);

typedef ANSC_STATUS
(*PFN_ANSCCO_REMOVE)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_ANSCCO_ENROLL_OBJECTS)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_ANSCCO_INITIALIZE)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_HANDLE
(*PFN_ANSCCO_GET_OWNER)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_ANSCCO_SET_OWNER)
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hOwner
);

typedef char*
(*PFN_ANSCCO_GET_NAME)
(
ANSC_HANDLE hThisObject
);

typedef ULONG
(*PFN_ANSCCO_GET_OID)
(
ANSC_HANDLE hThisObject
);

typedef ULONG
(*PFN_ANSCCO_GET_RID)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_ANSCCO_DISPATCH_EVENT)
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hEvent
);

/*
* The Component Objects are the extensions to the basic container.
Any software module that is
* shared between two or more extension objects or controller objects
shall be implemented as a
* Container Object. The container itself actually can leverage some
of functionalities provided
* by the Container Objects.
*/
#define ANSCCO_CLASS_CONTENT
\
/* start of object class content */
\
SINGLE_LINK_ENTRY Linkage;
\
ANSC_HANDLE hContainerContext;
\
ANSC_HANDLE hOwnerContext;
\
char Name[ANSC_OBJECT_NAME_SIZE];
\
ULONG Oid;
\
ULONG Rid;
\

\
PFN_ANSCCO_CREATE Create;
\
PFN_ANSCCO_REMOVE Remove;
\
PFN_ANSCCO_ENROLL_OBJECTS EnrollObjects;
\
PFN_ANSCCO_INITIALIZE Initialize;
\
PFN_ANSCCO_GET_OWNER GetOwner;
\
PFN_ANSCCO_SET_OWNER SetOwner;
\
PFN_ANSCCO_GET_NAME GetName;
\
PFN_ANSCCO_GET_OID GetOid;
\
PFN_ANSCCO_GET_RID GetRid;
\
PFN_ANSCCO_DISPATCH_EVENT DispatchEvent;
\
/* end of object class content */
\

typedef struct
_ANSC_COMPONENT_OBJECT
{
ANSCCO_CLASS_CONTENT
}
ANSC_COMPONENT_OBJECT, *PANSC_COMPONENT_OBJECT;

#define ACCESS_ANSC_COMPONENT_OBJECT(p) \
ACCESS_CONTAINER(p, ANSC_COMPONENT_OBJECT, Linkage)


#endif



/**********************************************************************

module: ansc_tso_interface.h

For Advanced Networking Service Container (ANSC),
BroadWay Service Delivery System

description:

This wrapper file defines all the platform-independent
functions and macros related to timer scheduling operation.

---------------------------------------------------------------
environment:

platform independent
revision:

10/14/01 initial revision.

**********************************************************************/


#ifndef _ANSC_TSO_INTERFACE_
#define _ANSC_TSO_INTERFACE_


/*
* This object is derived a virtual base object defined by the
underlying framework. We include the
* interface header files of the base object here to shield other
objects from knowing the derived
* relationship between this object and its base class.
*/
#include "ansc_co_interface.h"
#include "ansc_co_external_api.h"
#include "ansc_cover3_interface.h"
#include "ansc_cover3_external_api.h"


/***********************************************************
PLATFORM INDEPENDENT TIMER SCHEDULER OBJECT DEFINITION
***********************************************************/

/*
* Define some const values that will be used in the object mapper
object definition.
*/
#define ANSC_TSO_SCHEDULING_UNIT 10
#define ANSC_TSO_TASK_CLEANUP_TIME 5000

/*
* Since we write all kernel modules in C (due to better performance
and lack of compiler support),
* we have to simulate the C++ object by encapsulating a set of
functions inside a data structure.
*/
typedef ANSC_STATUS
(*PFN_TSO_RESET)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TSO_SCHEDULE)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TSO_START)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TSO_STOP)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TSO_REGISTER_TIMER)
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hTimerDescriptor
);

typedef ANSC_STATUS
(*PFN_TSO_CANCEL_TIMER)
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hTimerDescriptor
);

typedef ANSC_STATUS
(*PFN_TSO_SCHEDULE_TIMER)
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hTimerDescriptor
);

/*
* Most policy configuration information is stored and transmitted in
xml format. Compared to our
* proprietary al_store based configuration format, xml not only
provides more flexible and
* powerful hierarchical structure, it can also be translated into
other data format, such as html,
* very easily via XSLT (eXtensible Stylesheet Language
Transformation). This Xml Parser Object
* takes a xml-based data stream as input, and exposes a read/write
interface similar to al_store.
*/
#define ANSC_TIMER_SCHEDULER_CLASS_CONTENT
\
/* duplication of the base object class content */
\
ANSCCO_VER3_CLASS_CONTENT
\
/* start of object class content */
\
ULONG SchedulingUnit;
\
ANSC_HANDLE hCurInvokedTdo;
\
BOOL bStarted;
\

\
ANSC_EVENT SchedulerEvent;
\
ANSC_TS_LOCK SyncTsLock;
\
QUEUE_HEADER TdoQueue;
\
ANSC_LOCK TdoQueueLock;
\

\
PFN_TSO_RESET Reset;
\
PFN_TSO_SCHEDULE ScheduleTask;
\
PFN_TSO_START Start;
\
PFN_TSO_STOP Stop;
\

\
PFN_TSO_REGISTER_TIMER RegisterTimer;
\
PFN_TSO_CANCEL_TIMER CancelTimer;
\
PFN_TSO_SCHEDULE_TIMER ScheduleTimer;
\
/* end of object class content */
\

typedef struct
_ANSC_TIMER_SCHEDULER_OBJECT
{
ANSC_TIMER_SCHEDULER_CLASS_CONTENT
}
ANSC_TIMER_SCHEDULER_OBJECT, *PANSC_TIMER_SCHEDULER_OBJECT;

#define ACCESS_ANSC_TIMER_SCHEDULER_OBJECT(p) \
ACCESS_CONTAINER(p, ANSC_TIMER_SCHEDULER_OBJECT, Linkage)


/***********************************************************
PLATFORM INDEPENDENT TIMER DESCRIPTOR OBJECT DEFINITION
***********************************************************/

/*
* Define some const values that will be used in the object descriptor
object definition.
*/
#define ANSC_TIMER_TYPE_PERIODIC 1
#define ANSC_TIMER_TYPE_SPORADIC 2

/*
* Since we write all kernel modules in C (due to better performance
and lack of compiler support),
* we have to simulate the C++ object by encapsulating a set of
functions inside a data structure.
*/
typedef ANSC_HANDLE
(*PFN_TDO_GET_CONTEXT)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_SET_CONTEXT)
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hContext
);

typedef ULONG
(*PFN_TDO_GET_ULONG)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_SET_ULONG)
(
ANSC_HANDLE hThisObject,
ULONG ulValue
);

typedef BOOL
(*PFN_TDO_GET_BOOL)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_SET_BOOL)
(
ANSC_HANDLE hThisObject,
BOOL bValue
);

typedef ANSC_STATUS
(*PFN_TDO_ACQUIRE)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_RELEASE)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_START)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_STOP)
(
ANSC_HANDLE hThisObject
);

typedef ANSC_STATUS
(*PFN_TDO_INVOKE)
(
ANSC_HANDLE hThisObject
);

/*
* Many extension or feature objects need to perform some background
cleaning and maintenance work
* in any container environment. This type of work can be implemented
via separate low-priority
* tasks or periodic timer-based callback functions, depending on the
support of the underlying
* real-time operating system. From our previous experience, timer
callback implementation has more
* os-support than background task based approach.
*/
#define ANSC_TIMER_DESCRIPTOR_CLASS_CONTENT
\
/* duplication of the base object class content */
\
ANSCCO_CLASS_CONTENT
\
/* start of object class content */
\
ANSC_HANDLE hScheduler;
\
ANSC_HANDLE hClient;
\
ANSC_LOCK AccessLock;
\
ULONG StartTime;
\
ULONG TimerType;
\
ULONG Interval;
\
ULONG RelativeDelay;
\
ULONG CallCounter;
\
BOOL bScheduled;
\

\
PFN_TDO_GET_CONTEXT GetScheduler;
\
PFN_TDO_SET_CONTEXT SetScheduler;
\
PFN_TDO_GET_CONTEXT GetClient;
\
PFN_TDO_SET_CONTEXT SetClient;
\
PFN_TDO_GET_ULONG GetStartTime;
\
PFN_TDO_SET_ULONG SetStartTime;
\
PFN_TDO_GET_ULONG GetTimerType;
\
PFN_TDO_SET_ULONG SetTimerType;
\
PFN_TDO_GET_ULONG GetInterval;
\
PFN_TDO_SET_ULONG SetInterval;
\
PFN_TDO_GET_ULONG GetDelay;
\
PFN_TDO_SET_ULONG SetDelay;
\
PFN_TDO_GET_ULONG GetCallCounter;
\
PFN_TDO_SET_ULONG SetCallCounter;
\
PFN_TDO_GET_BOOL GetState;
\
PFN_TDO_SET_BOOL SetState;
\

\
PFN_TDO_ACQUIRE AcquireAccess;
\
PFN_TDO_RELEASE ReleaseAccess;
\
PFN_TDO_START Start;
\
PFN_TDO_STOP Stop;
\
PFN_TDO_INVOKE Invoke;
\
/* end of object class content */
\

typedef struct
_ANSC_TIMER_DESCRIPTOR_OBJECT
{
ANSC_TIMER_DESCRIPTOR_CLASS_CONTENT
}
ANSC_TIMER_DESCRIPTOR_OBJECT, *PANSC_TIMER_DESCRIPTOR_OBJECT;

#define ACCESS_ANSC_TIMER_DESCRIPTOR_OBJECT(p) \
ACCESS_CONTAINER(p, ANSC_TIMER_DESCRIPTOR_OBJECT, Linkage)


/***********************************************************
CLIENT OBJECT DEFINITION FOR ANSC TIMER DESCRIPTOR
***********************************************************/

/*
* Define some const values that will be used in the object mapper
object definition.
*/

/*
* Since we write all kernel modules in C (due to better performance
and lack of compiler support),
* we have to simulate the C++ object by encapsulating a set of
functions inside a data structure.
*/
typedef ANSC_STATUS
(*PFN_TDOCO_INVOKE)
(
ANSC_HANDLE hClient
);

/*
* Unlike the previous version of VPCom, in which the wrapper is part
of the container, the
* container is now 100% portable for different embedded platforms.
The os-specific wrapper has to
* be rewritten for each platform. The wrapper creates this wrapper
object during initialization
* and passes it to container.
*/
typedef struct
_ANSC_TDO_CLIENT_OBJECT
{
ANSC_HANDLE hClientContext;

PFN_TDOCO_INVOKE Invoke;
}
ANSC_TDO_CLIENT_OBJECT, *PANSC_TDO_CLIENT_OBJECT;


#endif


/**********************************************************************

caller: owner of this object

prototype:

ANSC_STATUS
AnscTsoCancelTimer
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hTimerDescriptor
);

description:

This function is called by external objects to cancel an
active
timer descriptor object.

argument: ANSC_HANDLE hThisObject
This handle is actually the pointer of this object
itself.

ANSC_HANDLE hTimerDescriptor
Specifies the timer descriptor object to be processed.

return: status of operation.

**********************************************************************/

ANSC_STATUS
AnscTsoCancelTimer
(
ANSC_HANDLE hThisObject,
ANSC_HANDLE hTimerDescriptor
)
{
ANSC_STATUS returnStatus =
ANSC_STATUS_SUCCESS;
PANSC_TIMER_SCHEDULER_OBJECT pMyObject =
(PANSC_TIMER_SCHEDULER_OBJECT )hThisObject;
PANSC_TIMER_DESCRIPTOR_OBJECT pTimerDescriptor =
(PANSC_TIMER_DESCRIPTOR_OBJECT)hTimerDescriptor;
PANSC_TIMER_DESCRIPTOR_OBJECT pNextTdo = NULL;
PSINGLE_LINK_ENTRY pSLinkEntry = NULL;
BOOL bWaitForInvoke = FALSE;

AnscAcquireLock(&pMyObject->TdoQueueLock);
pTimerDescriptor->AcquireAccess((ANSC_HANDLE)pTimerDescriptor);

if ( !pTimerDescriptor->GetState((ANSC_HANDLE)pTimerDescriptor) )
{
pTimerDescriptor->ReleaseAccess((ANSC_HANDLE)pTimerDescriptor);
AnscReleaseLock(&pMyObject->TdoQueueLock);

return ANSC_STATUS_SUCCESS;
}
else if ( pTimerDescriptor->GetScheduler((ANSC_HANDLE)pTimerDescriptor)
!= (ANSC_HANDLE)pMyObject )
{
pTimerDescriptor->ReleaseAccess((ANSC_HANDLE)pTimerDescriptor);
AnscReleaseLock(&pMyObject->TdoQueueLock);

return ANSC_STATUS_SUCCESS;
}

pSLinkEntry = AnscQueueGetNextEntry(&pTimerDescriptor->Linkage);

if ( pSLinkEntry )
{
pNextTdo = ACCESS_ANSC_TIMER_DESCRIPTOR_OBJECT(pSLinkEntry);

pNextTdo->RelativeDelay += pTimerDescriptor->RelativeDelay;
}

AnscQueuePopEntryByLink(&pMyObject->TdoQueue,
&pTimerDescriptor->Linkage);

pTimerDescriptor->SetState((ANSC_HANDLE)pTimerDescriptor, FALSE
);
pTimerDescriptor->SetDelay((ANSC_HANDLE)pTimerDescriptor,
pTimerDescriptor->GetInterval((ANSC_HANDLE)pTimerDescriptor));

if ( pMyObject->hCurInvokedTdo == (ANSC_HANDLE)pTimerDescriptor )
{
bWaitForInvoke = TRUE;
}

pTimerDescriptor->ReleaseAccess((ANSC_HANDLE)pTimerDescriptor);
AnscReleaseLock(&pMyObject->TdoQueueLock);

if ( bWaitForInvoke )
{
AnscAcquireTsLock(&pMyObject->SyncTsLock);
AnscReleaseTsLock(&pMyObject->SyncTsLock);
}

return ANSC_STATUS_SUCCESS;
}


with regards,

pravin
 
G

Gianni Mariani

Pravin said:
Hello to All,
I have interview 2moro.I need to explain this code and
i'm not getting this properly.I don't know what to do?

Tell the employer you're not interested.
 
M

Major_Small

Gianni said:
Tell the employer you're not interested.

I have to agree here - if you can't understand that code, how are you
supposed to do the job if you get it? that's the whole point of them
asking that. They're showing you some code you could possibly be
working with, and if you can understand it then you could be a
beneficial addition to their team. otherwise, you would be more dead
weight than anything. if we did tell you what it meant, you would not
learn much, and if they gave you more code at the interview (like any
smart employer would do), they would know exactly what you did
tonight...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,334
Latest member
66Zeinab9

Latest Threads

Top