You can use the services of the omnipresent rosapi node, these are equivalent to the command line statements:
rosservice call rosapi/topics
rosservice call rosapi/services
Roscpp
ros::ServiceClient topicfinder = n.serviceClient<rosapi::Topics>("rosapi/topics");
ros::ServiceClient servicesfinder = n.serviceClient<rosapi::Services>("rosapi/services");
rosapi::Topics topicsrv;
rosapi::Services servicessrv;
topicfinder.call(topicsrv);
servicesfinder.call(servicessrv);
Rospy
from rosapi.srv import Topics, Services
topics = rospy.ServiceProxy('/rosapi/topics', Topics)
services = rospy.ServiceProxy('/rosapi/services', Services)
topiclist = topics()
servicelist = services()
I've probably got some typos and mistakes in here, but that's the general gist.
Maybe sth like rostopic list && rosservice list | grep *roscpp*? I'm not sure about the exact syntax from my mind.
Thx. With roscpp I mean using a C++ function.