473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to Update a Object within a Callback Function

Hi,

I have a problem of how to update the Object data of a Class from within a Callback function that is not a member function of that Class, its just a C function.


void CallBack( int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *cd) // just a C function not a member function

{

// can i update the contents of the Object
// or the flow be passed to one of the member functions


}

Class A {

private:
/* data members */
public:
void example ( );
void example1 ( );

}

void A::example ()
{
/******

status = snmp.notify_register(oidc, targetc, CallBack, NULL);


}

In the above dummy coding very similar to my actuall requirement i call back function "CallBack" is called by snmp.notify_register.

Can i update the private data members of the Class or can i sent the control back to one of the member functions of that Class with the all the data members updated.

Thanks in Advance

Regards
SAK
Aug 7 '07 #1
2 3626
weaknessforcats
9,208 Expert Mod 8TB
Can i update the private data members of the Class...
Yes. Provided your function is a friend of the class.

Otherwise, you will need to use the public member functions like eveyone else.

Friend functions are discouraged and should only be used when the member function cannot have a this pointer as the first argument. Any other uses, generally, are there to bypass those messy rules about preserving encapsulation.
Aug 7 '07 #2
RRick
463 Expert 256MB
Callbacks between C APIs and C++ objects are possble without friend declarations. A typical C callback mechanism allows you to define/register a C style callback function with a void * data.

In this case, you register a static method from the object and pass the object as the void * data. When the callback is used, the C routine also passes back your object as the void * data. I assume that is what the last parameter is about. (If not, then oh-well, it was a nice idea).

Let's look at an example:

Expand|Select|Wrap|Line Numbers
  1. class CallMe
  2. {
  3. ......
  4. static void CallBack( int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *cd)
  5. };
  6.  
When CallMe::CallBack is compiled you will have access to all the static data in CallMe and access to a specific CallMe object. I believe you can access private data in the CallMe object from the static method.
Aug 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Simon Elliott | last post by:
If I have two classes: class bar { public: void RunTheBar(void); }; class foo {
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
35
by: eyoung | last post by:
I call a function that takes the unit price and quantity ordered to create an amount...it looks something like this. function calculateCost() { quantity=document.RFO.quantity.value;...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
1
by: Hoss | last post by:
Hello- I have the following Javascript code function Obj() { obj.squares = new Array(); } Obj.prototype.Load= function(xdoc) { var goat = "head"; xdoc.ProcessNodes("squares/square",...
0
by: Luke | last post by:
Hello All, Using the following delegate, and attempting to update the UI. There is no clear examples on how to pass multiple parameters though to the dispatcher. I keep receiving an exception...
5
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can...
6
by: 85ssp | last post by:
I have a server applicatoin that has a multitude of labels related to the clients connected to it. When I have a number near 50 clients and i recieve a updatated status from each of the clients at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.